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"));
}
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());
}
Aggregations