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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations