Search in sources :

Example 1 with PravegaTablesScope

use of io.pravega.controller.store.PravegaTablesScope in project pravega by pravega.

the class PravegaTablesStreamMetadataStoreTest method testDeleteScopeWithEntries.

@Test
public void testDeleteScopeWithEntries() {
    PravegaTablesStreamMetadataStore store = (PravegaTablesStreamMetadataStore) this.store;
    String scopeName = "newScopedelete";
    OperationContext context = store.createScopeContext(scopeName, 0L);
    Controller.CreateScopeStatus status = store.createScope(scopeName, context, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, status.getStatus());
    // verify that streams in scope table does not exist
    PravegaTablesScope scope = (PravegaTablesScope) store.getScope(scopeName, context);
    String stream = "stream";
    scope.addStreamToScope(stream, context).join();
    assertEquals(stream, scope.listStreamsInScope(context).join().get(0));
    UUID rgId = UUID.randomUUID();
    String rg = "rg";
    scope.addReaderGroupToScope(rg, rgId, context).join();
    assertEquals(rgId, scope.getReaderGroupId(rg, context).join());
    String kvt = "kvt";
    scope.addKVTableToScope(kvt, UUID.randomUUID(), context).join();
    assertEquals(kvt, scope.listKeyValueTables(10, "", executor, context).join().getKey().get(0));
    AssertExtensions.assertFutureThrows("delete scope should have failed", scope.deleteScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotEmptyException);
    scope.removeStreamFromScope(stream, context).join();
    AssertExtensions.assertFutureThrows("delete scope should have failed", scope.deleteScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotEmptyException);
    scope.removeKVTableFromScope(kvt, context).join();
    AssertExtensions.assertFutureThrows("delete scope should have failed", scope.deleteScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotEmptyException);
    scope.removeReaderGroupFromScope(rg, context).join();
    // now that we have deleted entries from all tables, the delete scope should succeed
    scope.deleteScope(context).join();
}
Also used : PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Mockito.anyString(org.mockito.Mockito.anyString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with PravegaTablesScope

use of io.pravega.controller.store.PravegaTablesScope in project pravega by pravega.

the class PravegaTablesStreamMetadataStoreTest method testPartiallyCreatedScope.

@Test
public void testPartiallyCreatedScope() {
    PravegaTablesStreamMetadataStore store = (PravegaTablesStreamMetadataStore) this.store;
    PravegaTablesStoreHelper storeHelper = store.getStoreHelper();
    String newScope = "newScope";
    Controller.CreateScopeStatus status = store.createScope(newScope, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, status.getStatus());
    status = store.createScope(newScope, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SCOPE_EXISTS, status.getStatus());
    // now partially create a scope
    String scopeName = "partial";
    byte[] idBytes = new byte[2 * Long.BYTES];
    UUID id = UUID.randomUUID();
    BitConverter.writeUUID(new ByteArraySegment(idBytes), id);
    // add entry for a scope in scopes table
    storeHelper.addNewEntry(PravegaTablesStreamMetadataStore.SCOPES_TABLE, scopeName, idBytes, x -> x, 0L).join();
    // verify that streams in scope table does not exist
    OperationContext context = store.createScopeContext(scopeName, 0L);
    PravegaTablesScope scope = (PravegaTablesScope) store.getScope(scopeName, context);
    ByteBuf token = Unpooled.wrappedBuffer(Base64.getDecoder().decode(""));
    Supplier<CompletableFuture<Map.Entry<ByteBuf, List<String>>>> tableCheckSupplier = () -> scope.getStreamsInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("Table should not exist", tableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    Supplier<CompletableFuture<Map.Entry<ByteBuf, List<String>>>> kvttableCheckSupplier = () -> scope.getKVTablesInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("Table should not exist", kvttableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    Supplier<CompletableFuture<?>> rgTableCheckSupplier = () -> scope.getReaderGroupsInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("RG Table should not exist", rgTableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    assertEquals(Collections.emptyList(), scope.listStreamsInScope(context).join());
    Pair<List<String>, String> listStreams = scope.listStreams(10, "", executor, context).join();
    assertEquals(Collections.emptyList(), listStreams.getKey());
    assertTrue(Strings.isNullOrEmpty(listStreams.getValue()));
    Pair<List<String>, String> listKvts = scope.listKeyValueTables(10, "", executor, context).join();
    assertEquals(Collections.emptyList(), listKvts.getKey());
    assertTrue(Strings.isNullOrEmpty(listKvts.getValue()));
    scope.addStreamToScope("stream", context).join();
    assertEquals("stream", scope.listStreamsInScope(context).join().get(0));
    assertTrue(Futures.await(tableCheckSupplier.get()));
    UUID rgId = UUID.randomUUID();
    String rgName = "rg1";
    scope.addReaderGroupToScope(rgName, rgId, context).join();
    assertEquals(rgId, scope.getReaderGroupId(rgName, context).join());
    assertTrue(Futures.await(rgTableCheckSupplier.get()));
    scope.addKVTableToScope("kvt", UUID.randomUUID(), context).join();
    assertEquals("kvt", scope.listKeyValueTables(10, "", executor, context).join().getKey().get(0));
    assertTrue(Futures.await(kvttableCheckSupplier.get()));
    // create scope idempotent
    status = store.createScope(scopeName, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SCOPE_EXISTS, status.getStatus());
    PravegaTablesStoreHelper spy = spy(storeHelper);
    PravegaTablesScope scopeObj = new PravegaTablesScope("thirdScope", spy);
    StoreException unknown = StoreException.create(StoreException.Type.UNKNOWN, "unknown");
    doReturn(Futures.failedFuture(unknown)).when(spy).addNewEntry(anyString(), anyString(), any(), any(), anyLong());
    AssertExtensions.assertFutureThrows("Create scope should have thrown exception", scopeObj.createScope(context), e -> Exceptions.unwrap(e).equals(unknown));
}
Also used : Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) COMPLETED_TRANSACTIONS_BATCHES_TABLE(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCHES_TABLE) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Unpooled(io.netty.buffer.Unpooled) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) Synchronized(lombok.Synchronized) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Base64(java.util.Base64) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) ByteArraySegment(io.pravega.common.util.ByteArraySegment) RetryPolicy(org.apache.curator.RetryPolicy) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) Futures(io.pravega.common.concurrent.Futures) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) Mockito.mock(org.mockito.Mockito.mock) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) SegmentHelper(io.pravega.controller.server.SegmentHelper) Exceptions(io.pravega.common.Exceptions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) BitConverter(io.pravega.common.util.BitConverter) Supplier(java.util.function.Supplier) Strings(com.google.common.base.Strings) RetryOneTime(org.apache.curator.retry.RetryOneTime) ByteBuf(io.netty.buffer.ByteBuf) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleEntry(java.util.AbstractMap.SimpleEntry) Mockito.anyString(org.mockito.Mockito.anyString) NameUtils(io.pravega.shared.NameUtils) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ByteArraySegment(io.pravega.common.util.ByteArraySegment) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Mockito.anyString(org.mockito.Mockito.anyString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ByteBuf(io.netty.buffer.ByteBuf) CompletableFuture(java.util.concurrent.CompletableFuture) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with PravegaTablesScope

use of io.pravega.controller.store.PravegaTablesScope in project pravega by pravega.

the class StreamTest method testPravegaTablesCreateStream.

@Test(timeout = 10000)
public void testPravegaTablesCreateStream() throws ExecutionException, InterruptedException {
    PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(SegmentHelperMock.getSegmentHelperMockForTables(executorService()), GrpcAuthHelper.getDisabledAuthHelper(), executorService());
    PravegaTablesScope scope = new PravegaTablesScope("test", storeHelper);
    OperationContext context = getContext();
    scope.createScope(context).join();
    scope.addStreamToScope("test", context).join();
    PravegaTablesStream stream = new PravegaTablesStream("test", "test", storeHelper, orderer, () -> 0, scope::getStreamsInScopeTableName, executorService());
    testStream(stream);
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Test(org.junit.Test)

Example 4 with PravegaTablesScope

use of io.pravega.controller.store.PravegaTablesScope in project pravega by pravega.

the class StreamTest method testConcurrentGetSuccessorScalePravegaTables.

@Test(timeout = 10000)
public void testConcurrentGetSuccessorScalePravegaTables() throws Exception {
    @Cleanup SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executorService());
    GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
    try (final StreamMetadataStore store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService(), authHelper)) {
        testConcurrentGetSuccessorScale(store, (x, y) -> {
            PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
            PravegaTablesScope scope = new PravegaTablesScope(x, storeHelper);
            OperationContext context = getContext();
            Futures.exceptionallyExpecting(scope.createScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataExistsException, null).join();
            scope.addStreamToScope(y, context).join();
            return new PravegaTablesStream(x, y, storeHelper, orderer, () -> 0, scope::getStreamsInScopeTableName, executorService());
        });
    }
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) Arrays(java.util.Arrays) SegmentHelper(io.pravega.controller.server.SegmentHelper) BiFunction(java.util.function.BiFunction) Exceptions(io.pravega.common.Exceptions) Cleanup(lombok.Cleanup) Mockito.spy(org.mockito.Mockito.spy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) RetryOneTime(org.apache.curator.retry.RetryOneTime) Lists(com.google.common.collect.Lists) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) StateRecord(io.pravega.controller.store.stream.records.StateRecord) Map(java.util.Map) After(org.junit.After) ClassRule(org.junit.ClassRule) Before(org.junit.Before) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) NameUtils(io.pravega.shared.NameUtils) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Assert.assertTrue(org.junit.Assert.assertTrue) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) Test(org.junit.Test) Collectors(java.util.stream.Collectors) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) ExecutionException(java.util.concurrent.ExecutionException) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) AbstractMap(java.util.AbstractMap) List(java.util.List) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) TestOperationContext(io.pravega.controller.store.TestOperationContext) RetryPolicy(org.apache.curator.RetryPolicy) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) Assert.assertEquals(org.junit.Assert.assertEquals) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 5 with PravegaTablesScope

