Search in sources :

Example 16 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class EventProcessorTest method testFailingEventProcessorInGroup.

@Test(timeout = 10000)
public void testFailingEventProcessorInGroup() throws ReinitializationRequiredException, CheckpointStoreException {
    String systemName = "testSystem";
    String readerGroupName = "testReaderGroup";
    int[] input = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore();
    EventProcessorGroupConfig config = createEventProcessorGroupConfig(1);
    EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(1, input), new EventStreamWriterMock<>(), readerGroupName);
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(StartFailingEventProcessor::new).serializer(new JavaSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore);
    // awaitRunning should succeed.
    group.awaitRunning();
    Assert.assertTrue(true);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) Test(org.junit.Test)

Example 17 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer 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();
    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 JavaSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore);
    // 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) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) Test(org.junit.Test)

Example 18 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer 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();
    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 JavaSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore);
    // 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) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) Test(org.junit.Test)

Aggregations

JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)18 Test (org.junit.Test)16 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)12 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)12 Cleanup (lombok.Cleanup)12 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)9 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)8 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)7 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)7 ClientFactory (io.pravega.client.ClientFactory)6 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)6 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 EventProcessorGroupConfig (io.pravega.controller.eventProcessor.EventProcessorGroupConfig)6 TestingServerStarter (io.pravega.test.common.TestingServerStarter)6 ClientConfig (io.pravega.client.ClientConfig)5 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)5 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)5 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)5 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 Controller (io.pravega.client.stream.impl.Controller)5