Search in sources :

Example 1 with ConnectionPoolImpl

use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.

the class ClientFactoryTest method testEventWriter.

@Test
public void testEventWriter() {
    String scope = "scope";
    String stream = "stream1";
    // setup mocks
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controllerClient, new ConnectionPoolImpl(ClientConfig.builder().build(), connectionFactory), inFactory, outFactory, condFactory, metaFactory);
    NavigableMap<Double, SegmentWithRange> segments = new TreeMap<>();
    Segment segment = new Segment(scope, stream, 0L);
    segments.put(1.0, new SegmentWithRange(segment, 0.0, 1.0));
    StreamSegments currentSegments = new StreamSegments(segments);
    SegmentOutputStream outStream = mock(SegmentOutputStream.class);
    when(controllerClient.getCurrentSegments(scope, stream)).thenReturn(CompletableFuture.completedFuture(currentSegments));
    when(outFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(outStream);
    EventWriterConfig writerConfig = EventWriterConfig.builder().build();
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(stream, new JavaSerializer<String>(), writerConfig);
    assertEquals(writerConfig, writer.getConfig());
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) TreeMap(java.util.TreeMap) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Test(org.junit.Test)

Example 2 with ConnectionPoolImpl

use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.

the class TestUtils method createScopeStream.

/**
 * Creates the given scope and stream using the given controller instance.
 *
 * @param controller    Controller instance to use to create the Scope and Stream.
 * @param scopeName     Name of the Scope.
 * @param streamName    Name of the Stream.
 * @param streamConfig  Configuration for the Stream to be created.
 */
public static void createScopeStream(Controller controller, String scopeName, String streamName, StreamConfiguration streamConfig) {
    ClientConfig clientConfig = ClientConfig.builder().build();
    @Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, new SocketConnectionFactoryImpl(clientConfig));
    // Don't close the controller.
    @SuppressWarnings("resource") StreamManager streamManager = new StreamManagerImpl(controller, cp);
    // create scope
    Boolean createScopeStatus = streamManager.createScope(scopeName);
    log.info("Create scope status {}", createScopeStatus);
    // create stream
    Boolean createStreamStatus = streamManager.createStream(scopeName, streamName, streamConfig);
    log.info("Create stream status {}", createStreamStatus);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) StreamManager(io.pravega.client.admin.StreamManager) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup)

Example 3 with ConnectionPoolImpl

use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.

the class TestUtils method deleteScopeStream.

/**
 * Deletes the given scope and stream using the given controller instance.
 *
 * @param controller    Controller instance to use to create the Scope and Stream.
 * @param scopeName     Name of the Scope.
 * @param streamName    Name of the Stream.
 */
public static void deleteScopeStream(Controller controller, String scopeName, String streamName) {
    ClientConfig clientConfig = ClientConfig.builder().build();
    @Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, new SocketConnectionFactoryImpl(clientConfig));
    // Don't close the controller.
    @SuppressWarnings("resource") StreamManager streamManager = new StreamManagerImpl(controller, cp);
    // delete stream
    Boolean sealStreamStatus = streamManager.sealStream(scopeName, streamName);
    log.info("Seal stream status {}", sealStreamStatus);
    Boolean deleteStreamStatus = streamManager.deleteStream(scopeName, streamName);
    log.info("Delete stream status {}", deleteStreamStatus);
    // create scope
    Boolean deleteScopeStatus = streamManager.deleteScope(scopeName);
    log.info("Delete scope status {}", deleteScopeStatus);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) StreamManager(io.pravega.client.admin.StreamManager) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup)

Example 4 with ConnectionPoolImpl

use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.

the class KeyValueTableFactory method withScope.

/**
 * Creates a new instance of {@link KeyValueTableFactory}.
 *
 * @param scope  The Key-Value Table scope.
 * @param config Configuration for the client.
 * @return Instance of {@link KeyValueTableFactory} implementation.
 */
static KeyValueTableFactory withScope(String scope, ClientConfig config) {
    ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
    ConnectionPool connectionPool = new ConnectionPoolImpl(config, connectionFactory);
    Controller controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
    return new KeyValueTableFactoryImpl(scope, controller, connectionPool);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) KeyValueTableFactoryImpl(io.pravega.client.tables.impl.KeyValueTableFactoryImpl) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Controller(io.pravega.client.control.impl.Controller)

Example 5 with ConnectionPoolImpl

use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.

the class StreamManagerImplTest method testForceDeleteScope.

@Test(timeout = 10000)
public void testForceDeleteScope() 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.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));
    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);
    String scope = "scope";
    String stream1 = "stream1";
    String stream2 = "stream2";
    String stream3 = "stream3";
    streamManager.createScope(scope);
    streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    streamManager.createStream(scope, stream3, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
    assertEquals(3, streams.size());
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream3)));
    // mock controller client to throw exceptions when attempting to seal and delete for stream 1.
    doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to seal stream"))).when(mockController).sealStream(scope, stream1);
    doAnswer(x -> Futures.failedFuture(new IllegalArgumentException("Stream not sealed"))).when(mockController).deleteStream(scope, stream1);
    AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
    // reset mock controller
    reset(mockController);
    // throw invalid stream for stream 2. Delete should happen despite invalid stream exception.
    doAnswer(x -> Futures.failedFuture(new InvalidStreamException("Stream does not exist"))).when(mockController).sealStream(scope, stream2);
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : 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) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ClientConnection(io.pravega.client.connection.impl.ClientConnection) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) 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)

Aggregations

ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)45 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)34 Test (org.junit.Test)34 Cleanup (lombok.Cleanup)33 ClientConfig (io.pravega.client.ClientConfig)31 StreamManager (io.pravega.client.admin.StreamManager)20 Controller (io.pravega.client.control.impl.Controller)20 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)19 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)17 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)14 MockController (io.pravega.client.stream.mock.MockController)14 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)12 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)12 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)11 Stream (io.pravega.client.stream.Stream)11 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)10 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)9 StreamImpl (io.pravega.client.stream.impl.StreamImpl)9 Segment (io.pravega.client.segment.impl.Segment)8 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)8