Search in sources :

Example 66 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class ReadTest method testEventPointer.

@Test(timeout = 10000)
public void testEventPointer() throws ReinitializationRequiredException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerName = "reader";
    String readerGroup = "group";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world ";
    String scope = "Scope1";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
    MockClientFactory clientFactory = streamManager.getClientFactory();
    ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(scope, streamName)).build();
    streamManager.createScope(scope);
    streamManager.createStream(scope, streamName, null);
    streamManager.createReaderGroup(readerGroup, groupConfig);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
    for (int i = 0; i < 100; i++) {
        producer.writeEvent(testString + i);
    }
    producer.flush();
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build());
    try {
        EventPointer pointer;
        String read;
        for (int i = 0; i < 100; i++) {
            pointer = reader.readNextEvent(5000).getEventPointer();
            read = reader.fetchEvent(pointer);
            assertEquals(testString + i, read);
        }
    } catch (NoSuchEventException e) {
        fail("Failed to read event using event pointer");
    }
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) NoSuchEventException(io.pravega.client.segment.impl.NoSuchEventException) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) EventPointer(io.pravega.client.stream.EventPointer) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 67 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class ReadWriteTest method setup.

@Before
public void setup() throws Exception {
    final int controllerPort = TestUtils.getAvailableListenPort();
    final String serviceHost = "localhost";
    final int servicePort = TestUtils.getAvailableListenPort();
    final int containerCount = 4;
    // 1. Start ZK
    this.zkTestServer = new TestingServerStarter().start();
    // 2. Start Pravega SegmentStore service.
    ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    this.server = new PravegaConnectionListener(false, servicePort, store);
    this.server.startListening();
    // 3. Start Pravega Controller service
    this.controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
    this.controllerWrapper.awaitRunning();
    this.controller = controllerWrapper.getController();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Before(org.junit.Before)

Example 68 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class ReaderGroupNotificationTest method setUp.

@Before
public void setUp() throws Exception {
    executor = Executors.newSingleThreadScheduledExecutor();
    zkTestServer = new TestingServerStarter().start();
    serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    server = new PravegaConnectionListener(false, servicePort, store);
    server.startListening();
    controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
    controllerWrapper.awaitRunning();
    listenerLatch.reset();
    listenerInvoked.set(false);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) Before(org.junit.Before)

Example 69 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class ReaderGroupTest method testMultiSegmentsPerReader.

@Test
public void testMultiSegmentsPerReader() throws Exception {
    String endpoint = "localhost";
    int servicePort = TestUtils.getAvailableListenPort();
    @Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, servicePort, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager(SCOPE, endpoint, servicePort);
    streamManager.createScope(SCOPE);
    streamManager.createStream(SCOPE, STREAM_NAME, StreamConfiguration.builder().scope(SCOPE).streamName(STREAM_NAME).scalingPolicy(ScalingPolicy.fixed(2)).build());
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(-1).stream(Stream.of(SCOPE, STREAM_NAME)).build();
    streamManager.createReaderGroup(READER_GROUP, groupConfig);
    writeEvents(100, clientFactory);
    new ReaderThread(100, "Reader", clientFactory).run();
    streamManager.deleteReaderGroup(READER_GROUP);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Example 70 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class StateSynchronizerTest method testSetSynchronizer.

@Test(timeout = 10000)
public void testSetSynchronizer() {
    String endpoint = "localhost";
    String stateName = "abc";
    int port = TestUtils.getAvailableListenPort();
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager("scope", endpoint, port);
    streamManager.createScope("scope");
    streamManager.createStream("scope", stateName, null);
    SetSynchronizer<String> setA = SetSynchronizer.createNewSet(stateName, streamManager.getClientFactory());
    SetSynchronizer<String> setB = SetSynchronizer.createNewSet(stateName, streamManager.getClientFactory());
    setA.add("foo");
    assertEquals(1, setA.getCurrentSize());
    assertTrue(setA.getCurrentValues().contains("foo"));
    setB.update();
    assertEquals(1, setB.getCurrentSize());
    assertTrue(setB.getCurrentValues().contains("foo"));
    setA.add("bar");
    assertEquals(1, setB.getCurrentSize());
    assertTrue(setB.getCurrentValues().contains("foo"));
    setB.update();
    assertEquals(2, setB.getCurrentSize());
    assertTrue(setB.getCurrentValues().contains("bar"));
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Test(org.junit.Test)

Aggregations

StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)75 Test (org.junit.Test)52 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)45 Cleanup (lombok.Cleanup)40 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)25 UUID (java.util.UUID)23 TestingServerStarter (io.pravega.test.common.TestingServerStarter)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)19 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)18 Before (org.junit.Before)17 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)16 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)15 Append (io.pravega.shared.protocol.netty.Append)14 CompletableFuture (java.util.concurrent.CompletableFuture)12 FailingRequestProcessor (io.pravega.shared.protocol.netty.FailingRequestProcessor)11 WireCommands (io.pravega.shared.protocol.netty.WireCommands)11 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Controller (io.pravega.client.stream.impl.Controller)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)10