use of io.pravega.client.EventStreamClientFactory in project pravega by pravega.
the class WatermarkingTest method recreateStreamWatermarkTest.
@Test(timeout = 120000)
public void recreateStreamWatermarkTest() throws Exception {
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(5)).build();
ClientConfig clientConfig = ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build();
@Cleanup StreamManager streamManager = StreamManager.create(clientConfig);
// then delete stream and move to next iteration and verify that watermarks are generated.
for (int i = 0; i < 2; i++) {
String scope = "scope";
String stream = "recreateStreamWatermarkTest";
streamManager.createScope(scope);
streamManager.createStream(scope, stream, config);
// create writer
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(scope, clientConfig);
JavaSerializer<Long> javaSerializer = new JavaSerializer<>();
@Cleanup EventStreamWriter<Long> writer = clientFactory.createEventWriter(stream, javaSerializer, EventWriterConfig.builder().build());
AtomicBoolean stopFlag = new AtomicBoolean(false);
// write events
CompletableFuture<Void> writerFuture = writeEvents(writer, stopFlag);
@Cleanup SynchronizerClientFactory syncClientFactory = SynchronizerClientFactory.withScope(scope, clientConfig);
String markStream = NameUtils.getMarkStreamForStream(stream);
@Cleanup RevisionedStreamClient<Watermark> watermarkReader = syncClientFactory.createRevisionedStreamClient(markStream, new WatermarkSerializer(), SynchronizerConfig.builder().build());
LinkedBlockingQueue<Watermark> watermarks = new LinkedBlockingQueue<>();
fetchWatermarks(watermarkReader, watermarks, stopFlag);
AssertExtensions.assertEventuallyEquals(true, () -> watermarks.size() >= 2, 100000);
// stop run and seal and delete stream
stopFlag.set(true);
writerFuture.join();
streamManager.sealStream(scope, stream);
streamManager.deleteStream(scope, stream);
}
}
use of io.pravega.client.EventStreamClientFactory in project pravega by pravega.
the class BoundedStreamReaderTest method testBoundedStreamTest.
@Test(timeout = 60000)
public void testBoundedStreamTest() throws Exception {
createScope(SCOPE);
createStream(STREAM1);
createStream(STREAM2);
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(SCOPE, ClientConfig.builder().controllerURI(controllerUri).build());
@Cleanup EventStreamWriter<String> writer1 = clientFactory.createEventWriter(STREAM1, serializer, EventWriterConfig.builder().build());
// Prep the stream with data.
// 1.Write events with event size of 30
writer1.writeEvent(keyGenerator.get(), getEventData.apply(1)).get();
writer1.writeEvent(keyGenerator.get(), getEventData.apply(2)).get();
writer1.writeEvent(keyGenerator.get(), getEventData.apply(3)).get();
writer1.writeEvent(keyGenerator.get(), getEventData.apply(4)).get();
@Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, controllerUri);
groupManager.createReaderGroup("group", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, STREAM1), // startStreamCut points to the current HEAD of stream
StreamCut.UNBOUNDED, // endStreamCut points to the offset after two events.(i.e 2 * 30(event size) = 60)
getStreamCut(STREAM1, 60L, 0)).stream(Stream.of(SCOPE, STREAM2)).build());
// Create a reader
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "group", serializer, ReaderConfig.builder().build());
// 2. Verify if endStreamCut configuration is enforced.
readAndVerify(reader, 1, 2);
// The following read should not return events 3, 4 due to the endStreamCut configuration.
Assert.assertNull("Null is expected", reader.readNextEvent(2000).getEvent());
// 3. Write events to the STREAM2.
@Cleanup EventStreamWriter<String> writer2 = clientFactory.createEventWriter(STREAM2, serializer, EventWriterConfig.builder().build());
writer2.writeEvent(keyGenerator.get(), getEventData.apply(5)).get();
writer2.writeEvent(keyGenerator.get(), getEventData.apply(6)).get();
// 4. Verify that events can be read from STREAM2. (Events from STREAM1 are not read since endStreamCut is reached).
readAndVerify(reader, 5, 6);
Assert.assertNull("Null is expected", reader.readNextEvent(2000).getEvent());
}
Aggregations