Search in sources :

Example 26 with TableStore

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();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Before(org.junit.Before)

Example 27 with TableStore

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());
}
Also used : Serializable(java.io.Serializable) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 28 with TableStore

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());
}
Also used : Serializable(java.io.Serializable) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 29 with TableStore

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());
}
Also used : lombok.val(lombok.val) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) Cleanup(lombok.Cleanup) BadKeyVersionException(io.pravega.segmentstore.contracts.tables.BadKeyVersionException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) InMemoryTableStore(io.pravega.segmentstore.storage.mocks.InMemoryTableStore) Test(org.junit.Test)

Example 30 with TableStore

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);
}
Also used : CompletionException(java.util.concurrent.CompletionException) IOException(java.io.IOException) Cleanup(lombok.Cleanup) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) InMemoryTableStore(io.pravega.segmentstore.storage.mocks.InMemoryTableStore) Test(org.junit.Test)

Aggregations

TableStore (io.pravega.segmentstore.contracts.tables.TableStore)81 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)69 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)54 Cleanup (lombok.Cleanup)49 Test (org.junit.Test)48 TestingServerStarter (io.pravega.test.common.TestingServerStarter)29 lombok.val (lombok.val)28 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)26 Before (org.junit.Before)26 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)23 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)20 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)18 CompletableFuture (java.util.concurrent.CompletableFuture)18 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)14 TableEntry (io.pravega.segmentstore.contracts.tables.TableEntry)13 InMemoryTableStore (io.pravega.segmentstore.storage.mocks.InMemoryTableStore)12 WireCommands (io.pravega.shared.protocol.netty.WireCommands)12 Random (java.util.Random)12 CompletionException (java.util.concurrent.CompletionException)12 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)11