Search in sources :

Example 6 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class StateSynchronizerTest method testReadsAllAvailable.

@Test(timeout = 20000)
public void testReadsAllAvailable() {
    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());
    for (int i = 0; i < 10; i++) {
        setA.add("Append: " + i);
    }
    SetSynchronizer<String> setB = SetSynchronizer.createNewSet(stateName, streamManager.getClientFactory());
    assertEquals(10, setB.getCurrentSize());
    for (int i = 10; i < 20; i++) {
        setA.add("Append: " + i);
    }
    setB.update();
    assertEquals(20, setB.getCurrentSize());
}
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)

Example 7 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener 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 8 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener 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 9 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener 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 10 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener 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)

Aggregations

PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)46 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)45 Cleanup (lombok.Cleanup)28 Test (org.junit.Test)23 TestingServerStarter (io.pravega.test.common.TestingServerStarter)22 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)20 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)19 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)18 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)16 Before (org.junit.Before)14 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Controller (io.pravega.client.stream.impl.Controller)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)10 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)7 TestingServer (org.apache.curator.test.TestingServer)7 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 StreamImpl (io.pravega.client.stream.impl.StreamImpl)5 ClientFactory (io.pravega.client.ClientFactory)4 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)4