use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorBasicOperation.
/**
* Test that the {@link ContainerEventProcessor} service is started as part of the {@link StreamSegmentContainer}
* and that it can process events.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorBasicOperation() 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.testBasicContainerEventProcessor(containerEventProcessor);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorMultipleConsumers.
/**
* Test the behavior of the {@link StreamSegmentContainer} when multiple {@link ContainerEventProcessor.EventProcessor}
* objects are registered, including one with a faulty handler.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorMultipleConsumers() 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.testMultipleProcessors(containerEventProcessor);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorMaxItemsPerBatchRespected.
/**
* Check that the max number of elements processed per EventProcessor iteration is respected.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorMaxItemsPerBatchRespected() 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.testContainerMaxItemsPerBatchRespected(containerEventProcessor);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorWithSerializationError.
/**
* Test the situation in which an EventProcessor gets BufferView.Reader.OutOfBoundsException during deserialization
* of events.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorWithSerializationError() 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.testEventProcessorWithSerializationError(containerEventProcessor);
}
use of io.pravega.segmentstore.server.ContainerEventProcessor in project pravega by pravega.
the class StreamSegmentContainerTests method testEventProcessorDurableQueueAndSwitchToConsumer.
/**
* Test the EventProcessor in durable queue mode (no handler). Then, close it and recreate another one on the same
* internal Segment (same name) that actually consumes the events stored previously.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testEventProcessorDurableQueueAndSwitchToConsumer() throws Exception {
@Cleanup TestContext context = createContext();
val container = (StreamSegmentContainer) context.container;
container.startAsync().awaitRunning();
int allEventsToProcess = 100;
@Cleanup ContainerEventProcessorImpl containerEventProcessor = new ContainerEventProcessorImpl(container, container.metadataStore, TIMEOUT_EVENT_PROCESSOR_ITERATION, TIMEOUT_EVENT_PROCESSOR_ITERATION, this.executorService());
ContainerEventProcessor.EventProcessor processor = containerEventProcessor.forDurableQueue("testDurableQueue").get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// At this point, we can only add events, but not consuming them as the EventProcessor works in durable queue mode.
for (int i = 0; i < allEventsToProcess; i++) {
BufferView event = new ByteArraySegment(ByteBuffer.allocate(Integer.BYTES).putInt(i).array());
processor.add(event, TIMEOUT_FUTURE).join();
}
Assert.assertEquals("Event processor object not matching", processor, containerEventProcessor.forDurableQueue("testDurableQueue").get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS));
// Close the processor and unregister it.
processor.close();
// Make sure that EventProcessor eventually terminates.
((ContainerEventProcessorImpl.EventProcessorImpl) processor).awaitTerminated();
// Now, re-create the Event Processor with a handler to consume the events.
ContainerEventProcessor.EventProcessorConfig eventProcessorConfig = new ContainerEventProcessor.EventProcessorConfig(EVENT_PROCESSOR_EVENTS_AT_ONCE, EVENT_PROCESSOR_MAX_OUTSTANDING_BYTES, EVENT_PROCESSOR_TRUNCATE_SIZE_BYTES);
List<Integer> processorResults = new ArrayList<>();
Function<List<BufferView>, CompletableFuture<Void>> handler = l -> {
l.forEach(b -> {
try {
processorResults.add(ByteBuffer.wrap(b.getReader().readNBytes(Integer.BYTES)).getInt());
} catch (IOException e) {
throw new CompletionException(e);
}
});
return CompletableFuture.completedFuture(null);
};
processor = containerEventProcessor.forConsumer("testDurableQueue", handler, eventProcessorConfig).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Wait for all items to be processed.
AssertExtensions.assertEventuallyEquals(true, () -> processorResults.size() == allEventsToProcess, 10000);
Assert.assertArrayEquals(processorResults.toArray(), IntStream.iterate(0, v -> v + 1).limit(allEventsToProcess).boxed().toArray());
// Just check failure callback.
((ContainerEventProcessorImpl.EventProcessorImpl) processor).failureCallback(new IntentionalException());
// Close the processor and unregister it.
processor.close();
// Make sure that EventProcessor eventually terminates.
((ContainerEventProcessorImpl.EventProcessorImpl) processor).awaitTerminated();
}
Aggregations