use of io.pravega.client.connection.impl.ConnectionPoolImpl 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));
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl 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);
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class ScopeTest method testListStreams.
@Test(timeout = 30000)
public void testListStreams() throws Exception {
final String scope = "test";
final String streamName1 = "test1";
final String streamName2 = "test2";
final String streamName3 = "test3";
final Map<String, Integer> foundCount = new HashMap<>();
foundCount.put(streamName1, 0);
foundCount.put(streamName2, 0);
foundCount.put(streamName3, 0);
foundCount.put(NameUtils.getMarkStreamForStream(streamName1), 0);
foundCount.put(NameUtils.getMarkStreamForStream(streamName2), 0);
foundCount.put(NameUtils.getMarkStreamForStream(streamName3), 0);
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
@Cleanup Controller controller = controllerWrapper.getController();
ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build();
@Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, 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 manager = new StreamManagerImpl(controller, cp);
Iterator<Stream> iterator = manager.listStreams(scope);
assertTrue(iterator.hasNext());
Stream next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertTrue(iterator.hasNext());
next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertTrue(iterator.hasNext());
next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertTrue(iterator.hasNext());
next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertTrue(iterator.hasNext());
next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertTrue(iterator.hasNext());
next = iterator.next();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
assertFalse(iterator.hasNext());
assertTrue(foundCount.entrySet().stream().allMatch(x -> x.getValue() == 1));
AsyncIterator<Stream> asyncIterator = controller.listStreams(scope);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
foundCount.computeIfPresent(next.getStreamName(), (x, y) -> ++y);
next = asyncIterator.getNext().join();
assertNull(next);
assertTrue(foundCount.entrySet().stream().allMatch(x -> x.getValue() == 2));
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class ByteStreamClientFactory method withScope.
/**
* Creates a new instance of ByteStreamClientFactory.
*
* @param scope The scope string.
* @param config Configuration for the client.
* @return Instance of ByteStreamClientFactory implementation.
*/
static ByteStreamClientFactory withScope(String scope, ClientConfig config) {
val connectionFactory = new SocketConnectionFactoryImpl(config);
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
val connectionPool = new ConnectionPoolImpl(config, Preconditions.checkNotNull(connectionFactory));
val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, connectionPool);
val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, connectionPool);
return new ByteStreamClientImpl(scope, controller, connectionPool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class ByteClientTest method createClientFactory.
ByteStreamClientFactory createClientFactory(String scope) {
ClientConfig config = ClientConfig.builder().build();
ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(Utils.buildClientConfig(controllerURI)).build(), connectionFactory.getInternalExecutor());
ConnectionPool pool = new ConnectionPoolImpl(config, connectionFactory);
val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, pool);
val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, pool);
val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, pool);
return new ByteStreamClientImpl(scope, controller, pool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
Aggregations