Search in sources :

Example 46 with ClientFactory

use of io.pravega.client.ClientFactory in project pravega by pravega.

the class ReaderCheckpointTest method writeEvents.

private <T extends Serializable> void writeEvents(final List<T> events) {
    try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
        EventStreamWriter<T> writer = clientFactory.createEventWriter(STREAM, new JavaSerializer<T>(), EventWriterConfig.builder().build())) {
        for (T event : events) {
            String routingKey = String.valueOf(event);
            log.info("Writing message: {} with routing-key: {} to stream {}", event, routingKey, STREAM);
            writer.writeEvent(routingKey, event);
        }
    }
}
Also used : ClientFactory(io.pravega.client.ClientFactory)

Example 47 with ClientFactory

use of io.pravega.client.ClientFactory 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

ClientFactory (io.pravega.client.ClientFactory)47 Cleanup (lombok.Cleanup)39 Test (org.junit.Test)36 HashMap (java.util.HashMap)22 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)21 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)20 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)20 Controller (io.pravega.client.stream.impl.Controller)17 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)15 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)15 MockController (io.pravega.client.stream.mock.MockController)15 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)15 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)15 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)14 Stream (io.pravega.client.stream.Stream)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 Segment (io.pravega.client.segment.impl.Segment)12 StreamImpl (io.pravega.client.stream.impl.StreamImpl)12 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)10 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)9