use of io.pravega.client.byteStream.ByteStreamWriter 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));
}
use of io.pravega.client.byteStream.ByteStreamWriter 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]);
}
Aggregations