Skip to content

Commit

Permalink
Even more FifoParallelDataProcessor simplification + test
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jan 1, 2016
1 parent 9665ca8 commit 0c2caf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
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.
*
Expand All @@ -45,12 +43,8 @@ public FifoParallelDataProcessor(int numThreads, int workAhead) {
* @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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ public void testRethrowsException() throws InterruptedException {
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);
Expand Down

0 comments on commit 0c2caf4

Please sign in to comment.