Search in sources :

Example 1 with CollectingExecutor

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

the class EventStreamWriterTest method testAutoNoteTime.

@Test
public void testAutoNoteTime() {
    String scope = "scope";
    String streamName = "stream";
    StreamImpl stream = new StreamImpl(scope, streamName);
    Segment segment1 = new Segment(scope, streamName, 0);
    EventWriterConfig config = EventWriterConfig.builder().automaticallyNoteTime(true).build();
    SegmentOutputStream mockOutputStream = Mockito.mock(SegmentOutputStream.class);
    SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
    Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment1), any(), any(), any())).thenReturn(mockOutputStream);
    Controller controller = Mockito.mock(Controller.class);
    Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment1));
    Mockito.when(mockOutputStream.getLastObservedWriteOffset()).thenReturn(1111L);
    CollectingExecutor executor = new CollectingExecutor();
    JavaSerializer<String> serializer = new JavaSerializer<>();
    @Cleanup EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, "id", controller, streamFactory, serializer, config, executor, executor, null);
    List<Runnable> tasks = executor.getScheduledTasks();
    assertEquals(1, tasks.size());
    tasks.get(0).run();
    ImmutableMap<Segment, Long> expectedOffsets = ImmutableMap.of(segment1, 1111L);
    Mockito.verify(controller).noteTimestampFromWriter(eq("id"), eq(stream), Mockito.anyLong(), eq(new WriterPosition(expectedOffsets)));
}
Also used : Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) CollectingExecutor(io.pravega.test.common.CollectingExecutor) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Test(org.junit.Test)

Aggregations

Controller (io.pravega.client.control.impl.Controller)1 Segment (io.pravega.client.segment.impl.Segment)1 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)1 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)1 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)1 CollectingExecutor (io.pravega.test.common.CollectingExecutor)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1