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)));
}
Aggregations