Search in sources :

Example 31 with StreamImpl

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

the class EndToEndTruncationTest method testWriteDuringTruncationAndDeletion.

@Test(timeout = 30000)
public void testWriteDuringTruncationAndDeletion() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 2)).build();
    LocalController controller = (LocalController) PRAVEGA.getLocalController();
    String streamName = "testWriteDuringTruncationAndDeletion";
    controller.createScope("test").get();
    controller.createStream("test", streamName, config).get();
    config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
    controller.updateStream("test", streamName, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
    // routing key "0" translates to key 0.8. This write happens to segment 1.
    writer.writeEvent("0", "truncationTest1").get();
    // scale down to one segment.
    Stream stream = new StreamImpl("test", streamName);
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 1.0);
    assertTrue("Stream Scale down", controller.scaleStream(stream, Lists.newArrayList(0L, 1L), map, executorService()).getFuture().get());
    // truncate stream at segment 2, offset 0.
    Map<Long, Long> streamCutPositions = new HashMap<>();
    streamCutPositions.put(computeSegmentId(2, 1), 0L);
    assertTrue("Truncate stream", controller.truncateStream("test", streamName, streamCutPositions).get());
    // routing key "2" translates to key 0.2.
    // this write translates to a write to Segment 0, but since segment 0 is truncated the write should happen on segment 2.
    // write to segment 0
    writer.writeEvent("2", "truncationTest2").get();
    String group = "testWriteDuringTruncationAndDeletion-group";
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
    groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).build());
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", group, new JavaSerializer<>(), ReaderConfig.builder().build());
    EventRead<String> event = reader.readNextEvent(10000);
    assertNotNull(event);
    assertEquals("truncationTest2", event.getEvent());
    // Seal and Delete stream.
    assertTrue(controller.sealStream("test", streamName).get());
    assertTrue(controller.deleteStream("test", streamName).get());
    // write by an existing writer to a deleted stream should complete exceptionally.
    assertFutureThrows("Should throw NoSuchSegmentException", writer.writeEvent("2", "write to deleted stream"), e -> NoSuchSegmentException.class.isAssignableFrom(e.getClass()));
    // subsequent writes will throw an exception to the application.
    assertThrows(RuntimeException.class, () -> writer.writeEvent("test"));
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) LocalController(io.pravega.controller.server.eventProcessor.LocalController) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) NoSuchSegmentException(io.pravega.client.segment.impl.NoSuchSegmentException) Test(org.junit.Test)

Example 32 with StreamImpl

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

the class RetentionTest method testRetentionSize.

@Test(timeout = 30000)
public void testRetentionSize() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(2)).retentionPolicy(RetentionPolicy.bySizeBytes(10)).build();
    LocalController controller = (LocalController) controllerWrapper.getController();
    String name = "testsize";
    Stream stream = new StreamImpl(name, name);
    controllerWrapper.getControllerService().createScope(name, 0L).get();
    controller.createStream(name, name, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(controllerURI).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(name, controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(name, new JavaSerializer<>(), EventWriterConfig.builder().build());
    Map<Segment, Long> x = controller.getSegmentsAtTime(stream, 0L).join();
    assertTrue(x.values().stream().allMatch(a -> a == 0));
    AtomicBoolean continueLoop = new AtomicBoolean(true);
    Futures.loop(continueLoop::get, () -> writer.writeEvent("a"), executor);
    AssertExtensions.assertEventuallyEquals(true, () -> controller.getSegmentsAtTime(stream, 0L).join().values().stream().anyMatch(a -> a > 0), 30 * 1000L);
    continueLoop.set(false);
}
Also used : Segment(io.pravega.client.segment.impl.Segment) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) AssertExtensions(io.pravega.test.common.AssertExtensions) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Cleanup(lombok.Cleanup) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) LocalController(io.pravega.controller.server.eventProcessor.LocalController) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TestingServer(org.apache.curator.test.TestingServer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) URI(java.net.URI) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Slf4j(lombok.extern.slf4j.Slf4j) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) TestUtils(io.pravega.test.common.TestUtils) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) LocalController(io.pravega.controller.server.eventProcessor.LocalController) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 33 with StreamImpl

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

the class RetentionTest method testRetentionTime.

@Test(timeout = 30000)
public void testRetentionTime() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(2)).retentionPolicy(RetentionPolicy.byTime(Duration.ofSeconds(1))).build();
    LocalController controller = (LocalController) controllerWrapper.getController();
    String name = "testtime";
    Stream stream = new StreamImpl(name, name);
    controllerWrapper.getControllerService().createScope(name, 0L).get();
    controller.createStream(name, name, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(controllerURI).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(name, controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(name, new JavaSerializer<>(), EventWriterConfig.builder().build());
    Map<Segment, Long> x = controller.getSegmentsAtTime(stream, 0L).join();
    assertTrue(x.values().stream().allMatch(a -> a == 0));
    AtomicBoolean continueLoop = new AtomicBoolean(true);
    Futures.loop(continueLoop::get, () -> writer.writeEvent("a"), executor);
    AssertExtensions.assertEventuallyEquals(true, () -> controller.getSegmentsAtTime(stream, 0L).join().values().stream().anyMatch(a -> a > 0), 30 * 1000L);
    continueLoop.set(false);
}
Also used : Segment(io.pravega.client.segment.impl.Segment) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) AssertExtensions(io.pravega.test.common.AssertExtensions) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Cleanup(lombok.Cleanup) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) LocalController(io.pravega.controller.server.eventProcessor.LocalController) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TestingServer(org.apache.curator.test.TestingServer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) URI(java.net.URI) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Slf4j(lombok.extern.slf4j.Slf4j) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) TestUtils(io.pravega.test.common.TestUtils) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) LocalController(io.pravega.controller.server.eventProcessor.LocalController) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 34 with StreamImpl

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

