Search in sources :

Example 1 with SegmentOutputStreamFactoryImpl

use of io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl in project pravega by pravega.

the class ReadTest method readThroughSegmentClient.

@Test(timeout = 10000)
public void readThroughSegmentClient() throws SegmentSealedException, EndOfSegmentException, SegmentTruncatedException {
    String endpoint = "localhost";
    String scope = "scope";
    String stream = "readThroughSegmentClient";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world\n";
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
    server.startListening();
    @Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
    @Cleanup Controller controller = new MockController(endpoint, port, connectionPool, true);
    controller.createScope(scope);
    controller.createStream(scope, stream, StreamConfiguration.builder().build());
    SegmentOutputStreamFactoryImpl segmentproducerClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
    SegmentInputStreamFactoryImpl segmentConsumerClient = new SegmentInputStreamFactoryImpl(controller, connectionPool);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup SegmentOutputStream out = segmentproducerClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
    out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(testString.getBytes()), new CompletableFuture<>()));
    out.flush();
    @Cleanup EventSegmentReader in = segmentConsumerClient.createEventReaderForSegment(segment);
    ByteBuffer result = in.read();
    assertEquals(ByteBuffer.wrap(testString.getBytes()), result);
    // Test large write followed by read
    out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
    out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
    out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(new byte[150000]), new CompletableFuture<>()));
    assertEquals(in.read().capacity(), 15);
    assertEquals(in.read().capacity(), 15);
    assertEquals(in.read().capacity(), 150000);
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) EventSegmentReader(io.pravega.client.segment.impl.EventSegmentReader) MockController(io.pravega.client.stream.mock.MockController) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) Test(org.junit.Test)

Example 2 with SegmentOutputStreamFactoryImpl

use of io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl in project pravega by pravega.

the class AppendTest method appendThroughSegmentClient.

@Test(timeout = 10000)
public void appendThroughSegmentClient() throws Exception {
    String endpoint = "localhost";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world\n";
    String scope = "scope";
    String stream = "appendThroughSegmentClient";
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
    server.startListening();
    @Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
    @Cleanup Controller controller = new MockController(endpoint, port, connectionPool, true);
    controller.createScope(scope);
    controller.createStream(scope, stream, StreamConfiguration.builder().build());
    SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
    CompletableFuture<Void> ack = new CompletableFuture<>();
    out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(testString.getBytes()), ack));
    ack.get(5, TimeUnit.SECONDS);
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 3 with SegmentOutputStreamFactoryImpl

use of io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl in project pravega by pravega.

the class ByteClientTest method createClientFactory.

ByteStreamClientFactory createClientFactory(String scope) {
    ClientConfig config = ClientConfig.builder().build();
    ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
    ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(Utils.buildClientConfig(controllerURI)).build(), connectionFactory.getInternalExecutor());
    ConnectionPool pool = new ConnectionPoolImpl(config, connectionFactory);
    val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, pool);
    val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, pool);
    val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, pool);
    return new ByteStreamClientImpl(scope, controller, pool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ByteStreamClientImpl(io.pravega.client.byteStream.impl.ByteStreamClientImpl)

Example 4 with SegmentOutputStreamFactoryImpl

use of io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl in project pravega by pravega.

the class ByteStreamClientFactory method withScope.

/**
 * Creates a new instance of ByteStreamClientFactory.
 *
 * @param scope The scope string.
 * @param config Configuration for the client.
 * @return Instance of ByteStreamClientFactory implementation.
 */
static ByteStreamClientFactory withScope(String scope, ClientConfig config) {
    val connectionFactory = new SocketConnectionFactoryImpl(config);
    ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
    val connectionPool = new ConnectionPoolImpl(config, Preconditions.checkNotNull(connectionFactory));
    val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, connectionPool);
    val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
    val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, connectionPool);
    return new ByteStreamClientImpl(scope, controller, connectionPool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
Also used : lombok.val(lombok.val) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ByteStreamClientImpl(io.pravega.client.byteStream.impl.ByteStreamClientImpl)

Example 5 with SegmentOutputStreamFactoryImpl

use of io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl in project pravega by pravega.

the class AppendReconnectTest method reconnectOnSegmentClient.

@Test(timeout = 30000)
public void reconnectOnSegmentClient() throws Exception {
    String endpoint = "localhost";
    int port = TestUtils.getAvailableListenPort();
    byte[] payload = "Hello world\n".getBytes();
    String scope = "scope";
    String stream = "stream";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
    server.startListening();
    @Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
    Controller controller = new MockController(endpoint, port, connectionPool, true);
    controller.createScope(scope);
    controller.createStream(scope, stream, StreamConfiguration.builder().build());
    SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
    CompletableFuture<Void> ack = new CompletableFuture<>();
    out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack));
    for (AutoCloseable c : connectionPool.getActiveChannels()) {
        c.close();
    }
    CompletableFuture<Void> ack2 = new CompletableFuture<>();
    out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack2));
    ack.get(5, TimeUnit.SECONDS);
    ack2.get(5, TimeUnit.SECONDS);
    @Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
    assertEquals(payload.length * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Segment(io.pravega.client.segment.impl.Segment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockController(io.pravega.client.stream.mock.MockController) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) Test(org.junit.Test)

Aggregations

ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)6 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)6 SegmentOutputStreamFactoryImpl (io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl)6 SegmentInputStreamFactoryImpl (io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl)4 SegmentMetadataClientFactoryImpl (io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl)4 ByteStreamClientImpl (io.pravega.client.byteStream.impl.ByteStreamClientImpl)3 Controller (io.pravega.client.control.impl.Controller)3 Segment (io.pravega.client.segment.impl.Segment)3 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)3 MockController (io.pravega.client.stream.mock.MockController)3 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)3 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)3 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Cleanup (lombok.Cleanup)3 lombok.val (lombok.val)3 Test (org.junit.Test)3 ClientConfig (io.pravega.client.ClientConfig)2 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)2 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)2