Search in sources :

Example 6 with ByteStreamClientFactory

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

the class ByteStreamTest method readLargeWrite.

@Test(timeout = 30000)
public void readLargeWrite() throws IOException {
    String scope = "ByteStreamTest";
    String stream = "readLargeWrite";
    StreamConfiguration config = StreamConfiguration.builder().build();
    @Cleanup StreamManager streamManager = new StreamManagerImpl(PRAVEGA.getLocalController(), Mockito.mock(ConnectionPool.class));
    // create a scope
    Boolean createScopeStatus = streamManager.createScope(scope);
    log.info("Create scope status {}", createScopeStatus);
    // create a stream
    Boolean createStreamStatus = streamManager.createStream(scope, stream, config);
    log.info("Create stream status {}", createStreamStatus);
    @Cleanup ByteStreamClientFactory client = createClientFactory(scope);
    byte[] payload = new byte[2 * PendingEvent.MAX_WRITE_SIZE + 2];
    Arrays.fill(payload, (byte) 7);
    byte[] readBuffer = new byte[PendingEvent.MAX_WRITE_SIZE];
    Arrays.fill(readBuffer, (byte) 0);
    @Cleanup ByteStreamWriter writer = client.createByteStreamWriter(stream);
    @Cleanup ByteStreamReader reader = client.createByteStreamReader(stream);
    writer.write(payload);
    writer.closeAndSeal();
    assertEquals(PendingEvent.MAX_WRITE_SIZE, StreamHelpers.readAll(reader, readBuffer, 0, readBuffer.length));
    assertEquals(7, readBuffer[readBuffer.length - 1]);
    Arrays.fill(readBuffer, (byte) 0);
    assertEquals(PendingEvent.MAX_WRITE_SIZE, StreamHelpers.readAll(reader, readBuffer, 0, readBuffer.length));
    assertEquals(7, readBuffer[readBuffer.length - 1]);
    Arrays.fill(readBuffer, (byte) 0);
    assertEquals(2, reader.read(readBuffer));
    assertEquals(7, readBuffer[0]);
    assertEquals(7, readBuffer[1]);
    assertEquals(0, readBuffer[2]);
    assertEquals(-1, reader.read(readBuffer));
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) StreamManager(io.pravega.client.admin.StreamManager) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ByteStreamReader(io.pravega.client.byteStream.ByteStreamReader) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) Cleanup(lombok.Cleanup) ByteStreamClientFactory(io.pravega.client.ByteStreamClientFactory) ByteStreamWriter(io.pravega.client.byteStream.ByteStreamWriter) Test(org.junit.Test)

Example 7 with ByteStreamClientFactory

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

the class ByteStreamTest method verifyByteClientReadWrite.

@SneakyThrows(IOException.class)
private void verifyByteClientReadWrite(String scope, String stream) {
    @Cleanup ByteStreamClientFactory client = createClientFactory(scope);
    byte[] payload = new byte[100];
    Arrays.fill(payload, (byte) 1);
    byte[] readBuffer = new byte[200];
    Arrays.fill(readBuffer, (byte) 0);
    @Cleanup ByteStreamWriter writer = client.createByteStreamWriter(stream);
    @Cleanup ByteStreamReader reader = client.createByteStreamReader(stream);
    AssertExtensions.assertBlocks(() -> {
        assertEquals(100, reader.read(readBuffer));
    }, () -> writer.write(payload));
    assertEquals(1, readBuffer[99]);
    assertEquals(0, readBuffer[100]);
}
Also used : ByteStreamReader(io.pravega.client.byteStream.ByteStreamReader) Cleanup(lombok.Cleanup) ByteStreamClientFactory(io.pravega.client.ByteStreamClientFactory) ByteStreamWriter(io.pravega.client.byteStream.ByteStreamWriter) SneakyThrows(lombok.SneakyThrows)

Aggregations

ByteStreamClientFactory (io.pravega.client.ByteStreamClientFactory)7 ByteStreamReader (io.pravega.client.byteStream.ByteStreamReader)7 ByteStreamWriter (io.pravega.client.byteStream.ByteStreamWriter)7 Cleanup (lombok.Cleanup)7 Test (org.junit.Test)6 StreamManager (io.pravega.client.admin.StreamManager)4 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)4 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)4 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)4 IOException (java.io.IOException)2 SegmentTruncatedException (io.pravega.client.segment.impl.SegmentTruncatedException)1 CompletionException (java.util.concurrent.CompletionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SneakyThrows (lombok.SneakyThrows)1