mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-28 07:30:19 +00:00
Even more FifoParallelDataProcessor simplification + test
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user