use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class ContainerEventProcessorTests method testReadWithFailingSegment.
/**
* Test the behavior of the EventProcessor when internal Segment reads fail.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testReadWithFailingSegment() throws Exception {
DirectSegmentAccess faultySegment = spy(new SegmentMock(this.executorService()));
Function<String, CompletableFuture<DirectSegmentAccess>> faultySegmentSupplier = s -> CompletableFuture.completedFuture(faultySegment);
@Cleanup ContainerEventProcessor eventProcessorService = new ContainerEventProcessorImpl(0, faultySegmentSupplier, ITERATION_DELAY, CONTAINER_OPERATION_TIMEOUT, this.executorService());
int maxItemsProcessed = 10;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
ContainerEventProcessor.EventProcessorConfig config = new ContainerEventProcessor.EventProcessorConfig(maxItemsProcessed, maxOutstandingBytes, truncationDataSize);
ReusableLatch latch = new ReusableLatch();
Function<List<BufferView>, CompletableFuture<Void>> doNothing = l -> {
latch.release();
return CompletableFuture.completedFuture(null);
};
// Make the internal Segment of the processor to fail upon a read.
when(faultySegment.read(anyLong(), anyInt(), any(Duration.class))).thenThrow(IntentionalException.class).thenCallRealMethod();
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testSegmentMax", doNothing, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Write an event to make sure that the processor is running and await for it to be processed.
BufferView event = new ByteArraySegment("Test".getBytes());
processor.add(event, TIMEOUT_FUTURE).join();
latch.await();
}
use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class ContainerEventProcessorTests method executeEventOrderingTest.
private void executeEventOrderingTest(int numEvents, List<Integer> readEvents, Consumer<DirectSegmentAccess> segmentFailure) throws Exception {
DirectSegmentAccess faultySegment = spy(new SegmentMock(this.executorService()));
Function<String, CompletableFuture<DirectSegmentAccess>> faultySegmentSupplier = s -> CompletableFuture.completedFuture(faultySegment);
@Cleanup ContainerEventProcessor eventProcessorService = new ContainerEventProcessorImpl(0, faultySegmentSupplier, ITERATION_DELAY, CONTAINER_OPERATION_TIMEOUT, this.executorService());
int maxItemsProcessed = 100;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
Function<List<BufferView>, CompletableFuture<Void>> handler = l -> {
l.forEach(d -> readEvents.add(new ByteArraySegment(d.getCopy()).getInt(0)));
return CompletableFuture.completedFuture(null);
};
// Induce some desired failures.
segmentFailure.accept(faultySegment);
ContainerEventProcessor.EventProcessorConfig config = new ContainerEventProcessor.EventProcessorConfig(maxItemsProcessed, maxOutstandingBytes, truncationDataSize);
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testSequence", handler, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Write some data.
for (int i = 0; i < numEvents; i++) {
ByteArraySegment b = new ByteArraySegment(new byte[Integer.BYTES]);
b.setInt(0, i);
processor.add(b.slice(), TIMEOUT_FUTURE).join();
}
// Wait until the last event is read.
AssertExtensions.assertEventuallyEquals(true, () -> !readEvents.isEmpty() && readEvents.get(readEvents.size() - 1) == numEvents - 1, 10000);
}
Aggregations