use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ScopeTest method testDeleteScopeRecursive.
@Test
public void testDeleteScopeRecursive() throws Exception {
final String scope = "testDeleteScope";
final String testFalseScope = "falseScope";
final String streamName1 = "test1";
final String streamName2 = "test2";
final String streamName3 = "test3";
final String streamName4 = "test4";
final String kvtName1 = "kvt1";
final String kvtName2 = "kvt2";
final String kvtName3 = "kvt3";
final String groupName1 = "rg1";
final String groupName2 = "rg2";
final String groupName3 = "rg3";
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
@Cleanup Controller controller = controllerWrapper.getController();
ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + controllerPort)).build();
@Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, new SocketConnectionFactoryImpl(clientConfig));
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(clientConfig);
// Create scope
controllerWrapper.getControllerService().createScope(scope, 0L).get();
assertTrue(controller.checkScopeExists(scope).get());
// Create streams
assertTrue(controller.createStream(scope, streamName1, config).get());
assertTrue(controller.createStream(scope, streamName2, config).get());
assertTrue(controller.createStream(scope, streamName3, config).get());
@Cleanup StreamManager streamManager = new StreamManagerImpl(controller, cp);
@Cleanup KeyValueTableManager keyValueTableManager = new KeyValueTableManagerImpl(clientConfig);
@Cleanup ReaderGroupManager readerGroupManager = new ReaderGroupManagerImpl(scope, clientConfig, connectionFactory);
// 1. Call deleteScopeRecursive() without creating a scope
assertTrue(streamManager.deleteScopeRecursive(testFalseScope));
// Create KVT under the scope
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
assertTrue(keyValueTableManager.createKeyValueTable(scope, kvtName1, kvtConfig));
assertTrue(keyValueTableManager.createKeyValueTable(scope, kvtName2, kvtConfig));
// Create RG under the same scope
assertTrue(readerGroupManager.createReaderGroup(groupName1, ReaderGroupConfig.builder().stream(getScopedStreamName(scope, streamName1)).build()));
assertTrue(readerGroupManager.createReaderGroup(groupName2, ReaderGroupConfig.builder().stream(getScopedStreamName(scope, streamName2)).build()));
// Call deleteScopeRecursive to delete the scope recursively
assertTrue(streamManager.deleteScopeRecursive(scope));
// Validate that the scope is deleted
assertFalse(controller.checkScopeExists(scope).get());
// Validate create operation of Stream/RG/KVT should throw error
AssertExtensions.assertThrows("Failed to create Reader Group as Scope does not exits", () -> readerGroupManager.createReaderGroup(groupName3, ReaderGroupConfig.builder().stream(getScopedStreamName(scope, streamName2)).build()), e -> e instanceof IllegalArgumentException);
AssertExtensions.assertThrows("Scope does not exist", () -> controller.createStream(scope, streamName4, config).get(), e -> e instanceof IllegalArgumentException);
AssertExtensions.assertThrows("Scope does not exist", () -> keyValueTableManager.createKeyValueTable(scope, kvtName3, kvtConfig), e -> e instanceof IllegalArgumentException);
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class TableMetadataTasksTest method testWorkflowCompletionTimeout.
@Test(timeout = 30000)
public void testWorkflowCompletionTimeout() throws Exception {
// Create a new KVTable
String tableName = "kvtable2";
long creationTime = System.currentTimeMillis();
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
CompletableFuture<Controller.CreateKeyValueTableStatus.Status> createOperationFuture = kvtMetadataTasks.createKeyValueTable(SCOPE, tableName, kvtConfig, creationTime, 0L);
assertTrue(Futures.await(processEvent((TableMetadataTasksTest.WriterMock) requestEventWriter)));
assertEquals(CreateKeyValueTableStatus.Status.SUCCESS, createOperationFuture.join());
// Create KVTable times out
EventHelper helper = new EventHelper(executor, "host", ((AbstractKVTableMetadataStore) kvtStore).getHostTaskIndex());
helper.setCompletionTimeoutMillis(50L);
EventStreamWriter<ControllerEvent> eventWriter = new WriterMock();
helper.setRequestEventWriter(eventWriter);
TableMetadataTasks kvtTasks = spy(new TableMetadataTasks(kvtStore, segmentHelperMock, executor, executor, "host", GrpcAuthHelper.getDisabledAuthHelper(), helper));
AssertExtensions.assertFutureThrows("create timedout", kvtTasks.createKeyValueTable(SCOPE, kvtable1, kvtConfig, creationTime, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
// Delete KVTable times out
AssertExtensions.assertFutureThrows("delete timedout", kvtTasks.deleteKeyValueTable(SCOPE, tableName, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class TableMetadataTasksTest method testDeleteKeyValueTable.
@Test(timeout = 30000)
public void testDeleteKeyValueTable() throws ExecutionException, InterruptedException {
Assert.assertTrue(isScopeCreated);
long creationTime = System.currentTimeMillis();
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
CompletableFuture<Controller.CreateKeyValueTableStatus.Status> createOperationFuture = kvtMetadataTasks.createKeyValueTable(SCOPE, kvtable1, kvtConfig, creationTime, 0L);
assertTrue(Futures.await(processEvent((TableMetadataTasksTest.WriterMock) requestEventWriter)));
assertEquals(CreateKeyValueTableStatus.Status.SUCCESS, createOperationFuture.join());
// delete KVTable
CompletableFuture<DeleteKVTableStatus.Status> future = kvtMetadataTasks.deleteKeyValueTable(SCOPE, kvtable1, 0L);
assertTrue(Futures.await(processEvent((TableMetadataTasksTest.WriterMock) requestEventWriter)));
assertEquals(Controller.DeleteKVTableStatus.Status.SUCCESS, future.get());
assertTrue(kvtMetadataTasks.isDeleted(SCOPE, kvtable1, null).join());
assertFalse(kvtStore.checkTableExists(SCOPE, kvtable1, null, executor).join());
assertFalse(kvtStore.isScopeSealed("testScope", null, executor).join());
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ControllerServiceImplTest method kvtablesInScopeTest.
@Test
public void kvtablesInScopeTest() {
KeyValueTableConfiguration config1 = KeyValueTableConfiguration.builder().partitionCount(3).primaryKeyLength(4).secondaryKeyLength(4).build();
// Test Create KeyValueTable
ResultObserver<CreateScopeStatus> result = new ResultObserver<>();
ScopeInfo scopeInfo = ScopeInfo.newBuilder().setScope(SCOPE4).build();
this.controllerService.createScope(scopeInfo, result);
CreateScopeStatus createScopeStatus = result.get();
assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
ResultObserver<CreateKeyValueTableStatus> result1 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, KVTABLE1, config1), result1);
CreateKeyValueTableStatus createStatus = result1.get();
assertEquals("Create KeyValueTable", CreateKeyValueTableStatus.Status.SUCCESS, createStatus.getStatus());
ResultObserver<CreateKeyValueTableStatus> result2 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, KVTABLE2, config1), result2);
createStatus = result2.get();
assertEquals("Create KeyValueTable", CreateKeyValueTableStatus.Status.SUCCESS, createStatus.getStatus());
ResultObserver<CreateKeyValueTableStatus> result3 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, KVTABLE3, config1), result3);
createStatus = result3.get();
assertEquals("Create KeyValueTable", CreateKeyValueTableStatus.Status.SUCCESS, createStatus.getStatus());
ResultObserver<Controller.KVTablesInScopeResponse> kvtablesInScopeResponse1 = new ResultObserver<>();
Controller.KVTablesInScopeRequest kvTablesInScopeRequest1 = Controller.KVTablesInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
this.controllerService.listKeyValueTablesInScope(kvTablesInScopeRequest1, kvtablesInScopeResponse1);
List<Controller.KeyValueTableInfo> list = kvtablesInScopeResponse1.get().getKvtablesList();
// check continuation token
assertEquals(kvtablesInScopeResponse1.get().getStatus(), Controller.KVTablesInScopeResponse.Status.SUCCESS);
assertFalse(Strings.isNullOrEmpty(kvtablesInScopeResponse1.get().getContinuationToken().getToken()));
assertEquals(2, list.size());
ResultObserver<Controller.KVTablesInScopeResponse> kvtablesInScopeResponse2 = new ResultObserver<>();
Controller.KVTablesInScopeRequest kvTablesInScopeRequest2 = Controller.KVTablesInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(kvtablesInScopeResponse1.get().getContinuationToken()).build();
this.controllerService.listKeyValueTablesInScope(kvTablesInScopeRequest2, kvtablesInScopeResponse2);
list = kvtablesInScopeResponse2.get().getKvtablesList();
// check continuation token
assertEquals(kvtablesInScopeResponse2.get().getStatus(), Controller.KVTablesInScopeResponse.Status.SUCCESS);
assertFalse(Strings.isNullOrEmpty(kvtablesInScopeResponse2.get().getContinuationToken().getToken()));
assertEquals(1, list.size());
ResultObserver<Controller.KVTablesInScopeResponse> kvtablesInScopeResponse3 = new ResultObserver<>();
Controller.KVTablesInScopeRequest kvTablesInScopeRequest3 = Controller.KVTablesInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(kvtablesInScopeResponse2.get().getContinuationToken()).build();
this.controllerService.listKeyValueTablesInScope(kvTablesInScopeRequest3, kvtablesInScopeResponse3);
list = kvtablesInScopeResponse3.get().getKvtablesList();
// check continuation token
assertEquals(kvtablesInScopeResponse3.get().getStatus(), Controller.KVTablesInScopeResponse.Status.SUCCESS);
assertFalse(Strings.isNullOrEmpty(kvtablesInScopeResponse3.get().getContinuationToken().getToken()));
assertEquals(0, list.size());
List<Controller.KeyValueTableInfo> m = new LinkedList<>();
m.addAll(kvtablesInScopeResponse1.get().getKvtablesList());
m.addAll(kvtablesInScopeResponse2.get().getKvtablesList());
m.addAll(kvtablesInScopeResponse3.get().getKvtablesList());
// verify that all three streams have been found
assertTrue(m.stream().anyMatch(x -> x.getKvtName().equals(KVTABLE1)));
assertTrue(m.stream().anyMatch(x -> x.getKvtName().equals(KVTABLE2)));
assertTrue(m.stream().anyMatch(x -> x.getKvtName().equals(KVTABLE3)));
Controller.KVTablesInScopeRequest nonExistentScopeRequest = Controller.KVTablesInScopeRequest.newBuilder().setScope(ScopeInfo.newBuilder().setScope("NonExistent").build()).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
ResultObserver<Controller.KVTablesInScopeResponse> nonExistentScopeResponse = new ResultObserver<>();
this.controllerService.listKeyValueTablesInScope(nonExistentScopeRequest, nonExistentScopeResponse);
assertEquals(Controller.KVTablesInScopeResponse.Status.SCOPE_NOT_FOUND, nonExistentScopeResponse.get().getStatus());
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ControllerServiceTest method testControllerService.
@Test(timeout = 80000)
public void testControllerService() throws Exception {
final String scope1 = "scope1";
final String scope2 = "scope2";
controllerWrapper.getControllerService().createScope("scope1", 0L).get();
controllerWrapper.getControllerService().createScope("scope2", 0L).get();
Controller controller = controllerWrapper.getController();
final String streamName1 = "stream1";
final String streamName2 = "stream2";
final String streamName3 = "stream3";
final ScalingPolicy scalingPolicy = ScalingPolicy.fixed(2);
final StreamConfiguration config1 = StreamConfiguration.builder().scalingPolicy(scalingPolicy).build();
final StreamConfiguration config2 = StreamConfiguration.builder().scalingPolicy(scalingPolicy).build();
final StreamConfiguration config3 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build();
createAStream(scope1, streamName1, controller, config1);
// Same name in different scope
createAStream(scope2, streamName1, controller, config2);
// Different name in same scope
createAStream(scope1, streamName2, controller, config3);
createAStream(scope1, streamName3, controller, config3);
final String kvtName1 = "kvtable1";
final String kvtName2 = "kvtable2";
final KeyValueTableConfiguration kvtConfig1 = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
createAKeyValueTable(scope1, kvtName1, controller, kvtConfig1);
// Same name in different scope
createAKeyValueTable(scope2, kvtName1, controller, kvtConfig1);
// Different name in different scope
createAKeyValueTable(scope2, kvtName2, controller, kvtConfig1);
final String scopeSeal = "scopeSeal";
final String streamNameSeal = "streamSeal";
sealAStream(controllerWrapper, controller, scalingPolicy, scopeSeal, streamNameSeal);
sealASealedStream(controller, scopeSeal, streamNameSeal);
sealNonExistantStream(controller, scopeSeal);
streamDuplicationNotAllowed(scope1, streamName1, controller, config1);
// update stream config section
updateStreamName(controller, scope1, scalingPolicy);
updateScalingPolicy(controller, scope1, streamName1);
updateTargetRate(controller, scope1, streamName1);
updateScaleFactor(controller, scope1, streamName1);
updataMinSegmentes(controller, scope1, streamName1);
updateConfigOfNonExistantStream(controller);
// get currently active segments
getActiveSegments(controller, scope1, streamName1);
getActiveSegmentsForNonExistentStream(controller);
// get positions at a given time stamp
getSegmentsAtTime(controller, scope1, streamName1);
getSegmentsAtTime(controller, scope1, streamName2);
getSegmentsForNonExistentStream(controller);
getSegmentsBeforeCreation(controller, scope1, streamName1);
getSegmentsAfterCreation(controller, scope1, streamName1);
readerGroupsTest(controller, scope1, streamName1, streamName2, streamName3);
updateSubscriberStreamCutTest(controller, scope2, streamName1);
}
Aggregations