implement DEV workspace and project automation authority
This commit is contained in:
@@ -12,6 +12,39 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class ExecutorOperationExecutorTest {
|
||||
@Test
|
||||
void cancellationDoesNotPretendAnUncooperativeWorkerHasStopped() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
final var started = new CountDownLatch(1);
|
||||
final var finish = new CountDownLatch(1);
|
||||
try {
|
||||
var handle = new ExecutorOperationExecutor(executor).submit("stubborn worker", () -> {
|
||||
started.countDown();
|
||||
boolean done = false;
|
||||
while (!done) try { finish.await(); done = true; } catch (InterruptedException ignored) { }
|
||||
return 42;
|
||||
});
|
||||
assertTrue(started.await(2, TimeUnit.SECONDS));
|
||||
handle.cancel();
|
||||
assertTrue(handle.completion().toCompletableFuture().isCancelled());
|
||||
org.junit.jupiter.api.Assertions.assertFalse(handle.termination().toCompletableFuture().isDone());
|
||||
finish.countDown();
|
||||
handle.termination().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
} finally { finish.countDown(); executor.shutdownNow(); }
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancellingQueuedWorkCompletesTerminationWithoutRunningItsBody() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
final var finish = new CountDownLatch(1);
|
||||
try {
|
||||
executor.submit(() -> { try { finish.await(); } catch (InterruptedException ignored) { } });
|
||||
var handle = new ExecutorOperationExecutor(executor).submit("queued", () -> { throw new AssertionError("must not execute"); });
|
||||
handle.cancel();
|
||||
handle.termination().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
} finally { finish.countDown(); executor.shutdownNow(); }
|
||||
}
|
||||
|
||||
@Test
|
||||
void completesWithTypedResultAndTerminalSnapshot() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
Reference in New Issue
Block a user