use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class ContainerEventProcessorTests method testEventProcessorClose.
/**
* Test closing the EventProcessor.
*
* @throws Exception
*/
@Test(timeout = 30000)
public void testEventProcessorClose() throws Exception {
@Cleanup ContainerEventProcessor eventProcessorService = new ContainerEventProcessorImpl(0, mockSegmentSupplier(), 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);
AtomicLong processorResults = new AtomicLong(0);
Function<List<BufferView>, CompletableFuture<Void>> handler = l -> {
processorResults.addAndGet(l.size());
return CompletableFuture.completedFuture(null);
};
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testClose", handler, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Assert that the existing object in the ContainerEventProcessorImpl map is the same as the one we just instantiated.
Assert.assertEquals(processor, eventProcessorService.forConsumer("testClose", handler, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS));
// Now, close the EventProcessor object, which should auto-unregister from the map.
processor.close();
// After that, we should see a new object being instantiated in ContainerEventProcessorImpl for the same name.
Assert.assertNotEquals(processor, eventProcessorService.forConsumer("testClose", handler, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS));
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class ContainerEventProcessorTests method testEventProcessorWithSerializationError.
public static void testEventProcessorWithSerializationError(ContainerEventProcessor containerEventProcessor) throws Exception {
int maxItemsPerBatch = 10;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
AtomicLong readEvents = new AtomicLong(0);
Function<List<BufferView>, CompletableFuture<Void>> handler = l -> {
readEvents.addAndGet(l.size());
return CompletableFuture.completedFuture(null);
};
ContainerEventProcessor.EventProcessorConfig eventProcessorConfig = spy(new ContainerEventProcessor.EventProcessorConfig(maxItemsPerBatch, maxOutstandingBytes, truncationDataSize));
@Cleanup ContainerEventProcessor.EventProcessor processor = containerEventProcessor.forConsumer("testConsumer", handler, eventProcessorConfig).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Simulate an BufferView.Reader.OutOfBoundsException within the deserializeEvents() method and then behave normally.
when(eventProcessorConfig.getMaxItemsAtOnce()).thenThrow(new BufferView.Reader.OutOfBoundsException()).thenThrow(new RuntimeException(new SerializationException("Intentional exception"))).thenCallRealMethod();
// Write an event and wait for the event to be processed.
BufferView event = new ByteArraySegment("event".getBytes());
processor.add(event, TIMEOUT_FUTURE).join();
// Wait until the processor reads the event.
AssertExtensions.assertEventuallyEquals(true, () -> readEvents.get() == 1, 10000);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class ContainerEventProcessorTests method testMultipleProcessors.
public static void testMultipleProcessors(ContainerEventProcessor eventProcessorService) throws Exception {
int allEventsToProcess = 100;
int maxItemsPerBatch = 10;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
List<Integer> processorResults1 = new ArrayList<>();
Function<List<BufferView>, CompletableFuture<Void>> handler1 = getNumberSequenceHandler(processorResults1, maxItemsPerBatch);
List<Integer> processorResults2 = new ArrayList<>();
Function<List<BufferView>, CompletableFuture<Void>> handler2 = getNumberSequenceHandler(processorResults2, maxItemsPerBatch);
AtomicLong processorResults3 = new AtomicLong(0);
Function<List<BufferView>, CompletableFuture<Void>> handler3 = l -> {
Object o = null;
// We should expect NPE here, so the results counter would not be incremented.
o.toString();
processorResults3.addAndGet(1);
return CompletableFuture.completedFuture(null);
};
ContainerEventProcessor.EventProcessorConfig config = new ContainerEventProcessor.EventProcessorConfig(maxItemsPerBatch, maxOutstandingBytes, truncationDataSize);
@Cleanup ContainerEventProcessor.EventProcessor processor1 = eventProcessorService.forConsumer("testSegment1", handler1, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
@Cleanup ContainerEventProcessor.EventProcessor processor2 = eventProcessorService.forConsumer("testSegment2", handler2, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
@Cleanup ContainerEventProcessor.EventProcessor processor3 = eventProcessorService.forConsumer("testSegment3", handler3, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
for (int i = 0; i < allEventsToProcess; i++) {
BufferView event = new ByteArraySegment(ByteBuffer.allocate(Integer.BYTES).putInt(i).array());
processor1.add(event, TIMEOUT_FUTURE).join();
processor2.add(event, TIMEOUT_FUTURE).join();
processor3.add(event, TIMEOUT_FUTURE).join();
}
// Wait for all items to be processed.
validateProcessorResults(processor1, processorResults1, allEventsToProcess);
validateProcessorResults(processor2, processorResults2, allEventsToProcess);
AssertExtensions.assertEventuallyEquals(true, () -> processorResults3.get() == 0, 10000);
AssertExtensions.assertEventuallyEquals(true, () -> ((ContainerEventProcessorImpl.EventProcessorImpl) processor3).getOutstandingBytes() > 0, 10000);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorEventRejectionOnMaxOutstanding.
/**
* Check that an EventProcessor does not accept any new event once the maximum outstanding bytes has been reached.
*
* @throws Exception
*/
@Test(timeout = 30000)
public void testEventProcessorEventRejectionOnMaxOutstanding() throws Exception {
@Cleanup TestContext context = createContext();
val container = (StreamSegmentContainer) context.container;
container.startAsync().awaitRunning();
@Cleanup ContainerEventProcessor containerEventProcessor = new ContainerEventProcessorImpl(container, container.metadataStore, TIMEOUT_EVENT_PROCESSOR_ITERATION, TIMEOUT_EVENT_PROCESSOR_ITERATION, this.executorService());
ContainerEventProcessorTests.testEventRejectionOnMaxOutstanding(containerEventProcessor);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorFaultyHandler.
/**
* Verify that when a faulty handler is passed to an EventProcessor, the Segment is not truncated and the retries
* continue indefinitely.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorFaultyHandler() throws Exception {
@Cleanup TestContext context = createContext();
val container = (StreamSegmentContainer) context.container;
container.startAsync().awaitRunning();
@Cleanup ContainerEventProcessor containerEventProcessor = new ContainerEventProcessorImpl(container, container.metadataStore, TIMEOUT_EVENT_PROCESSOR_ITERATION, TIMEOUT_EVENT_PROCESSOR_ITERATION, this.executorService());
ContainerEventProcessorTests.testFaultyHandler(containerEventProcessor);
}
Aggregations