the class ReaderGroupNotificationTest method testEndOfStreamNotifications.

@Test(timeout = 40000)
public void testEndOfStreamNotifications() throws Exception {
    final String streamName = "stream2";
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope(SCOPE, 0L).get();
    controller.createStream(SCOPE, streamName, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
    writer.writeEvent("0", "data1").get();
    // scale
    Stream stream = new StreamImpl(SCOPE, streamName);
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.5);
    map.put(0.5, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0L), map, executorService()).getFuture().get();
    assertTrue(result);
    writer.writeEvent("0", "data2").get();
    // seal stream
    assertTrue(controller.sealStream(SCOPE, streamName).get());
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(SCOPE, controller, clientFactory);
    groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, streamName)).groupRefreshTimeMillis(0).build());
    @Cleanup ReaderGroup readerGroup = groupManager.getReaderGroup("reader");
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().initialAllocationDelay(0).build());
    // Add segment event listener
    Listener<EndOfDataNotification> l1 = notification -> {
        listenerInvoked.set(true);
        listenerLatch.release();
    };
    EndOfDataNotifier endOfDataNotifier = (EndOfDataNotifier) readerGroup.getEndOfDataNotifier(executorService());
    endOfDataNotifier.registerListener(l1);
    EventRead<String> event1 = reader1.readNextEvent(10000);
    assertEquals("data1", event1.getEvent());
    EventRead<String> emptyEvent = reader1.readNextEvent(0);
    assertNull(emptyEvent.getEvent());
    assertFalse(emptyEvent.isCheckpoint());
    readerGroup.initiateCheckpoint("cp", executorService());
    EventRead<String> cpEvent = reader1.readNextEvent(10000);
    assertTrue(cpEvent.isCheckpoint());
    EventRead<String> event2 = reader1.readNextEvent(10000);
    assertEquals("data2", event2.getEvent());
    emptyEvent = reader1.readNextEvent(0);
    assertNull(emptyEvent.getEvent());
    assertFalse(emptyEvent.isCheckpoint());
    emptyEvent = reader1.readNextEvent(0);
    assertNull(emptyEvent.getEvent());
    assertFalse(emptyEvent.isCheckpoint());
    readerGroup.initiateCheckpoint("cp2", executorService());
    cpEvent = reader1.readNextEvent(10000);
    assertTrue(cpEvent.isCheckpoint());
    emptyEvent = reader1.readNextEvent(0);
    assertNull(emptyEvent.getEvent());
    assertFalse(emptyEvent.isCheckpoint());
    endOfDataNotifier.pollNow();
    listenerLatch.await();
    assertTrue("Listener invoked", listenerInvoked.get());
}
Also used : EventStreamWriter(io.pravega.client.stream.EventStreamWriter) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Cleanup(lombok.Cleanup) ReaderGroup(io.pravega.client.stream.ReaderGroup) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) EventRead(io.pravega.client.stream.EventRead) EndOfDataNotification(io.pravega.client.stream.notifications.EndOfDataNotification) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) After(org.junit.After) URI(java.net.URI) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EndOfDataNotifier(io.pravega.client.stream.notifications.notifier.EndOfDataNotifier) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Slf4j(lombok.extern.slf4j.Slf4j) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) Controller(io.pravega.client.control.impl.Controller) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) SegmentNotification(io.pravega.client.stream.notifications.SegmentNotification) TestingServerStarter(io.pravega.test.common.TestingServerStarter) TestingServer(org.apache.curator.test.TestingServer) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ReusableLatch(io.pravega.common.util.ReusableLatch) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Listener(io.pravega.client.stream.notifications.Listener) Assert.assertNotNull(org.junit.Assert.assertNotNull) lombok.val(lombok.val) SegmentNotifier(io.pravega.client.stream.notifications.notifier.SegmentNotifier) Assert.assertTrue(org.junit.Assert.assertTrue) EventStreamReader(io.pravega.client.stream.EventStreamReader) Test(org.junit.Test) Assert.assertNull(org.junit.Assert.assertNull) ReaderConfig(io.pravega.client.stream.ReaderConfig) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ReaderGroup(io.pravega.client.stream.ReaderGroup) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) EndOfDataNotification(io.pravega.client.stream.notifications.EndOfDataNotification) EndOfDataNotifier(io.pravega.client.stream.notifications.notifier.EndOfDataNotifier) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Example 35 with StreamImpl

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

