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();
}
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));
}
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);
}
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());
});
}
}
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);
}
Aggregations