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());
}
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);
}
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);
}
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);
}
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));
}
Aggregations