the class ReaderGroupNotificationTest method testSegmentNotifications.

@Test(timeout = 40000)
public void testSegmentNotifications() throws Exception {
    final String streamName = "stream1";
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope(SCOPE, 0L).get();
    controller.createStream(SCOPE, streamName, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
    writer.writeEvent("0", "data1").get();
    // scale
    Stream stream = new StreamImpl(SCOPE, streamName);
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.5);
    map.put(0.5, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0L), map, executorService()).getFuture().get();
    assertTrue(result);
    writer.writeEvent("0", "data2").get();
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(SCOPE, controller, clientFactory);
    groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, streamName)).groupRefreshTimeMillis(0).build());
    @Cleanup ReaderGroup readerGroup = groupManager.getReaderGroup("reader");
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().initialAllocationDelay(0).build());
    val notificationResults = new ArrayBlockingQueue<SegmentNotification>(2);
    // Add segment event listener
    Listener<SegmentNotification> l1 = notification -> {
        log.info("Number of Segments: {}, Number of Readers: {}", notification.getNumOfSegments(), notification.getNumOfReaders());
        notificationResults.add(notification);
    };
    SegmentNotifier segmentNotifier = (SegmentNotifier) readerGroup.getSegmentNotifier(executorService());
    segmentNotifier.registerListener(l1);
    // Read first event and validate notification.
    EventRead<String> event1 = reader1.readNextEvent(5000);
    assertEquals("data1", event1.getEvent());
    segmentNotifier.pollNow();
    SegmentNotification initialSegmentNotification = notificationResults.take();
    assertNotNull(initialSegmentNotification);
    assertEquals(1, initialSegmentNotification.getNumOfReaders());
    assertEquals(1, initialSegmentNotification.getNumOfSegments());
    EventRead<String> emptyEvent = reader1.readNextEvent(0);
    assertNull(emptyEvent.getEvent());
    assertFalse(emptyEvent.isCheckpoint());
    readerGroup.initiateCheckpoint("cp", executorService());
    EventRead<String> cpEvent = reader1.readNextEvent(1000);
    assertTrue(cpEvent.isCheckpoint());
    // Read second event and validate notification.
    EventRead<String> event2 = reader1.readNextEvent(10000);
    assertEquals("data2", event2.getEvent());
    segmentNotifier.pollNow();
    SegmentNotification segmentNotificationPostScale = notificationResults.take();
    assertEquals(1, segmentNotificationPostScale.getNumOfReaders());
    assertEquals(2, segmentNotificationPostScale.getNumOfSegments());
}
Also used : EventStreamWriter(io.pravega.client.stream.EventStreamWriter) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Cleanup(lombok.Cleanup) ReaderGroup(io.pravega.client.stream.ReaderGroup) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) EventRead(io.pravega.client.stream.EventRead) EndOfDataNotification(io.pravega.client.stream.notifications.EndOfDataNotification) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) After(org.junit.After) URI(java.net.URI) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EndOfDataNotifier(io.pravega.client.stream.notifications.notifier.EndOfDataNotifier) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Slf4j(lombok.extern.slf4j.Slf4j) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) Controller(io.pravega.client.control.impl.Controller) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) SegmentNotification(io.pravega.client.stream.notifications.SegmentNotification) TestingServerStarter(io.pravega.test.common.TestingServerStarter) TestingServer(org.apache.curator.test.TestingServer) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ReusableLatch(io.pravega.common.util.ReusableLatch) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Listener(io.pravega.client.stream.notifications.Listener) Assert.assertNotNull(org.junit.Assert.assertNotNull) lombok.val(lombok.val) SegmentNotifier(io.pravega.client.stream.notifications.notifier.SegmentNotifier) Assert.assertTrue(org.junit.Assert.assertTrue) EventStreamReader(io.pravega.client.stream.EventStreamReader) Test(org.junit.Test) Assert.assertNull(org.junit.Assert.assertNull) ReaderConfig(io.pravega.client.stream.ReaderConfig) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) HashMap(java.util.HashMap) ReaderGroup(io.pravega.client.stream.ReaderGroup) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SegmentNotification(io.pravega.client.stream.notifications.SegmentNotification) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) lombok.val(lombok.val) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) SegmentNotifier(io.pravega.client.stream.notifications.notifier.SegmentNotifier) Test(org.junit.Test)

Aggregations

StreamImpl (io.pravega.client.stream.impl.StreamImpl)74 Test (org.junit.Test)50 Stream (io.pravega.client.stream.Stream)47 Cleanup (lombok.Cleanup)36 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)32 HashMap (java.util.HashMap)32 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)22 Map (java.util.Map)22 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)21 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)21 Controller (io.pravega.client.control.impl.Controller)21 ClientConfig (io.pravega.client.ClientConfig)20 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)18 Segment (io.pravega.client.segment.impl.Segment)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)16 Slf4j (lombok.extern.slf4j.Slf4j)14 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)13 CompletableFuture (java.util.concurrent.CompletableFuture)12 Before (org.junit.Before)12