Search in sources :

Example 1 with ConnectionFactory

use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.

the class EndToEndTxnWithScaleTest method testTxnWithScale.

@Test(timeout = 10000)
public void testTxnWithScale() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope("test").get();
    controller.createStream(config).get();
    @Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ClientFactory clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
    @Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutScaleGracePeriod(10000).transactionTimeoutTime(10000).build());
    Transaction<String> transaction = test.beginTxn();
    transaction.writeEvent("0", "txntest1");
    transaction.commit();
    // scale
    Stream stream = new StreamImpl("test", "test");
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.33);
    map.put(0.33, 0.66);
    map.put(0.66, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0), map, executorService).getFuture().get();
    assertTrue(result);
    transaction = test.beginTxn();
    transaction.writeEvent("0", "txntest2");
    transaction.commit();
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory, connectionFactory);
    groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/test").build());
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().build());
    EventRead<String> event = reader.readNextEvent(10000);
    assertNotNull(event);
    assertEquals("txntest1", event.getEvent());
    event = reader.readNextEvent(10000);
    assertNotNull(event);
    assertEquals("txntest2", event.getEvent());
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ClientFactory(io.pravega.client.ClientFactory) Controller(io.pravega.client.stream.impl.Controller) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Example 2 with ConnectionFactory

use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.

the class PravegaTest method createStream.

/**
 * Invoke the createStream method, ensure we are able to create stream.
 *
 * @throws InterruptedException if interrupted
 * @throws URISyntaxException   If URI is invalid
 * @throws ExecutionException   if error in create stream
 */
@Before
public void createStream() throws InterruptedException, ExecutionException {
    Service conService = Utils.createPravegaControllerService(null);
    List<URI> ctlURIs = conService.getServiceDetails();
    URI controllerUri = ctlURIs.get(0);
    log.info("Invoking create stream with Controller URI: {}", controllerUri);
    @Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
    ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerUri).build()).build(), connectionFactory.getInternalExecutor());
    assertTrue(controller.createScope(STREAM_SCOPE).get());
    assertTrue(controller.createStream(config).get());
}
Also used : ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) Service(io.pravega.test.system.framework.services.Service) URI(java.net.URI) Cleanup(lombok.Cleanup) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Before(org.junit.Before)

Example 3 with ConnectionFactory

use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.

the class SegmentHelper method sendRequestAsync.

private <ResultT> void sendRequestAsync(final WireCommand request, final ReplyProcessor replyProcessor, final CompletableFuture<ResultT> resultFuture, final ConnectionFactory connectionFactory, final PravegaNodeUri uri) {
    CompletableFuture<ClientConnection> connectionFuture = connectionFactory.establishConnection(uri, replyProcessor);
    connectionFuture.whenComplete((connection, e) -> {
        if (connection == null) {
            resultFuture.completeExceptionally(new WireCommandFailedException(new ConnectionFailedException(e), request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
        } else {
            try {
                connection.send(request);
            } catch (ConnectionFailedException cfe) {
                throw new WireCommandFailedException(cfe, request.getType(), WireCommandFailedException.Reason.ConnectionFailed);
            } catch (Exception e2) {
                throw new RuntimeException(e2);
            }
        }
    }).exceptionally(e -> {
        Throwable cause = Exceptions.unwrap(e);
        if (cause instanceof WireCommandFailedException) {
            resultFuture.completeExceptionally(cause);
        } else if (cause instanceof ConnectionFailedException) {
            resultFuture.completeExceptionally(new WireCommandFailedException(cause, request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
        } else {
            resultFuture.completeExceptionally(new RuntimeException(cause));
        }
        return null;
    });
    resultFuture.whenComplete((result, e) -> {
        connectionFuture.thenAccept(ClientConnection::close);
    });
}
Also used : ClientConnection(io.pravega.client.netty.impl.ClientConnection) AuthenticationException(io.pravega.common.auth.AuthenticationException) Segment(io.pravega.client.segment.impl.Segment) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) Pair(org.apache.commons.lang3.tuple.Pair) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) ModelHelper(io.pravega.client.stream.impl.ModelHelper) Host(io.pravega.common.cluster.Host) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AtomicLong(java.util.concurrent.atomic.AtomicLong) Slf4j(lombok.extern.slf4j.Slf4j) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) ClientConnection(io.pravega.client.netty.impl.ClientConnection) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException)

Example 4 with ConnectionFactory

use of io.pravega.client.netty.impl.ConnectionFactory 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

ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)4 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)3 ClientFactory (io.pravega.client.ClientFactory)2 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)2 ControllerImpl (io.pravega.client.stream.impl.ControllerImpl)2 Cleanup (lombok.Cleanup)2 Test (org.junit.Test)2 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)1 ClientConnection (io.pravega.client.netty.impl.ClientConnection)1 Segment (io.pravega.client.segment.impl.Segment)1 ReinitializationRequiredException (io.pravega.client.stream.ReinitializationRequiredException)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 Stream (io.pravega.client.stream.Stream)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 Controller (io.pravega.client.stream.impl.Controller)1 ModelHelper (io.pravega.client.stream.impl.ModelHelper)1 StreamImpl (io.pravega.client.stream.impl.StreamImpl)1 Exceptions (io.pravega.common.Exceptions)1 AuthenticationException (io.pravega.common.auth.AuthenticationException)1