Even more FifoParallelDataProcessor simplification + test

This commit is contained in:
Sebastian Stenzel
2016-01-01 16:15:36 +01:00
parent 9665ca8dff
commit 0c2caf4469
2 changed files with 15 additions and 8 deletions

View File

@@ -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);
}
/**

View File

@@ -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);