use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class StreamCutsTest method setUp.
@Before
public void setUp() throws Exception {
executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
zkTestServer = new TestingServerStarter().start();
serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
TableStore tableStore = serviceBuilder.createTableStoreService();
server = new PravegaConnectionListener(false, servicePort, store, tableStore, serviceBuilder.getLowPriorityExecutor());
server.startListening();
controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
controllerWrapper.awaitRunning();
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class TransactionTest method testTransactionalWritesOrderedCorrectly.
@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testTransactionalWritesOrderedCorrectly() throws TxnFailedException, ReinitializationRequiredException {
int readTimeout = 5000;
String readerName = "reader";
String groupName = "testTransactionalWritesOrderedCorrectly-group";
String endpoint = "localhost";
String streamName = "testTransactionalWritesOrderedCorrectly";
int port = TestUtils.getAvailableListenPort();
String txnEvent = "TXN Event\n";
String nonTxEvent = "Non-TX Event\n";
String routingKey = "RoutingKey";
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
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)).disableAutomaticCheckpoints().build());
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
EventWriterConfig eventWriterConfig = EventWriterConfig.builder().transactionTimeoutTime(60000).build();
@Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), eventWriterConfig);
@Cleanup TransactionalEventStreamWriter<String> txnProducer = clientFactory.createTransactionalEventWriter(streamName, new JavaSerializer<>(), eventWriterConfig);
producer.writeEvent(routingKey, nonTxEvent);
Transaction<String> transaction = txnProducer.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));
@Cleanup 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.tables.TableStore in project pravega by pravega.
the class TransactionTest method testDrop.
@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testDrop() throws TxnFailedException, ReinitializationRequiredException {
String endpoint = "localhost";
String groupName = "testDrop-group";
String streamName = "testDrop";
int port = TestUtils.getAvailableListenPort();
String txnEvent = "TXN Event\n";
String nonTxEvent = "Non-TX Event\n";
String routingKey = "RoutingKey";
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
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)).disableAutomaticCheckpoints().build());
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
EventWriterConfig eventWriterConfig = EventWriterConfig.builder().transactionTimeoutTime(60000).build();
@Cleanup TransactionalEventStreamWriter<String> txnProducer = clientFactory.createTransactionalEventWriter(streamName, new JavaSerializer<>(), eventWriterConfig);
Transaction<String> transaction = txnProducer.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());
@Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), eventWriterConfig);
producer.writeEvent(routingKey, nonTxEvent);
producer.flush();
assertEquals(nonTxEvent, consumer.readNextEvent(1500).getEvent());
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class TableBasedMetadataStoreMockTests method testDataLogWriterNotPrimaryExceptionDuringWrite.
@Test
public void testDataLogWriterNotPrimaryExceptionDuringWrite() {
TableStore mockTableStore = mock(TableStore.class);
@Cleanup TableBasedMetadataStore tableBasedMetadataStore = new TableBasedMetadataStore("test", mockTableStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
when(mockTableStore.createSegment(any(), any(), any())).thenReturn(Futures.failedFuture(new CompletionException(new StreamSegmentExistsException("test"))));
// Throw DataLogWriterNotPrimaryException exception
Exception e = new CompletionException(new DataLogWriterNotPrimaryException("test"));
val td = BaseMetadataStore.TransactionData.builder().key("foo").version(1L).dbObject(2L).build();
CompletableFuture<List<Long>> f = new CompletableFuture<>();
f.completeExceptionally(e);
when(mockTableStore.put(anyString(), any(), any())).thenReturn(f);
AssertExtensions.assertFutureThrows("write should throw an exception", tableBasedMetadataStore.writeAll(Collections.singleton(td)), ex -> ex instanceof StorageMetadataWritesFencedOutException && ex.getCause() == e.getCause());
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class TableBasedMetadataStoreMockTests method testExceptionDuringIterator.
@Test
public void testExceptionDuringIterator() {
TableStore mockTableStore = mock(TableStore.class);
@Cleanup TableBasedMetadataStore tableBasedMetadataStore = new TableBasedMetadataStore("test", mockTableStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
when(mockTableStore.entryIterator(anyString(), any())).thenReturn(Futures.failedFuture(new CompletionException(new IOException("test"))));
AssertExtensions.assertFutureThrows("getAllEntries", tableBasedMetadataStore.getAllEntries(), ex -> ex instanceof StorageMetadataException && ex.getCause() instanceof IOException);
AssertExtensions.assertFutureThrows("getAllKeys", tableBasedMetadataStore.getAllKeys(), ex -> ex instanceof StorageMetadataException && ex.getCause() instanceof IOException);
}
Aggregations