Search in sources :

Example 31 with TableStore

use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.

the class TableBasedMetadataStoreMockTests method testRandomRuntimeExceptionDuringWrite.

@Test
public void testRandomRuntimeExceptionDuringWrite() {
    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 random exception
    Exception e = new ArithmeticException();
    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 StorageMetadataException && ex.getCause() == e);
}
Also used : lombok.val(lombok.val) 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 32 with TableStore

use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.

the class TableBasedMetadataStoreMockTests method testExceptionDuringRemove.

@Test
public void testExceptionDuringRemove() throws Exception {
    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 random exception
    Exception e = new ArithmeticException();
    val td = BaseMetadataStore.TransactionData.builder().key("foo").version(1L).dbObject(2L).build();
    val toRet = new ArrayList<Long>();
    toRet.add(3L);
    CompletableFuture<Void> f = new CompletableFuture<>();
    f.completeExceptionally(e);
    when(mockTableStore.remove(anyString(), any(), any())).thenReturn(f);
    when(mockTableStore.put(anyString(), any(), any())).thenReturn(CompletableFuture.completedFuture(toRet));
    tableBasedMetadataStore.writeAll(Collections.singleton(td)).get();
}
Also used : lombok.val(lombok.val) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) 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 33 with TableStore

use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.

the class TableBasedMetadataStoreMockTests method testRandomExceptionDuringRead.

@Test
public void testRandomExceptionDuringRead() {
    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 random exception
    Exception e = new ArithmeticException();
    val f = new CompletableFuture<List<TableEntry>>();
    f.completeExceptionally(e);
    when(mockTableStore.get(anyString(), any(), any())).thenReturn(f);
    AssertExtensions.assertFutureThrows("read should throw an exception", tableBasedMetadataStore.read("test"), ex -> ex instanceof StorageMetadataException && ex.getCause() == e);
}
Also used : lombok.val(lombok.val) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) 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 34 with TableStore

use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.

the class TableBasedMetadataStoreMockTests method testBadKeyVersionExceptionDuringWrite.

@Test
public void testBadKeyVersionExceptionDuringWrite() {
    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 BadKeyVersionException exception
    Exception e = new CompletionException(new BadKeyVersionException("test", new HashMap<>()));
    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 excpetion", tableBasedMetadataStore.writeAll(Collections.singleton(td)), ex -> ex instanceof StorageMetadataVersionMismatchException && ex.getCause() == e.getCause());
}
Also used : BadKeyVersionException(io.pravega.segmentstore.contracts.tables.BadKeyVersionException) lombok.val(lombok.val) HashMap(java.util.HashMap) 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) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 35 with TableStore

use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.

the class EndToEndStatsTest method setUp.

@Before
public void setUp() throws Exception {
    zkTestServer = new TestingServerStarter().start();
    serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    statsRecorder = new TestStatsRecorder();
    server = new PravegaConnectionListener(false, false, "localhost", servicePort, store, tableStore, statsRecorder, TableSegmentStatsRecorder.noOp(), null, null, null, true, serviceBuilder.getLowPriorityExecutor(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    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)

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