use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ControllerServiceImplTest method createKeyValueTableTests.
@Test(timeout = 30000L)
public void createKeyValueTableTests() {
KeyValueTableConfiguration config1 = KeyValueTableConfiguration.builder().partitionCount(5).primaryKeyLength(4).secondaryKeyLength(4).build();
KeyValueTableConfiguration config2 = KeyValueTableConfiguration.builder().partitionCount(3).primaryKeyLength(4).secondaryKeyLength(4).build();
// Test Create KeyValueTable
ResultObserver<CreateScopeStatus> result = new ResultObserver<>();
this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE4), 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());
result1 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, KVTABLE2, config2), result1);
createStatus = result1.get();
assertEquals("Create KeyValueTable", CreateKeyValueTableStatus.Status.SUCCESS, createStatus.getStatus());
// endregion
// region duplicate create kvtable
result1 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, KVTABLE1, config1), result1);
createStatus = result1.get();
Assert.assertEquals(createStatus.getStatus(), CreateKeyValueTableStatus.Status.TABLE_EXISTS);
// endregion
// create kvtable for non-existent scope
result1 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode("SCOPE3", KVTABLE1, config2), result1);
createStatus = result1.get();
Assert.assertEquals(createStatus.getStatus(), CreateKeyValueTableStatus.Status.SCOPE_NOT_FOUND);
// endregion
// create kvtable with invalid name "abc/def"
result1 = new ResultObserver<>();
this.controllerService.createKeyValueTable(ModelHelper.decode(SCOPE4, "abc/def", config1), result1);
createStatus = result1.get();
assertEquals(createStatus.getStatus(), CreateKeyValueTableStatus.Status.INVALID_TABLE_NAME);
// endregion
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ControllerServiceImplTest method getCurrentSegmentsKeyValueTableTest.
@Test
public void getCurrentSegmentsKeyValueTableTest() {
KeyValueTableConfiguration config = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
createScopeAndKVTable(SCOPE5, KVTABLE3, config);
ResultObserver<SegmentRanges> result2 = new ResultObserver<>();
this.controllerService.getCurrentSegmentsKeyValueTable(ModelHelper.createKeyValueTableInfo(SCOPE5, KVTABLE3), result2);
SegmentRanges segmentRanges = result2.get();
Assert.assertEquals(2, segmentRanges.getSegmentRangesCount());
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class ControllerServiceImplTest method deleteKeyValueTableTests.
@Test
public void deleteKeyValueTableTests() {
// Try deleting a non-existent KeyValueTable with non-existent scope.
ResultObserver<DeleteKVTableStatus> result3 = new ResultObserver<>();
this.controllerService.deleteKeyValueTable(ModelHelper.createKeyValueTableInfo("dummyScope", "dummyKeyValueTable"), result3);
DeleteKVTableStatus deleteKVTStatus = result3.get();
assertEquals("Delete Non-existent KeyValueTable with non-existent Scope", DeleteKVTableStatus.Status.TABLE_NOT_FOUND, deleteKVTStatus.getStatus());
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());
// Try deleting a non-existent KeyValueTable inside an existing scope
ResultObserver<DeleteKVTableStatus> result2 = new ResultObserver<>();
this.controllerService.deleteKeyValueTable(ModelHelper.createKeyValueTableInfo(SCOPE4, "dummyKvt"), result2);
DeleteKVTableStatus deleteKVTStatus1 = result2.get();
assertEquals("Delete Non-existent KeyValueTable", DeleteKVTableStatus.Status.TABLE_NOT_FOUND, deleteKVTStatus1.getStatus());
// Create a test KeyValueTable
KeyValueTableConfiguration config1 = KeyValueTableConfiguration.builder().partitionCount(3).primaryKeyLength(4).secondaryKeyLength(4).build();
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());
// Delete the KeyValueTable.
ResultObserver<DeleteKVTableStatus> result7 = new ResultObserver<>();
this.controllerService.deleteKeyValueTable(ModelHelper.createKeyValueTableInfo(SCOPE4, KVTABLE1), result7);
deleteKVTStatus = result7.get();
assertEquals("Delete KeyValueTable", DeleteKVTableStatus.Status.SUCCESS, deleteKVTStatus.getStatus());
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class LocalControllerTest method testGetKeyValueTableConfiguration.
@Test(timeout = 10000)
public void testGetKeyValueTableConfiguration() {
KeyValueTableConfiguration config = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.SUCCESS).setConfig(ModelHelper.decode("scope", "kvtable1", config)).build()));
KeyValueTableConfiguration responseConfig = this.testController.getKeyValueTableConfiguration("scope", "kvtable1").join();
assertEquals(config.getPartitionCount(), responseConfig.getPartitionCount());
assertEquals(config.getPrimaryKeyLength(), responseConfig.getPrimaryKeyLength());
assertEquals(config.getSecondaryKeyLength(), responseConfig.getSecondaryKeyLength());
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.FAILURE).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable2").join(), ex -> ex instanceof ControllerFailureException);
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.TABLE_NOT_FOUND).build()));
assertThrows("Expected IllegalArgumentException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable3").join(), ex -> ex instanceof IllegalArgumentException);
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatusValue(-1).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable4").join(), ex -> ex instanceof ControllerFailureException);
}
use of io.pravega.client.tables.KeyValueTableConfiguration in project pravega by pravega.
the class KVTableMetadataStoreTest method deleteKeyValueTableTest.
@Test(timeout = 30000)
public void deleteKeyValueTableTest() throws Exception {
final String scopeName = "ScopeDelete";
final String kvtName = "KVTableDelete";
KeyValueTableConfiguration config = KeyValueTableConfiguration.builder().partitionCount(3).primaryKeyLength(4).secondaryKeyLength(4).build();
// create KeyValueTable in scope
Controller.CreateScopeStatus scopeCreateStatus = createScope(scopeName);
assertEquals(scopeCreateStatus.getStatus(), Controller.CreateScopeStatus.Status.SUCCESS);
UUID id = store.newScope(scope).newId();
store.createEntryForKVTable(scopeName, kvtName, id, null, executor).get();
long start = System.currentTimeMillis();
store.createKeyValueTable(scopeName, kvtName, config, start, null, executor).get();
store.setState(scopeName, kvtName, KVTableState.ACTIVE, null, executor).get();
assertTrue(store.checkTableExists(scopeName, kvtName, null, executor).join());
store.deleteKeyValueTable(scopeName, kvtName, null, executor).get();
assertFalse(store.checkTableExists(scopeName, kvtName, null, executor).join());
}
Aggregations