Search in sources :

Example 1 with WriterPosition

use of io.pravega.client.stream.impl.WriterPosition in project pravega by pravega.

the class ControllerWatermarkingTest method watermarkTest.

@Test(timeout = 60000)
public void watermarkTest() throws Exception {
    Controller controller = controllerWrapper.getController();
    String scope = "scope";
    String stream = "stream";
    controller.createScope(scope).join();
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    controller.createStream(scope, stream, config).join();
    String markStream = NameUtils.getMarkStreamForStream(stream);
    Stream streamObj = new StreamImpl(scope, stream);
    WriterPosition pos1 = WriterPosition.builder().segments(Collections.singletonMap(new Segment(scope, stream, 0L), 10L)).build();
    WriterPosition pos2 = WriterPosition.builder().segments(Collections.singletonMap(new Segment(scope, stream, 0L), 20L)).build();
    controller.noteTimestampFromWriter("1", streamObj, 1L, pos1).join();
    controller.noteTimestampFromWriter("2", streamObj, 2L, pos2).join();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
    @Cleanup RevisionedStreamClient<Watermark> reader = clientFactory.createRevisionedStreamClient(markStream, new WatermarkSerializer(), SynchronizerConfig.builder().build());
    AssertExtensions.assertEventuallyEquals(true, () -> {
        Iterator<Entry<Revision, Watermark>> watermarks = reader.readFrom(reader.fetchOldestRevision());
        return watermarks.hasNext();
    }, 30000);
    Iterator<Entry<Revision, Watermark>> watermarks = reader.readFrom(reader.fetchOldestRevision());
    Watermark watermark = watermarks.next().getValue();
    assertEquals(watermark.getLowerTimeBound(), 1L);
    assertTrue(watermark.getStreamCut().entrySet().stream().anyMatch(x -> x.getKey().getSegmentId() == 0L && x.getValue() == 20L));
    controller.sealStream(scope, stream).join();
    controller.deleteStream(scope, stream).join();
    AssertExtensions.assertFutureThrows("Mark Stream should not exist", controller.getCurrentSegments(scope, markStream), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
Also used : Segment(io.pravega.client.segment.impl.Segment) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) AssertExtensions(io.pravega.test.common.AssertExtensions) Exceptions(io.pravega.common.Exceptions) Cleanup(lombok.Cleanup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StoreException(io.pravega.controller.store.stream.StoreException) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Stream(io.pravega.client.stream.Stream) After(org.junit.After) TestingServer(org.apache.curator.test.TestingServer) RevisionedStreamClient(io.pravega.client.state.RevisionedStreamClient) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) WatermarkSerializer(io.pravega.client.watermark.WatermarkSerializer) Iterator(java.util.Iterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) WriterPosition(io.pravega.client.stream.impl.WriterPosition) Watermark(io.pravega.shared.watermarks.Watermark) Entry(java.util.Map.Entry) Revision(io.pravega.client.state.Revision) TestUtils(io.pravega.test.common.TestUtils) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Controller(io.pravega.client.control.impl.Controller) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) WriterPosition(io.pravega.client.stream.impl.WriterPosition) WatermarkSerializer(io.pravega.client.watermark.WatermarkSerializer) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) StoreException(io.pravega.controller.store.stream.StoreException) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Entry(java.util.Map.Entry) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) Watermark(io.pravega.shared.watermarks.Watermark) Test(org.junit.Test)

Aggregations

ClientConfig (io.pravega.client.ClientConfig)1 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)1 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)1 Controller (io.pravega.client.control.impl.Controller)1 Segment (io.pravega.client.segment.impl.Segment)1 Revision (io.pravega.client.state.Revision)1 RevisionedStreamClient (io.pravega.client.state.RevisionedStreamClient)1 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 Stream (io.pravega.client.stream.Stream)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)1 StreamImpl (io.pravega.client.stream.impl.StreamImpl)1 WriterPosition (io.pravega.client.stream.impl.WriterPosition)1 WatermarkSerializer (io.pravega.client.watermark.WatermarkSerializer)1 Exceptions (io.pravega.common.Exceptions)1 StoreException (io.pravega.controller.store.stream.StoreException)1 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)1