use of io.pravega.client.stream.impl.ControllerImpl in project pravega by pravega.
the class RetentionTest method retentionTest.
@Test
public void retentionTest() throws Exception {
ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURI).build()).build(), connectionFactory.getInternalExecutor());
ClientFactory clientFactory = new ClientFactoryImpl(SCOPE, controller);
log.info("Invoking Writer test with Controller URI: {}", controllerURI);
// create a writer
EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(STREAM, new JavaSerializer<>(), EventWriterConfig.builder().build());
// write an event
String writeEvent = "event";
writer.writeEvent(writeEvent);
writer.flush();
log.debug("Writing event: {} ", writeEvent);
// sleep for 4 mins
Exceptions.handleInterrupted(() -> Thread.sleep(5 * 60 * 1000));
// create a reader
ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, controllerURI);
groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, STREAM)).build());
EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
// expectation is it should have been truncated and we should find stream to be empty
try {
String readEvent = reader.readNextEvent(6000).getEvent();
log.debug("Reading event: {} ", readEvent);
assertEquals(null, readEvent);
} catch (ReinitializationRequiredException e) {
log.error("Unexpected request to reinitialize {}", e);
Assert.fail("Unexpected request to reinitialize.Test failed.");
}
log.debug("The stream is already truncated.Simple retention test passed.");
}
Aggregations