Search in sources :

Example 6 with KeyValueTableConfiguration

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
}
Also used : CreateKeyValueTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) Test(org.junit.Test)

Example 7 with KeyValueTableConfiguration

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());
}
Also used : KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) Test(org.junit.Test)

Example 8 with KeyValueTableConfiguration

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());
}
Also used : DeleteKVTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteKVTableStatus) CreateKeyValueTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) ScopeInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo) Test(org.junit.Test)

Example 9 with KeyValueTableConfiguration

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);
}
Also used : KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Test(org.junit.Test)

Example 10 with KeyValueTableConfiguration

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());
}
Also used : KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

KeyValueTableConfiguration (io.pravega.client.tables.KeyValueTableConfiguration)20 Test (org.junit.Test)16 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)8 CreateKeyValueTableStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus)8 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)7 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)7 DeleteKVTableStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteKVTableStatus)7 Exceptions (io.pravega.common.Exceptions)5 List (java.util.List)5 ClientConfig (io.pravega.client.ClientConfig)4 Controller (io.pravega.client.control.impl.Controller)4 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)4 Futures (io.pravega.common.concurrent.Futures)4 UUID (java.util.UUID)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 KeyValueTableManager (io.pravega.client.admin.KeyValueTableManager)3 StreamManager (io.pravega.client.admin.StreamManager)3 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)3 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)3 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)3