use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.
the class EndToEndReaderGroupTest method testResetSubscriberToNonSubscriberReaderGroup.
@Test(timeout = 30000)
public void testResetSubscriberToNonSubscriberReaderGroup() throws InterruptedException, ExecutionException {
StreamConfiguration config = getStreamConfig();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
String streamName = "testResetSubscriberToNonSubscriberReaderGroup";
controller.createScope("test").get();
controller.createStream("test", streamName, config).get();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
// Create a ReaderGroup
String group = "testResetSubscriberToNonSubscriberReaderGroup-group";
groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build());
List<String> subs = controller.listSubscribers("test", streamName).get();
assertTrue("Subscriber list does not contain required reader group", subs.contains("test/" + group));
ReaderGroup subGroup = groupManager.getReaderGroup(group);
subGroup.resetReaderGroup(ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).build());
subs = controller.listSubscribers("test", streamName).get();
assertFalse("Subscriber list contains required reader group", subs.contains("test/" + group));
}
use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.
the class EndToEndReaderGroupTest method testGenerateStreamCuts.
@Test(timeout = 30000)
public void testGenerateStreamCuts() throws Exception {
String streamName = "testGenerateStreamCuts";
final Stream stream = Stream.of(SCOPE, streamName);
final String group = "testGenerateStreamCuts-group";
createScope(SCOPE);
createStream(SCOPE, streamName, ScalingPolicy.fixed(1));
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(SCOPE, ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
// Prep the stream with data.
// 1.Write events with event size of 30
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(1)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(2)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(3)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(4)).join();
@Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, PRAVEGA.getControllerURI());
groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(1000).stream(stream).build());
ReaderGroup readerGroup = groupManager.getReaderGroup(group);
// Create a reader
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", group, serializer, ReaderConfig.builder().build());
readAndVerify(reader, 1);
@Cleanup("shutdown") InlineExecutor backgroundExecutor = new InlineExecutor();
CompletableFuture<Map<Stream, StreamCut>> sc = readerGroup.generateStreamCuts(backgroundExecutor);
// The reader group state will be updated after 1 second.
TimeUnit.SECONDS.sleep(1);
EventRead<String> data = reader.readNextEvent(15000);
// wait until the streamCut is obtained.
assertTrue(Futures.await(sc));
// expected segment 0 offset is 30L.
Map<Segment, Long> expectedOffsetMap = ImmutableMap.of(getSegment(streamName, 0, 0), 30L);
Map<Stream, StreamCut> scMap = sc.join();
assertEquals("StreamCut for a single stream expected", 1, scMap.size());
assertEquals("StreamCut pointing ot offset 30L expected", new StreamCutImpl(stream, expectedOffsetMap), scMap.get(stream));
}
use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.
the class EndToEndReaderGroupTest method testCreateSubscriberReaderGroup.
@Test(timeout = 30000)
public void testCreateSubscriberReaderGroup() throws InterruptedException, ExecutionException {
StreamConfiguration config = getStreamConfig();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
String streamName = "testCreateSubscriberReaderGroup";
controller.createScope("test").get();
controller.createStream("test", streamName, config).get();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
// Create a ReaderGroup
String groupName = "testCreateSubscriberReaderGroup-group";
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build());
List<String> subs = controller.listSubscribers("test", streamName).get();
assertTrue("Subscriber list does not contain required reader group", subs.contains("test/" + groupName));
}
use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.
the class EndToEndReaderGroupTest method testReaderOfflineWithSilentCheckpoint.
@Test(timeout = 30000)
public void testReaderOfflineWithSilentCheckpoint() throws Exception {
String streamName = "testReaderOfflineWithSilentCheckpoint";
final Stream stream = Stream.of(SCOPE, streamName);
final String group = "testReaderOfflineWithSilentCheckpoint-group";
@Cleanup("shutdown") InlineExecutor backgroundExecutor = new InlineExecutor();
createScope(SCOPE);
createStream(SCOPE, streamName, ScalingPolicy.fixed(1));
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(SCOPE, ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
// Prep the stream with data.
// 1.Write events with event size of 30
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(1)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(2)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(3)).join();
writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(4)).join();
@Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, PRAVEGA.getControllerURI());
groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(1000).stream(stream).build());
ReaderGroup readerGroup = groupManager.getReaderGroup(group);
// Create a reader
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", group, serializer, ReaderConfig.builder().build());
// 2. Read an event.
readAndVerify(reader, 1);
// 3. Trigger a checkpoint and verify it is completed.
CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("chk1", backgroundExecutor);
// The reader group state will be updated after 1 second.
TimeUnit.SECONDS.sleep(1);
EventRead<String> data = reader.readNextEvent(15000);
assertTrue(data.isCheckpoint());
readAndVerify(reader, 2);
assertTrue("Checkpointing should complete successfully", Futures.await(checkpoint));
// 4. GenerateStreamCuts and validate the offset of stream cut.
CompletableFuture<Map<Stream, StreamCut>> sc = readerGroup.generateStreamCuts(backgroundExecutor);
// The reader group state will be updated after 1 second.
TimeUnit.SECONDS.sleep(1);
data = reader.readNextEvent(15000);
assertTrue("StreamCut generation should complete successfully", Futures.await(sc));
// expected segment 0 offset is 60L, since 2 events are read.
Map<Segment, Long> expectedOffsetMap = ImmutableMap.of(getSegment(streamName, 0, 0), 60L);
Map<Stream, StreamCut> scMap = sc.join();
assertEquals("StreamCut for a single stream expected", 1, scMap.size());
assertEquals("StreamCut pointing ot offset 30L expected", new StreamCutImpl(stream, expectedOffsetMap), scMap.get(stream));
// 5. Invoke readerOffline with last position as null. The newer readers should start reading
// from the last checkpointed position
readerGroup.readerOffline("readerId", null);
@Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId", group, serializer, ReaderConfig.builder().build());
readAndVerify(reader1, 2);
}
use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.
the class EndToEndReaderGroupTest method testDeleteReaderGroup.
@Test(timeout = 30000)
public void testDeleteReaderGroup() throws Exception {
StreamConfiguration config = getStreamConfig();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
String streamName = "testDeleteReaderGroup";
controller.createScope("test").get();
controller.createStream("test", streamName, config).get();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
// Create a ReaderGroup
String groupName = "testDeleteReaderGroup-group";
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).build());
// Create a Reader
EventStreamReader<String> reader = clientFactory.createReader("reader1", groupName, serializer, ReaderConfig.builder().build());
// Write events into the stream.
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
writer.writeEvent("0", "data1").get();
EventRead<String> eventRead = reader.readNextEvent(10000);
assertEquals("data1", eventRead.getEvent());
// Close the reader, this internally invokes ReaderGroup#readerOffline
reader.close();
// delete the readerGroup.
groupManager.deleteReaderGroup(groupName);
// create a new readerGroup with the same name.
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).build());
reader = clientFactory.createReader("reader1", groupName, new JavaSerializer<>(), ReaderConfig.builder().build());
eventRead = reader.readNextEvent(10000);
assertEquals("data1", eventRead.getEvent());
}
Aggregations