use of io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation in project pravega by pravega.
the class OperationProcessorTests method testConcurrentStopAndCommit.
/**
* Tests a scenario where the OperationProcessor is shut down while a DataFrame is being processed and will eventually
* complete successfully - however its operation should be cancelled.
*/
@Test
public void testConcurrentStopAndCommit() throws Exception {
@Cleanup TestContext context = new TestContext();
// Generate some test data.
val segmentId = createStreamSegmentsInMetadata(1, context.metadata).stream().findFirst().orElse(-1L);
List<Operation> operations = Collections.singletonList(new StreamSegmentAppendOperation(segmentId, new byte[1], null));
CompletableFuture<LogAddress> appendCallback = new CompletableFuture<>();
// Setup an OperationProcessor with a custom DurableDataLog and start it.
@Cleanup DurableDataLog dataLog = new ManualAppendOnlyDurableDataLog(() -> appendCallback);
dataLog.initialize(TIMEOUT);
@Cleanup OperationProcessor operationProcessor = new OperationProcessor(context.metadata, context.stateUpdater, dataLog, getNoOpCheckpointPolicy(), executorService());
operationProcessor.startAsync().awaitRunning();
// Process all generated operations.
OperationWithCompletion completionFuture = processOperations(operations, operationProcessor).stream().findFirst().orElse(null);
operationProcessor.stopAsync();
appendCallback.complete(new TestLogAddress(1));
// Stop the processor.
operationProcessor.awaitTerminated();
// Wait for the operation to complete. The operation should have been cancelled (due to the OperationProcessor
// shutting down) - no other exception (or successful completion is accepted).
AssertExtensions.assertThrows("Operation did not fail with the right exception.", () -> completionFuture.completion, ex -> ex instanceof CancellationException || ex instanceof ObjectClosedException);
}
Aggregations