Search in sources :

Example 21 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager 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)

Example 22 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.

the class TransactionTest method testDoubleCommit.

@Test
public void testDoubleCommit() throws TxnFailedException {
    String endpoint = "localhost";
    String streamName = "abc";
    int port = TestUtils.getAvailableListenPort();
    String event = "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, null);
    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, event);
    transaction.commit();
    AssertExtensions.assertThrows(TxnFailedException.class, () -> transaction.commit());
}
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) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) Test(org.junit.Test)

Aggregations

MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)22 Cleanup (lombok.Cleanup)21 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)20 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)19 Test (org.junit.Test)17 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)16 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)9 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)7 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Checkpoint (io.pravega.client.stream.Checkpoint)2 ReaderGroup (io.pravega.client.stream.ReaderGroup)2 InlineExecutor (io.pravega.test.common.InlineExecutor)2 Serializable (java.io.Serializable)2 NoSuchEventException (io.pravega.client.segment.impl.NoSuchEventException)1 EventPointer (io.pravega.client.stream.EventPointer)1 ReinitializationRequiredException (io.pravega.client.stream.ReinitializationRequiredException)1 IntegerSerializer (io.pravega.test.integration.utils.IntegerSerializer)1 TreeSet (java.util.TreeSet)1 lombok.val (lombok.val)1