complete Studio core and JavaFX boundary migration
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package p.studio.app.operation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.api.operation.OperationState;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class ExecutorOperationExecutorTest {
|
||||
@Test
|
||||
void completesWithTypedResultAndTerminalSnapshot() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
final var handle = new ExecutorOperationExecutor(executor).submit("test operation", () -> 42);
|
||||
|
||||
assertEquals(42, handle.completion().toCompletableFuture().get(2, TimeUnit.SECONDS));
|
||||
assertEquals(OperationState.SUCCEEDED, handle.snapshot().state());
|
||||
assertEquals("test operation", handle.snapshot().summary());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancellationInterruptsWorkAndCancelsCompletion() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
final var started = new CountDownLatch(1);
|
||||
try {
|
||||
final var handle = new ExecutorOperationExecutor(executor).submit("cancel operation", () -> {
|
||||
started.countDown();
|
||||
new CountDownLatch(1).await();
|
||||
return 42;
|
||||
});
|
||||
assertTrue(started.await(2, TimeUnit.SECONDS));
|
||||
|
||||
assertTrue(handle.cancel());
|
||||
assertEquals(OperationState.CANCELLED, handle.snapshot().state());
|
||||
assertThrows(java.util.concurrent.CancellationException.class,
|
||||
() -> handle.completion().toCompletableFuture().join());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user