Search in sources :

Example 1 with ByteBufferSerializer

use of io.pravega.client.stream.impl.ByteBufferSerializer in project pravega by pravega.

the class IdleSegmentTest method testByteBufferEventsWithIdleSegments.

@Test(timeout = 5000)
public void testByteBufferEventsWithIdleSegments() throws ReinitializationRequiredException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerName = "reader";
    String readerGroup = "group";
    int port = TestUtils.getAvailableListenPort();
    ByteBuffer testPayload = ByteBuffer.allocate(100);
    String scope = "Scope1";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, serviceBuilder.getLowPriorityExecutor());
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().stream(Stream.of(scope, streamName)).disableAutomaticCheckpoints().build();
    streamManager.createScope(scope);
    streamManager.createStream(scope, streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(20)).build());
    streamManager.createReaderGroup(readerGroup, groupConfig);
    Serializer<ByteBuffer> serializer = new ByteBufferSerializer();
    @Cleanup EventStreamWriter<ByteBuffer> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
    List<CompletableFuture<Void>> results = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        results.add(producer.writeEvent("FixedRoutingKey", testPayload));
        System.out.println("Writing event " + i);
    }
    producer.flush();
    @Cleanup EventStreamReader<ByteBuffer> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build());
    for (int i = 0; i < 10; i++) {
        ByteBuffer read = reader.readNextEvent(10000).getEvent();
        assertEquals(testPayload, read);
    }
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ArrayList(java.util.ArrayList) ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) ByteBuffer(java.nio.ByteBuffer) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 2 with ByteBufferSerializer

use of io.pravega.client.stream.impl.ByteBufferSerializer in project pravega by pravega.

the class LargeEventTest method startNewReader.

private CompletableFuture<Void> startNewReader(final String readerId, final EventStreamClientFactory clientFactory, final String readerGroupName, final Queue<ByteBuffer> readResult, final AtomicLong writeCount, final AtomicLong readCount, final AtomicBoolean exitFlag) {
    return CompletableFuture.runAsync(() -> {
        @Cleanup final EventStreamReader<ByteBuffer> reader = clientFactory.createReader(readerId, readerGroupName, new ByteBufferSerializer(), ReaderConfig.builder().build());
        log.info("Starting Reader: {}", readerId);
        log.info("Read Count: {}, Write Count: {}", readCount.get(), writeCount.get());
        while (!(exitFlag.get() && readCount.get() == writeCount.get())) {
            final ByteBuffer event = reader.readNextEvent(SECONDS.toMillis(2)).getEvent();
            // Update if event read is not null.
            if (event != null) {
                readResult.add(event);
                readCount.incrementAndGet();
            }
        }
        log.info("Closing Reader : {}", reader);
        reader.close();
    }, readerPool);
}
Also used : ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer)

Example 3 with ByteBufferSerializer

use of io.pravega.client.stream.impl.ByteBufferSerializer in project pravega by pravega.

the class LargeEventTest method startNewWriter.

private CompletableFuture<Void> startNewWriter(final String routingKey, final String streamName, final AtomicLong writeCount, final List<ByteBuffer> data, final EventStreamClientFactory clientFactory) {
    return CompletableFuture.runAsync(() -> {
        @Cleanup final EventStreamWriter<ByteBuffer> writer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().enableLargeEvents(true).build());
        for (ByteBuffer buf : data) {
            log.debug("Writing LargeEvent: [{}/{}]", buf.get(0), buf.get(1));
            writer.writeEvent(routingKey, buf).thenRun(() -> writeCount.incrementAndGet());
        }
        log.info("Closing writer {}", writer);
        writer.close();
    }, writerPool);
}
Also used : ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer)

Example 4 with ByteBufferSerializer

use of io.pravega.client.stream.impl.ByteBufferSerializer in project pravega by pravega.

the class LargeEventTest method largeEventSimpleTest.

/**
 * Invoke the largeEventSimpleTest, ensure we are able to produce  events.
 * The test fails incase of exceptions while writing to the stream.
 */
