use of io.pravega.client.stream.mock.MockStreamManager 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.client.stream.mock.MockStreamManager 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.client.stream.mock.MockStreamManager in project pravega by pravega.
the class StartLocalService method main.
public static void main(String[] args) throws Exception {
@Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, StartLocalService.SERVICE_PORT, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(SCOPE, "localhost", StartLocalService.SERVICE_PORT);
streamManager.createScope(SCOPE);
streamManager.createStream(SCOPE, STREAM_NAME, null);
Thread.sleep(60000);
System.exit(0);
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class InProcessMockClientAdapter method startUp.
// endregion
// region ClientAdapterBase Implementation
@Override
protected void startUp() throws Exception {
int segmentStorePort = this.testConfig.getSegmentStorePort(0);
this.listener = new PravegaConnectionListener(false, segmentStorePort, getStreamSegmentStore());
this.listener.startListening();
this.streamManager = new MockStreamManager(SCOPE, LISTENING_ADDRESS, segmentStorePort);
this.streamManager.createScope(SCOPE);
super.startUp();
}
use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.
the class AutoCheckpointTest method testOnlyOneOutstanding.
@Test(timeout = 30000)
public void testOnlyOneOutstanding() throws ReinitializationRequiredException, DurableDataLogException {
String endpoint = "localhost";
String streamName = "abc";
String readerGroup = "group";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world: ";
String scope = "Scope1";
@Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
MockClientFactory clientFactory = streamManager.getClientFactory();
ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(1000).stream(Stream.of(scope, streamName)).build();
streamManager.createScope(scope);
streamManager.createStream(scope, streamName, null);
streamManager.createReaderGroup(readerGroup, groupConfig);
JavaSerializer<String> serializer = new JavaSerializer<>();
populateEvents(streamName, testString, clientFactory, serializer);
AtomicLong fakeClock = new AtomicLong(0);
@Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("reader1", readerGroup, serializer, ReaderConfig.builder().build(), () -> fakeClock.get(), () -> fakeClock.get() / NANOS_PER_SECOND);
@Cleanup EventStreamReader<String> reader2 = clientFactory.createReader("reader2", readerGroup, serializer, ReaderConfig.builder().build(), () -> fakeClock.get(), () -> fakeClock.get() / NANOS_PER_SECOND);
int numRead = 0;
int checkpointCount = 0;
while (numRead < 100) {
fakeClock.addAndGet(NANOS_PER_SECOND);
EventRead<String> event = reader1.readNextEvent(1000);
if (event.isCheckpoint()) {
checkpointCount++;
} else {
String message = event.getEvent();
assertEquals(testString + numRead, message);
numRead++;
}
}
assertEquals("As there is a second reader that does not pass the checkpoint, only one should occur", 1, checkpointCount);
}
Aggregations