瀏覽代碼

Even more FifoParallelDataProcessor simplification + test

Sebastian Stenzel 9 年之前
父節點
當前提交
0c2caf4469

+ 2 - 8
main/filesystem-crypto/src/main/java/org/cryptomator/crypto/engine/impl/FifoParallelDataProcessor.java

@@ -17,8 +17,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
 
-import org.cryptomator.common.UncheckedInterruptedException;
-
 /**
  * Executes long-running computations and returns the result strictly in order of the job submissions, no matter how long each job takes.
  * 
@@ -45,12 +43,8 @@ class FifoParallelDataProcessor<T> {
 	 * @throws InterruptedException
 	 */
 	void submit(Callable<T> processingJob) throws InterruptedException {
-		try {
-			Future<T> future = executorService.submit(processingJob);
-			processedData.put(future);
-		} catch (UncheckedInterruptedException e) {
-			throw e.getCause();
-		}
+		Future<T> future = executorService.submit(processingJob);
+		processedData.put(future);
 	}
 
 	/**

+ 13 - 0
main/filesystem-crypto/src/test/java/org/cryptomator/crypto/engine/impl/FifoParallelDataProcessorTest.java

@@ -32,6 +32,19 @@ public class FifoParallelDataProcessorTest {
 		processor.processedData();
 	}
 
+	@Test(expected = RuntimeException.class)
+	public void testRethrowsCheckedExceptionAsRuntimeExceptions() throws InterruptedException {
+		FifoParallelDataProcessor<Object> processor = new FifoParallelDataProcessor<>(1, 1);
+		try {
+			processor.submit(() -> {
+				throw new Exception("will be wrapped in a RuntimeException during 'processedData()'");
+			});
+		} catch (Exception e) {
+			Assert.fail("Exception must not yet be thrown.");
+		}
+		processor.processedData();
+	}
+
 	@Test(expected = RejectedExecutionException.class)
 	public void testRejectExecutionAfterShutdown() throws InterruptedException, ReflectiveOperationException, SecurityException {
 		FifoParallelDataProcessor<Integer> processor = new FifoParallelDataProcessor<>(1, 1);