@Test
public void largeEventSimpleTest() {
    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 SocketConnectionFactoryImpl(Utils.buildClientConfig(controllerUri));
    @Cleanup ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(Utils.buildClientConfig(controllerUri)).build(), connectionFactory.getInternalExecutor());
    assertTrue(controller.createScope(STREAM_SCOPE).join());
    assertTrue(controller.createStream(STREAM_SCOPE, STREAM_NAME, config).join());
    @Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(STREAM_SCOPE, Utils.buildClientConfig(controllerUri));
    log.info("Invoking Writer test with Controller URI: {}", controllerUri);
    @Cleanup EventStreamWriter<ByteBuffer> writer = clientFactory.createEventWriter(STREAM_NAME, new ByteBufferSerializer(), EventWriterConfig.builder().build());
    byte[] payload = new byte[Serializer.MAX_EVENT_SIZE];
    for (int i = 0; i < NUM_EVENTS; i++) {
        log.debug("Producing event: {} ", i);
        // any exceptions while writing the event will fail the test.
        writer.writeEvent("", ByteBuffer.wrap(payload));
        writer.flush();
    }
    log.info("Invoking Reader test.");
    ReaderGroupManager groupManager = ReaderGroupManager.withScope(STREAM_SCOPE, Utils.buildClientConfig(controllerUri));
    groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(STREAM_SCOPE, STREAM_NAME)).build());
    @Cleanup EventStreamReader<ByteBuffer> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new ByteBufferSerializer(), ReaderConfig.builder().build());
    int readCount = 0;
    EventRead<ByteBuffer> event = null;
    do {
        event = reader.readNextEvent(10_000);
        log.debug("Read event: {}.", event.getEvent());
        if (event.getEvent() != null) {
            readCount++;
        }
    // try reading until all the written events are read, else the test will timeout.
    } while ((event.getEvent() != null || event.isCheckpoint()) && readCount < NUM_EVENTS);
    assertEquals("Read count should be equal to write count", NUM_EVENTS, readCount);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) Service(io.pravega.test.system.framework.services.Service) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) URI(java.net.URI) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) Test(org.junit.Test)

Example 5 with ByteBufferSerializer

use of io.pravega.client.stream.impl.ByteBufferSerializer in project pravega by pravega.

the class AppendTest method miniBenchmark.

@Test(timeout = 20000)
public void miniBenchmark() throws InterruptedException, ExecutionException, TimeoutException {
    String endpoint = "localhost";
    String streamName = "miniBenchmark";
    int port = TestUtils.getAvailableListenPort();
    byte[] testPayload = new byte[1000];
    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 MockStreamManager streamManager = new MockStreamManager("Scope", endpoint, port);
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    streamManager.createScope("Scope");
    streamManager.createStream("Scope", streamName, null);
    @Cleanup EventStreamWriter<ByteBuffer> producer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().build());
    long blockingTime = timeWrites(testPayload, 3000, producer, true);
    long nonBlockingTime = timeWrites(testPayload, 60000, producer, false);
    System.out.println("Blocking took: " + blockingTime + "ms.");
    System.out.println("Non blocking took: " + nonBlockingTime + "ms.");
    assertTrue(blockingTime < 10000);
    assertTrue(nonBlockingTime < 10000);
}
Also used : ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ByteBuffer(java.nio.ByteBuffer) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Aggregations

ByteBufferSerializer (io.pravega.client.stream.impl.ByteBufferSerializer)6 ByteBuffer (java.nio.ByteBuffer)6 Cleanup (lombok.Cleanup)6 Test (org.junit.Test)4 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)3 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)3 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)3 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)2 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)2 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)2 ClientConfig (io.pravega.client.ClientConfig)1 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)1 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)1 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)1 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)1 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)1 RawClient (io.pravega.client.connection.impl.RawClient)1 Controller (io.pravega.client.control.impl.Controller)1 ControllerImpl (io.pravega.client.control.impl.ControllerImpl)1 Segment (io.pravega.client.segment.impl.Segment)1