Search in sources :

Example 1 with MaxNumberOfCheckpointsExceededException

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());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) MaxNumberOfCheckpointsExceededException(io.pravega.client.stream.impl.MaxNumberOfCheckpointsExceededException) ReaderGroup(io.pravega.client.stream.ReaderGroup) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Checkpoint(io.pravega.client.stream.Checkpoint) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) Checkpoint(io.pravega.client.stream.Checkpoint) InlineExecutor(io.pravega.test.common.InlineExecutor) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Checkpoint (io.pravega.client.stream.Checkpoint)1 ReaderGroup (io.pravega.client.stream.ReaderGroup)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)1 MaxNumberOfCheckpointsExceededException (io.pravega.client.stream.impl.MaxNumberOfCheckpointsExceededException)1 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)1 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)1 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)1 InlineExecutor (io.pravega.test.common.InlineExecutor)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1