use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class ControllerCommandsTest method testDescribeStreamCommand.
@Test
@SneakyThrows
public void testDescribeStreamCommand() {
String scope = "testScope";
String testStream = "testStream";
String commandResult = executeCommand("controller describe-stream " + scope + " " + testStream, cliConfig());
Assert.assertTrue(commandResult.contains("stream_config"));
Assert.assertTrue(commandResult.contains("stream_state"));
Assert.assertTrue(commandResult.contains("segment_count"));
Assert.assertTrue(commandResult.contains("is_sealed"));
Assert.assertTrue(commandResult.contains("active_epoch"));
Assert.assertTrue(commandResult.contains("truncation_record"));
Assert.assertTrue(commandResult.contains("scaling_info"));
// Exercise actual instantiateSegmentHelper
CommandArgs commandArgs = new CommandArgs(Arrays.asList(scope, testStream), cliConfig());
ControllerDescribeStreamCommand command = new ControllerDescribeStreamCommand(commandArgs);
@Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CLUSTER.zookeeperConnectString(), new RetryOneTime(5000));
curatorFramework.start();
@Cleanup ConnectionPool pool = new ConnectionPoolImpl(CLIENT_CONFIG, new SocketConnectionFactoryImpl(CLIENT_CONFIG));
@Cleanup SegmentHelper sh = command.instantiateSegmentHelper(curatorFramework, pool);
Assert.assertNotNull(sh);
// Try the Zookeeper backend, which is expected to fail and be handled by the command.
Properties properties = new Properties();
properties.setProperty("cli.store.metadata.backend", CLIConfig.MetadataBackends.ZOOKEEPER.name());
cliConfig().getConfigBuilder().include(properties);
commandArgs = new CommandArgs(Arrays.asList(scope, testStream), cliConfig());
new ControllerDescribeStreamCommand(commandArgs).execute();
properties.setProperty("cli.store.metadata.backend", CLIConfig.MetadataBackends.SEGMENTSTORE.name());
cliConfig().getConfigBuilder().include(properties);
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class AppendReconnectTest method reconnectOnSegmentClient.
@Test(timeout = 30000)
public void reconnectOnSegmentClient() throws Exception {
String endpoint = "localhost";
int port = TestUtils.getAvailableListenPort();
byte[] payload = "Hello world\n".getBytes();
String scope = "scope";
String stream = "stream";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
CompletableFuture<Void> ack = new CompletableFuture<>();
out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack));
for (AutoCloseable c : connectionPool.getActiveChannels()) {
c.close();
}
CompletableFuture<Void> ack2 = new CompletableFuture<>();
out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack2));
ack.get(5, TimeUnit.SECONDS);
ack2.get(5, TimeUnit.SECONDS);
@Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals(payload.length * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class AppendReconnectTest method reconnectThroughConditionalClient.
@Test(timeout = 30000)
public void reconnectThroughConditionalClient() throws Exception {
String endpoint = "localhost";
int port = TestUtils.getAvailableListenPort();
byte[] payload = "Hello world\n".getBytes();
String scope = "scope";
String stream = "stream";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
ConditionalOutputStreamFactoryImpl segmentClient = new ConditionalOutputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup ConditionalOutputStream out = segmentClient.createConditionalOutputStream(segment, DelegationTokenProviderFactory.createWithEmptyToken(), EventWriterConfig.builder().build());
assertTrue(out.write(ByteBuffer.wrap(payload), 0));
for (AutoCloseable c : connectionPool.getActiveChannels()) {
c.close();
}
assertTrue(out.write(ByteBuffer.wrap(payload), payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE));
@Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals((payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE) * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class ByteStreamTest method createClientFactory.
ByteStreamClientFactory createClientFactory(String scope) {
ClientConfig config = ClientConfig.builder().build();
ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
ConnectionPool pool = new ConnectionPoolImpl(config, connectionFactory);
val inputStreamFactory = new SegmentInputStreamFactoryImpl(PRAVEGA.getLocalController(), pool);
val outputStreamFactory = new SegmentOutputStreamFactoryImpl(PRAVEGA.getLocalController(), pool);
val metaStreamFactory = new SegmentMetadataClientFactoryImpl(PRAVEGA.getLocalController(), pool);
return new ByteStreamClientImpl(scope, PRAVEGA.getLocalController(), pool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
use of io.pravega.client.connection.impl.ConnectionPoolImpl in project pravega by pravega.
the class EndToEndTransactionTest method main.
@Test
public static void main(String[] args) throws Exception {
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
int port = Config.SERVICE_PORT;
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, serviceBuilder.createTableStoreService(), serviceBuilder.getLowPriorityExecutor(), Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()]));
server.startListening();
Thread.sleep(1000);
@Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port);
Controller controller = controllerWrapper.getController();
controllerWrapper.awaitRunning();
final String testScope = "testScope";
final String testStream = "testStream";
if (!controller.createScope(testScope).get()) {
log.error("FAILURE: Error creating test scope");
return;
}
ScalingPolicy policy = ScalingPolicy.fixed(5);
StreamConfiguration streamConfig = StreamConfiguration.builder().scalingPolicy(policy).build();
if (!controller.createStream(testScope, testStream, streamConfig).get()) {
log.error("FAILURE: Error creating test stream");
return;
}
final long txnTimeout = 4000;
ClientConfig config = ClientConfig.builder().build();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
@Cleanup MockClientFactory clientFactory = new MockClientFactory(testScope, controller, new ConnectionPoolImpl(config, connectionFactory));
@Cleanup TransactionalEventStreamWriter<String> producer = clientFactory.createTransactionalEventWriter("writer", testStream, new UTF8StringSerializer(), EventWriterConfig.builder().transactionTimeoutTime(txnTimeout).build());
// region Successful commit tests
Transaction<String> transaction = producer.beginTxn();
for (int i = 0; i < 1; i++) {
String event = "\n Transactional Publish \n";
log.info("Producing event: " + event);
transaction.writeEvent("", event);
transaction.flush();
Thread.sleep(500);
}
CompletableFuture<Object> commit = CompletableFuture.supplyAsync(() -> {
try {
transaction.commit();
} catch (Exception e) {
log.warn("Error committing transaction", e);
}
return null;
});
commit.join();
Transaction.Status txnStatus = transaction.checkStatus();
assertTrue(txnStatus == Transaction.Status.COMMITTING || txnStatus == Transaction.Status.COMMITTED);
log.info("SUCCESS: successful in committing transaction. Transaction status=" + txnStatus);
Thread.sleep(2000);
txnStatus = transaction.checkStatus();
assertTrue(txnStatus == Transaction.Status.COMMITTED);
log.info("SUCCESS: successfully committed transaction. Transaction status=" + txnStatus);
// endregion
// region Successful abort tests
Transaction<String> transaction2 = producer.beginTxn();
for (int i = 0; i < 1; i++) {
String event = "\n Transactional Publish \n";
log.info("Producing event: " + event);
transaction2.writeEvent("", event);
transaction2.flush();
Thread.sleep(500);
}
CompletableFuture<Object> drop = CompletableFuture.supplyAsync(() -> {
try {
transaction2.abort();
} catch (Exception e) {
log.warn("Error aborting transaction", e);
}
return null;
});
drop.join();
Transaction.Status txn2Status = transaction2.checkStatus();
assertTrue(txn2Status == Transaction.Status.ABORTING || txn2Status == Transaction.Status.ABORTED);
log.info("SUCCESS: successful in dropping transaction. Transaction status=" + txn2Status);
Thread.sleep(2000);
txn2Status = transaction2.checkStatus();
assertTrue(txn2Status == Transaction.Status.ABORTED);
log.info("SUCCESS: successfully aborted transaction. Transaction status=" + txn2Status);
// endregion
// region Successful timeout tests
Transaction<String> tx1 = producer.beginTxn();
Thread.sleep((long) (1.3 * txnTimeout));
Transaction.Status txStatus = tx1.checkStatus();
Assert.assertTrue(Transaction.Status.ABORTING == txStatus || Transaction.Status.ABORTED == txStatus);
log.info("SUCCESS: successfully aborted transaction after timeout. Transaction status=" + txStatus);
// endregion
// region Ping failure due to controller going into disconnection state
// Fill in these tests once we have controller.stop() implemented.
System.exit(0);
}
Aggregations