Search in sources :

Example 16 with StreamSegmentStore

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

the class StateSynchronizerTest method testStateTracker.

@Test(timeout = 20000)
public void testStateTracker() {
    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);
    JavaSerializer<TestUpdate> serializer = new JavaSerializer<TestUpdate>();
    @Cleanup val a = streamManager.getClientFactory().createStateSynchronizer(stateName, serializer, serializer, SynchronizerConfig.builder().build());
    @Cleanup val b = streamManager.getClientFactory().createStateSynchronizer(stateName, serializer, serializer, SynchronizerConfig.builder().build());
    a.initialize(new TestUpdate("init"));
    b.fetchUpdates();
    assertEquals("init", b.getState().value);
    assertEquals(1, update(a, "already up to date 1"));
    assertEquals(2, update(b, "fail Initially 2"));
    assertEquals("already up to date 1", a.getState().value);
    assertEquals("fail Initially 2", b.getState().value);
    assertEquals(1, update(b, "already up to date 3"));
    assertEquals("already up to date 1", a.getState().value);
    a.fetchUpdates();
    assertEquals("already up to date 3", a.getState().value);
    assertEquals(1, update(a, "already up to date 4"));
    assertEquals("already up to date 4", a.getState().value);
    assertEquals("already up to date 3", b.getState().value);
    assertEquals(2, update(b, "fail Initially 5"));
    assertEquals("already up to date 4", a.getState().value);
    a.fetchUpdates();
    assertEquals("fail Initially 5", a.getState().value);
    a.fetchUpdates();
    b.fetchUpdates();
    assertEquals("fail Initially 5", a.getState().value);
    assertEquals("fail Initially 5", b.getState().value);
}
Also used : lombok.val(lombok.val) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Test(org.junit.Test)

Example 17 with StreamSegmentStore

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

the class StreamCutsTest 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();
}
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 18 with StreamSegmentStore

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

the class TransactionTest method testDrop.

@Test
public void testDrop() throws TxnFailedException, ReinitializationRequiredException {
    String endpoint = "localhost";
    String groupName = "group";
    String streamName = "abc";
    int port = TestUtils.getAvailableListenPort();
    String txnEvent = "TXN Event\n";
    String nonTxEvent = "Non-TX Event\n";
    String routingKey = "RoutingKey";
    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", streamName, StreamConfiguration.builder().build());
    streamManager.createReaderGroup(groupName, ReaderGroupConfig.builder().stream(Stream.of("scope", streamName)).build());
    MockClientFactory clientFactory = streamManager.getClientFactory();
    @Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutTime(60000).transactionTimeoutScaleGracePeriod(60000).build());
    Transaction<String> transaction = producer.beginTxn();
    transaction.writeEvent(routingKey, txnEvent);
    transaction.flush();
    transaction.abort();
    transaction.abort();
    AssertExtensions.assertThrows(TxnFailedException.class, () -> transaction.writeEvent(routingKey, txnEvent));
    AssertExtensions.assertThrows(TxnFailedException.class, () -> transaction.commit());
    @Cleanup EventStreamReader<Serializable> consumer = streamManager.getClientFactory().createReader("reader", groupName, new JavaSerializer<>(), ReaderConfig.builder().build());
    producer.writeEvent(routingKey, nonTxEvent);
    producer.flush();
    assertEquals(nonTxEvent, consumer.readNextEvent(1500).getEvent());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Serializable(java.io.Serializable) 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) Test(org.junit.Test)

Example 19 with StreamSegmentStore

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

the class TransactionTest method testTransactionalWritesOrderedCorrectly.

@Test
public void testTransactionalWritesOrderedCorrectly() throws TxnFailedException, ReinitializationRequiredException {
    int readTimeout = 5000;
    String readerName = "reader";
    String groupName = "group";
    String endpoint = "localhost";
    String streamName = "abc";
    int port = TestUtils.getAvailableListenPort();
    String txnEvent = "TXN Event\n";
    String nonTxEvent = "Non-TX Event\n";
    String routingKey = "RoutingKey";
    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", streamName, StreamConfiguration.builder().build());
    streamManager.createReaderGroup(groupName, ReaderGroupConfig.builder().stream(Stream.of("scope", streamName)).build());
    MockClientFactory clientFactory = streamManager.getClientFactory();
    @Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutTime(60000).transactionTimeoutScaleGracePeriod(60000).build());
    producer.writeEvent(routingKey, nonTxEvent);
    Transaction<String> transaction = producer.beginTxn();
    producer.writeEvent(routingKey, nonTxEvent);
    transaction.writeEvent(routingKey, txnEvent);
    producer.writeEvent(routingKey, nonTxEvent);
    transaction.writeEvent(routingKey, txnEvent);
    producer.flush();
    producer.writeEvent(routingKey, nonTxEvent);
    transaction.writeEvent(routingKey, txnEvent);
    producer.writeEvent(routingKey, nonTxEvent);
    transaction.writeEvent(routingKey, txnEvent);
    transaction.flush();
    producer.writeEvent(routingKey, nonTxEvent);
    transaction.writeEvent(routingKey, txnEvent);
    producer.flush();
    transaction.writeEvent(routingKey, txnEvent);
    transaction.commit();
    producer.writeEvent(routingKey, nonTxEvent);
    AssertExtensions.assertThrows(TxnFailedException.class, () -> transaction.writeEvent(routingKey, txnEvent));
    EventStreamReader<Serializable> consumer = streamManager.getClientFactory().createReader(readerName, groupName, new JavaSerializer<>(), ReaderConfig.builder().build());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(txnEvent, consumer.readNextEvent(readTimeout).getEvent());
    assertEquals(nonTxEvent, consumer.readNextEvent(readTimeout).getEvent());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Serializable(java.io.Serializable) 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) Test(org.junit.Test)

Example 20 with StreamSegmentStore

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

the class UnreadBytesTest 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();
}
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)

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