use of io.pravega.controller.store.PravegaTablesScope in project pravega by pravega.

the class PravegaTablesStreamMetadataStore method createStreamContext.

@Override
public OperationContext createStreamContext(String scopeName, String streamName, long requestId) {
    PravegaTablesScope scope = newScope(scopeName);
    Stream stream = new PravegaTablesStream(scopeName, streamName, storeHelper, orderer, completedTxnGCRef.get()::getLatestBatch, scope::getStreamsInScopeTableName, executor);
    return new StreamOperationContext(scope, stream, requestId);
}
Also used : PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope)

Aggregations

PravegaTablesScope (io.pravega.controller.store.PravegaTablesScope)7 Test (org.junit.Test)5 PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)3 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)3 UUID (java.util.UUID)3 Mockito.anyString (org.mockito.Mockito.anyString)3 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Exceptions (io.pravega.common.Exceptions)2 Futures (io.pravega.common.concurrent.Futures)2 PravegaZkCuratorResource (io.pravega.controller.PravegaZkCuratorResource)2 SegmentHelperMock (io.pravega.controller.mocks.SegmentHelperMock)2 SegmentHelper (io.pravega.controller.server.SegmentHelper)2 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)2 TestOperationContext (io.pravega.controller.store.TestOperationContext)2 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)2 EpochTransitionRecord (io.pravega.controller.store.stream.records.EpochTransitionRecord)2 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)2 NameUtils (io.pravega.shared.NameUtils)2 Arrays (java.util.Arrays)2