Search in sources :

Example 1 with SegmentSelector

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;
        }
    }
}
Also used : SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) SegmentSelector(io.pravega.client.stream.impl.SegmentSelector) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)1 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 SegmentSelector (io.pravega.client.stream.impl.SegmentSelector)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1