Search in sources :

Example 6 with CheckpointConfig

use of io.pravega.controller.eventProcessor.CheckpointConfig in project pravega by pravega.

the class EventProcessorTest method testInitialize.

@Test(timeout = 10000)
public void testInitialize() throws ReinitializationRequiredException, CheckpointStoreException {
    String systemName = "testSystem";
    String readerGroupName = "testReaderGroup";
    EventStreamWriterMock<TestEvent> writer = new EventStreamWriterMock<>();
    int[] input = { 1, 2, 3, 4, 5 };
    CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore();
    checkpointStore.addReaderGroup(PROCESS, readerGroupName);
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build();
    EventProcessorGroupConfig config = EventProcessorGroupConfigImpl.builder().eventProcessorCount(3).readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build();
    createEventProcessorGroupConfig(3);
    EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(3, input), writer, readerGroupName);
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new StartWritingEventProcessor(false, input)).serializer(new EventSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    @Cleanup EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore, executor);
    // test idempotent initialize
    group.initialize();
    group.initialize();
    // Await until it is ready.
    group.awaitRunning();
    group.initialize();
    assertEquals(3, group.getEventProcessorMap().values().size());
}
Also used : EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Cleanup(lombok.Cleanup) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) EventSerializer(io.pravega.controller.eventProcessor.EventSerializer) Test(org.junit.Test)

Example 7 with CheckpointConfig

use of io.pravega.controller.eventProcessor.CheckpointConfig in project pravega by pravega.

the class EventProcessorTest method createEventProcessorGroupConfig.

private EventProcessorGroupConfig createEventProcessorGroupConfig(int count) {
    CheckpointConfig.CheckpointPeriod period = CheckpointConfig.CheckpointPeriod.builder().numEvents(1).numSeconds(1).build();
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.Periodic).checkpointPeriod(period).build();
    return EventProcessorGroupConfigImpl.builder().eventProcessorCount(count).readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build();
}
Also used : CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig)

Example 8 with CheckpointConfig

use of io.pravega.controller.eventProcessor.CheckpointConfig in project pravega by pravega.

the class EventProcessorTest method testEventProcessorWriter.

@Test(timeout = 10000)
public void testEventProcessorWriter() throws ReinitializationRequiredException, CheckpointStoreException {
    int initialCount = 1;
    String systemName = "testSystem";
    String readerGroupName = "testReaderGroup";
    int[] input = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    EventStreamWriterMock<TestEvent> writer = new EventStreamWriterMock<>();
    CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore();
    checkpointStore.addReaderGroup(PROCESS, readerGroupName);
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build();
    EventProcessorGroupConfig config = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build();
    createEventProcessorGroupConfig(initialCount);
    EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(1, input), writer, readerGroupName);
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new StartWritingEventProcessor(false, input)).serializer(new EventSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    @Cleanup EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore, executor);
    // Await until it is ready.
    group.awaitRunning();
    // By now, the events have been written to the Mock EventStreamWriter.
    Integer[] writerList = writer.getEventList().stream().map(TestEvent::getNumber).collect(Collectors.toList()).toArray(new Integer[input.length]);
    // Validate that events are correctly written.
    Assert.assertArrayEquals(input, ArrayUtils.toPrimitive(writerList));
}
Also used : EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Cleanup(lombok.Cleanup) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) EventSerializer(io.pravega.controller.eventProcessor.EventSerializer) Test(org.junit.Test)

Aggregations

CheckpointConfig (io.pravega.controller.eventProcessor.CheckpointConfig)8 EventProcessorGroupConfig (io.pravega.controller.eventProcessor.EventProcessorGroupConfig)7 Test (org.junit.Test)6 EventProcessorSystem (io.pravega.controller.eventProcessor.EventProcessorSystem)5 Cleanup (lombok.Cleanup)5 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)4 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)4 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)4 EventSerializer (io.pravega.controller.eventProcessor.EventSerializer)4 EventProcessorSystemImpl (io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl)4 CheckpointStore (io.pravega.controller.store.checkpoint.CheckpointStore)4 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)3 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)3 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)3 Position (io.pravega.client.stream.Position)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)1