Search in sources :

Example 16 with ControllerImpl

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.");
}
Also used : ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Serializable(java.io.Serializable) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) ClientFactory(io.pravega.client.ClientFactory) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Aggregations

ControllerImpl (io.pravega.client.stream.impl.ControllerImpl)16 URI (java.net.URI)13 Service (io.pravega.test.system.framework.services.Service)12 Before (org.junit.Before)11 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)9 Test (org.junit.Test)8 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)7 ClientFactory (io.pravega.client.ClientFactory)6 Controller (io.pravega.client.stream.impl.Controller)6 Cleanup (lombok.Cleanup)6 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)5 Transaction (io.pravega.client.stream.Transaction)5 ExecutionException (java.util.concurrent.ExecutionException)5 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)4 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)4 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)4 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)4 StreamImpl (io.pravega.client.stream.impl.StreamImpl)4 Futures (io.pravega.common.concurrent.Futures)4 Retry (io.pravega.common.util.Retry)4