Search in sources :

Example 41 with InlineExecutor

use of io.pravega.test.common.InlineExecutor in project pravega by pravega.

the class EndToEndReaderGroupTest method testReaderOfflineWithSilentCheckpoint.

@Test(timeout = 30000)
public void testReaderOfflineWithSilentCheckpoint() throws Exception {
    String streamName = "testReaderOfflineWithSilentCheckpoint";
    final Stream stream = Stream.of(SCOPE, streamName);
    final String group = "testReaderOfflineWithSilentCheckpoint-group";
    @Cleanup("shutdown") InlineExecutor backgroundExecutor = new InlineExecutor();
    createScope(SCOPE);
    createStream(SCOPE, streamName, ScalingPolicy.fixed(1));
    @Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(SCOPE, ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
    // Prep the stream with data.
    // 1.Write events with event size of 30
    writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(1)).join();
    writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(2)).join();
    writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(3)).join();
    writer.writeEvent(randomKeyGenerator.get(), getEventData.apply(4)).join();
    @Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, PRAVEGA.getControllerURI());
    groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(1000).stream(stream).build());
    ReaderGroup readerGroup = groupManager.getReaderGroup(group);
    // Create a reader
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", group, serializer, ReaderConfig.builder().build());
    // 2. Read an event.
    readAndVerify(reader, 1);
    // 3. Trigger a checkpoint and verify it is completed.
    CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("chk1", backgroundExecutor);
    // The reader group state will be updated after 1 second.
    TimeUnit.SECONDS.sleep(1);
    EventRead<String> data = reader.readNextEvent(15000);
    assertTrue(data.isCheckpoint());
    readAndVerify(reader, 2);
    assertTrue("Checkpointing should complete successfully", Futures.await(checkpoint));
    // 4. GenerateStreamCuts and validate the offset of stream cut.
    CompletableFuture<Map<Stream, StreamCut>> sc = readerGroup.generateStreamCuts(backgroundExecutor);
    // The reader group state will be updated after 1 second.
    TimeUnit.SECONDS.sleep(1);
    data = reader.readNextEvent(15000);
    assertTrue("StreamCut generation should complete successfully", Futures.await(sc));
    // expected segment 0 offset is 60L, since 2 events are read.
    Map<Segment, Long> expectedOffsetMap = ImmutableMap.of(getSegment(streamName, 0, 0), 60L);
    Map<Stream, StreamCut> scMap = sc.join();
    assertEquals("StreamCut for a single stream expected", 1, scMap.size());
    assertEquals("StreamCut pointing ot offset 30L expected", new StreamCutImpl(stream, expectedOffsetMap), scMap.get(stream));
    // 5. Invoke readerOffline with last position as null. The newer readers should start reading
    // from the last checkpointed position
    readerGroup.readerOffline("readerId", null);
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId", group, serializer, ReaderConfig.builder().build());
    readAndVerify(reader1, 2);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ReaderGroup(io.pravega.client.stream.ReaderGroup) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Checkpoint(io.pravega.client.stream.Checkpoint) InlineExecutor(io.pravega.test.common.InlineExecutor) Stream(io.pravega.client.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 42 with InlineExecutor

use of io.pravega.test.common.InlineExecutor in project pravega by pravega.

the class EndToEndChannelLeakTest method setUp.

@Before
public void setUp() throws Exception {
    executor = new InlineExecutor();
    zkTestServer = new TestingServerStarter().start();
    serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    server = new PravegaConnectionListener(false, servicePort, store, tableStore, this.serviceBuilder.getLowPriorityExecutor());
    server.startListening();
    controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
    controllerWrapper.awaitRunning();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) InlineExecutor(io.pravega.test.common.InlineExecutor) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Before(org.junit.Before)

Example 43 with InlineExecutor

use of io.pravega.test.common.InlineExecutor in project pravega by pravega.

the class MultiKeyLatestItemSequentialProcessorTest method testRunsItems.

@Test
public void testRunsItems() {
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    AtomicBoolean ran = new AtomicBoolean(false);
    MultiKeyLatestItemSequentialProcessor<String, String> processor = new MultiKeyLatestItemSequentialProcessor<>((k, v) -> ran.set(true), executor);
    processor.updateItem("k1", "Foo");
    assertTrue(ran.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 44 with InlineExecutor

use of io.pravega.test.common.InlineExecutor in project pravega by pravega.

the class AppendProcessorTest method testSetupTokenExpiryTaskClosesConnectionIfTokenHasExpired.

@Test
public void testSetupTokenExpiryTaskClosesConnectionIfTokenHasExpired() {
    // Arrange
    String streamSegmentName = "scope/stream/0.#epoch.0";
    UUID clientId = UUID.randomUUID();
    StreamSegmentStore mockStore = mock(StreamSegmentStore.class);
    ServerConnection mockConnection = mock(ServerConnection.class);
    @Cleanup("shutdown") ScheduledExecutorService executor = new InlineExecutor();
    @Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(mockStore).connection(new TrackedConnection(mockConnection)).tokenExpiryHandlerExecutor(executor).build();
    // Spy the actual Append Processor, so that we can have some of the methods return stubbed values.
    AppendProcessor mockProcessor = spy(processor);
    doReturn(true).when(mockProcessor).isSetupAppendCompleted(streamSegmentName, clientId);
    JsonWebToken token = new JsonWebToken("subject", "audience", "secret".getBytes(), Date.from(Instant.now().minusSeconds(5)), null);
    SetupAppend setupAppend = new SetupAppend(1, clientId, streamSegmentName, token.toCompactString());
    // Act
    mockProcessor.setupTokenExpiryTask(setupAppend, token).join();
    // Assert
    verify(mockConnection).close();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InlineExecutor(io.pravega.test.common.InlineExecutor) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) Cleanup(lombok.Cleanup) JsonWebToken(io.pravega.shared.security.token.JsonWebToken) Test(org.junit.Test)

Example 45 with InlineExecutor

use of io.pravega.test.common.InlineExecutor in project pravega by pravega.

the class AppendProcessorTest method testSetupTokenExpiryWhenConnectionSendThrowsException.

@Test
public void testSetupTokenExpiryWhenConnectionSendThrowsException() {
    // Arrange
    String streamSegmentName = "scope/stream/0.#epoch.0";
    UUID clientId = UUID.randomUUID();
    StreamSegmentStore mockStore = mock(StreamSegmentStore.class);
    ServerConnection mockConnection = mock(ServerConnection.class);
    @Cleanup("shutdown") ScheduledExecutorService executor = new InlineExecutor();
    @Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(mockStore).connection(new TrackedConnection(mockConnection)).tokenExpiryHandlerExecutor(executor).build();
    // Spy the actual Append Processor, so that we can have some of the methods return stubbed values.
    AppendProcessor mockProcessor = spy(processor);
    doReturn(true).when(mockProcessor).isSetupAppendCompleted(streamSegmentName, clientId);
    doThrow(new RuntimeException()).when(mockConnection).send(any());
    Date expiryDate = Date.from(Instant.now().plusMillis(300));
    JsonWebToken token = new JsonWebToken("subject", "audience", "secret".getBytes(), expiryDate, null);
    SetupAppend setupAppend = new SetupAppend(1, clientId, streamSegmentName, token.toCompactString());
    // Act
    mockProcessor.setupTokenExpiryTask(setupAppend, token).join();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) JsonWebToken(io.pravega.shared.security.token.JsonWebToken) Date(java.util.Date) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) InlineExecutor(io.pravega.test.common.InlineExecutor) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

InlineExecutor (io.pravega.test.common.InlineExecutor)54 Test (org.junit.Test)52 Cleanup (lombok.Cleanup)51 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)17 UUID (java.util.UUID)13 Segment (io.pravega.client.segment.impl.Segment)11 WireCommands (io.pravega.shared.protocol.netty.WireCommands)11 ReaderGroup (io.pravega.client.stream.ReaderGroup)10 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)10 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)9 Stream (io.pravega.client.stream.Stream)9 Append (io.pravega.shared.protocol.netty.Append)9 Checkpoint (io.pravega.client.stream.Checkpoint)8 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)8 Event (io.pravega.shared.protocol.netty.WireCommands.Event)8 HashMap (java.util.HashMap)8 ClientConfig (io.pravega.client.ClientConfig)7 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)7 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)7 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)6