Search in sources :

Example 1 with KeyValueTableManager

use of io.pravega.client.admin.KeyValueTableManager in project pravega by pravega.

the class StreamManagerImplTest method testForceDeleteScopeWithKeyValueTables.

@Test(timeout = 10000)
public void testForceDeleteScopeWithKeyValueTables() throws ConnectionFailedException, DeleteScopeFailedException {
    // Setup Mocks
    ClientConnection connection = mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.CreateTableSegment request = (WireCommands.CreateTableSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.CreateTableSegment request = invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.DeleteSegment request = (WireCommands.DeleteSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.DeleteSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.DeleteTableSegment request = invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.DeleteTableSegment.class));
    connectionFactory.provideConnection(location, connection);
    MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
    ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
    @Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
    @Cleanup final KeyValueTableManager keyValueTableManager = new KeyValueTableManagerImpl(mockController, connectionFactory);
    String scope = "scope";
    String kvt1 = "kvt1";
    String kvt2 = "kvt2";
    streamManager.createScope(scope);
    KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(1).primaryKeyLength(1).secondaryKeyLength(1).build();
    keyValueTableManager.createKeyValueTable(scope, kvt1, kvtConfig);
    keyValueTableManager.createKeyValueTable(scope, kvt2, kvtConfig);
    Set<KeyValueTableInfo> keyValueTables = Sets.newHashSet(keyValueTableManager.listKeyValueTables(scope));
    assertEquals(2, keyValueTables.size());
    assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt1)));
    assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt2)));
    // mock controller client to throw exceptions when attempting to delete key value table 1.
    doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to delete key value table"))).when(mockController).deleteKeyValueTable(scope, kvt1);
    AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
    // reset mock controller
    reset(mockController);
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) StreamSegments(io.pravega.client.stream.impl.StreamSegments) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Set(java.util.Set) StreamInfo(io.pravega.client.admin.StreamInfo) Sets(com.google.common.collect.Sets) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) Mockito.mock(org.mockito.Mockito.mock) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) Assert.assertTrue(org.junit.Assert.assertTrue) AsyncIterator(io.pravega.common.util.AsyncIterator) Test(org.junit.Test) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Mockito(org.mockito.Mockito) TreeMap(java.util.TreeMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Cleanup(lombok.Cleanup) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ClientConnection(io.pravega.client.connection.impl.ClientConnection) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StreamManager(io.pravega.client.admin.StreamManager) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 2 with KeyValueTableManager

use of io.pravega.client.admin.KeyValueTableManager in project pravega by pravega.

the class ScopeTest method testForceDeleteScope.

@Test
public void testForceDeleteScope() throws Exception {
    final String scope = "test";
    final String streamName1 = "test1";
    final String streamName2 = "test2";
    final String streamName3 = "test3";
    final String kvtName1 = "kvt1";
    final String kvtName2 = "kvt2";
    final String groupName1 = "rg1";
    final String groupName2 = "rg2";
    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);
    controllerWrapper.getControllerService().createScope(scope, 0L).get();
    controller.createStream(scope, streamName1, config).get();
    controller.createStream(scope, streamName2, config).get();
    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);
    KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
    keyValueTableManager.createKeyValueTable(scope, kvtName1, kvtConfig);
    keyValueTableManager.createKeyValueTable(scope, kvtName2, kvtConfig);
    readerGroupManager.createReaderGroup(groupName1, ReaderGroupConfig.builder().stream(getScopedStreamName(scope, streamName1)).build());
    readerGroupManager.createReaderGroup(groupName2, ReaderGroupConfig.builder().stream(getScopedStreamName(scope, streamName2)).build());
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) KeyValueTableManagerImpl(io.pravega.client.admin.impl.KeyValueTableManagerImpl) StreamManager(io.pravega.client.admin.StreamManager) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Example 3 with KeyValueTableManager

use of io.pravega.client.admin.KeyValueTableManager 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);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) KeyValueTableManagerImpl(io.pravega.client.admin.impl.KeyValueTableManagerImpl) StreamManager(io.pravega.client.admin.StreamManager) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Aggregations

ClientConfig (io.pravega.client.ClientConfig)3 KeyValueTableManager (io.pravega.client.admin.KeyValueTableManager)3 StreamManager (io.pravega.client.admin.StreamManager)3 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)3 Controller (io.pravega.client.control.impl.Controller)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 KeyValueTableConfiguration (io.pravega.client.tables.KeyValueTableConfiguration)3 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 KeyValueTableManagerImpl (io.pravega.client.admin.impl.KeyValueTableManagerImpl)2 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)2 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)2 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)2 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)2 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)2 Cleanup (lombok.Cleanup)2 Test (org.junit.Test)2 Lists (com.google.common.collect.Lists)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets (com.google.common.collect.Sets)1 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)1