use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class CheckpointTest method testCheckpointAndRestore.
@Test(timeout = 20000)
public void testCheckpointAndRestore() throws ReinitializationRequiredException, InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "abc";
String readerName = "reader";
String readerGroupName = "group";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
String scope = "Scope1";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
MockClientFactory clientFactory = streamManager.getClientFactory();
ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(scope, streamName)).build();
streamManager.createScope(scope);
streamManager.createStream(scope, streamName, StreamConfiguration.builder().scope(scope).streamName(streamName).scalingPolicy(ScalingPolicy.fixed(1)).build());
ReaderGroup readerGroup = streamManager.createReaderGroup(readerGroupName, groupConfig);
JavaSerializer<String> serializer = new JavaSerializer<>();
EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
producer.writeEvent(testString);
producer.writeEvent(testString);
producer.writeEvent(testString);
producer.flush();
AtomicLong clock = new AtomicLong();
@Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
EventRead<String> read = reader.readNextEvent(60000);
assertEquals(testString, read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(60000);
assertEquals(testString, read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
@Cleanup("shutdown") final InlineExecutor backgroundExecutor = new InlineExecutor();
CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("Checkpoint", backgroundExecutor);
assertFalse(checkpoint.isDone());
read = reader.readNextEvent(60000);
assertTrue(read.isCheckpoint());
assertEquals("Checkpoint", read.getCheckpointName());
assertNull(read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(60000);
assertEquals(testString, read.getEvent());
Checkpoint cpResult = checkpoint.get(5, TimeUnit.SECONDS);
assertTrue(checkpoint.isDone());
assertEquals("Checkpoint", cpResult.getName());
read = reader.readNextEvent(100);
assertNull(read.getEvent());
assertFalse(read.isCheckpoint());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(cpResult).build());
try {
reader.readNextEvent(60000);
fail();
} catch (ReinitializationRequiredException e) {
// Expected
}
reader.close();
reader = clientFactory.createReader(readerName, readerGroupName, serializer, ReaderConfig.builder().build());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(60000);
assertEquals(testString, read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(100);
assertNull(read.getEvent());
assertFalse(read.isCheckpoint());
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class StartReader method main.
public static void main(String[] args) throws Exception {
@Cleanup MockStreamManager streamManager = new MockStreamManager(StartLocalService.SCOPE, InetAddress.getLocalHost().getHostAddress(), StartLocalService.SERVICE_PORT);
streamManager.createScope(StartLocalService.SCOPE);
streamManager.createStream(StartLocalService.SCOPE, StartLocalService.STREAM_NAME, null);
streamManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(StartLocalService.SCOPE, StartLocalService.STREAM_NAME)).build());
EventStreamReader<String> reader = streamManager.getClientFactory().createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
for (int i = 0; i < 20; i++) {
String event = reader.readNextEvent(60000).getEvent();
System.err.println("Read event: " + event);
}
reader.close();
System.exit(0);
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class StartWriter method main.
public static void main(String[] args) throws Exception {
@Cleanup MockStreamManager streamManager = new MockStreamManager(StartLocalService.SCOPE, InetAddress.getLocalHost().getHostAddress(), StartLocalService.SERVICE_PORT);
streamManager.createScope(StartLocalService.SCOPE);
streamManager.createStream(StartLocalService.SCOPE, StartLocalService.STREAM_NAME, null);
MockClientFactory clientFactory = streamManager.getClientFactory();
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(StartLocalService.STREAM_NAME, new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutTime(60000).transactionTimeoutScaleGracePeriod(60000).build());
Transaction<String> transaction = writer.beginTxn();
for (int i = 0; i < 10; i++) {
String event = "\n Transactional write \n";
System.err.println("Writing event: " + event);
transaction.writeEvent(event);
transaction.flush();
Thread.sleep(500);
}
for (int i = 0; i < 10; i++) {
String event = "\n Non-transactional Publish \n";
System.err.println("Writing event: " + event);
writer.writeEvent(event);
writer.flush();
Thread.sleep(500);
}
transaction.commit();
System.exit(0);
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class AppendTest method miniBenchmark.
@Test(timeout = 40000)
public void miniBenchmark() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "abc";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
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<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
long blockingTime = timeWrites(testString, 200, producer, true);
long nonBlockingTime = timeWrites(testString, 1000, producer, false);
System.out.println("Blocking took: " + blockingTime + "ms.");
System.out.println("Non blocking took: " + nonBlockingTime + "ms.");
assertTrue(blockingTime < 15000);
assertTrue(nonBlockingTime < 15000);
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class AppendTest method appendThroughStreamingClient.
@Test
public void appendThroughStreamingClient() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "abc";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
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<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
Future<Void> ack = producer.writeEvent(testString);
ack.get(5, TimeUnit.SECONDS);
}
Aggregations