use of io.pravega.client.stream.impl.SegmentSelector in project pravega by pravega.
the class DebugStreamSegmentsTest method testOutOfSequence.
@Test(timeout = 30000)
public void testOutOfSequence() throws Exception {
// 1. Prepare
createScope(SCOPE);
createStream(STREAM);
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
when(streamFactory.createOutputStreamForSegment(any(), any(), any(), any())).thenReturn(mock(SegmentOutputStream.class));
SegmentSelector selector = new SegmentSelector(Stream.of(SCOPE, STREAM), controllerWrapper.getController(), streamFactory, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
// 2.Create clientFactory.
@Cleanup EventStreamClientFactory clientFactoryInternal = EventStreamClientFactory.withScope("_system", ClientConfig.builder().controllerURI(controllerUri).build());
@Cleanup final Controller controller = controllerWrapper.getController();
Segment[] lastSegments = new Segment[100];
for (int i = 0; i < 10; i++) {
randomScaleUpScaleDown(clientFactoryInternal, controller);
selector.refreshSegmentEventWriters(segment -> {
});
for (int key = 0; key < 100; key++) {
Segment segment = selector.getSegmentForEvent("key-" + key);
if (lastSegments[key] != null) {
int lastEpoch = NameUtils.getEpoch(lastSegments[key].getSegmentId());
int thisEpoch = NameUtils.getEpoch(segment.getSegmentId());
assertTrue(thisEpoch >= lastEpoch);
if (thisEpoch == lastEpoch) {
assertEquals(lastSegments[key], segment);
}
}
lastSegments[key] = segment;
}
}
}
Aggregations