use of io.pravega.client.stream.notifications.EndOfDataNotification in project pravega by pravega.
the class EndOfDataNotifier method checkAndTriggerEndOfStreamNotification.
private void checkAndTriggerEndOfStreamNotification() {
this.synchronizer.fetchUpdates();
ReaderGroupState state = this.synchronizer.getState();
if (state == null) {
log.warn("Current state of StateSynchronizer {} is null, will try again.", synchronizer);
} else if (state.isEndOfData()) {
notifySystem.notify(new EndOfDataNotification());
}
}
use of io.pravega.client.stream.notifications.EndOfDataNotification 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());
}
Aggregations