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