use of io.pravega.client.stream.impl.MaxNumberOfCheckpointsExceededException in project pravega by pravega.
the class CheckpointTest method testMaxPendingCheckpoint.
@Test(timeout = 20000)
public void testMaxPendingCheckpoint() throws ReinitializationRequiredException, InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "testGenerateStreamCuts";
String readerGroupName = "testGenerateStreamCuts-group1";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
String scope = "Scope12";
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();
int maxOutstandingCheckpointRequest = 1;
ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().stream(Stream.of(scope, streamName)).maxOutstandingCheckpointRequest(maxOutstandingCheckpointRequest).build();
streamManager.createScope(scope);
streamManager.createStream(scope, streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
streamManager.createReaderGroup(readerGroupName, groupConfig);
@Cleanup ReaderGroup readerGroup = streamManager.getReaderGroup(readerGroupName);
JavaSerializer<String> serializer = new JavaSerializer<>();
@Cleanup 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> reader1 = clientFactory.createReader("reader1", readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
@Cleanup EventStreamReader<String> reader2 = clientFactory.createReader("reader2", readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
@Cleanup("shutdown") final InlineExecutor backgroundExecutor1 = new InlineExecutor();
@Cleanup("shutdown") final InlineExecutor backgroundExecutor2 = new InlineExecutor();
CompletableFuture<Checkpoint> checkpoint1 = readerGroup.initiateCheckpoint("Checkpoint1", backgroundExecutor1);
assertFalse(checkpoint1.isDone());
CompletableFuture<Checkpoint> checkpoint2 = readerGroup.initiateCheckpoint("Checkpoint2", backgroundExecutor2);
assertTrue(checkpoint2.isCompletedExceptionally());
try {
checkpoint2.get();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof MaxNumberOfCheckpointsExceededException);
assertTrue(e.getCause().getMessage().equals("rejecting checkpoint request since pending checkpoint reaches max allowed limit"));
}
EventRead<String> read = reader1.readNextEvent(100);
assertTrue(read.isCheckpoint());
assertEquals("Checkpoint1", read.getCheckpointName());
assertNull(read.getEvent());
read = reader2.readNextEvent(100);
assertTrue(read.isCheckpoint());
assertEquals("Checkpoint1", read.getCheckpointName());
assertNull(read.getEvent());
read = reader1.readNextEvent(100);
assertFalse(read.isCheckpoint());
read = reader2.readNextEvent(100);
assertFalse(read.isCheckpoint());
Checkpoint cpResult = checkpoint1.get(5, TimeUnit.SECONDS);
assertTrue(checkpoint1.isDone());
assertEquals("Checkpoint1", cpResult.getName());
}
Aggregations