use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl 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.SocketConnectionFactoryImpl 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.SocketConnectionFactoryImpl 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.SocketConnectionFactoryImpl 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.SocketConnectionFactoryImpl in project pravega by pravega.
the class EndToEndAutoScaleUpTest method main.
public static void main(String[] args) throws Exception {
try {
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
int port = Config.SERVICE_PORT;
@Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port, false);
Controller controller = controllerWrapper.getController();
ClientFactoryImpl internalCF = new ClientFactoryImpl(NameUtils.INTERNAL_SCOPE_NAME, controller, new SocketConnectionFactoryImpl(ClientConfig.builder().build()));
@Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
@Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
TableStore tableStore = serviceBuilder.createTableStoreService();
@Cleanup AutoScaleMonitor autoScaleMonitor = new AutoScaleMonitor(store, internalCF, AutoScalerConfig.builder().with(AutoScalerConfig.MUTE_IN_SECONDS, 0).with(AutoScalerConfig.COOLDOWN_IN_SECONDS, 0).build());
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, false, "localhost", 12345, store, tableStore, autoScaleMonitor.getStatsRecorder(), autoScaleMonitor.getTableSegmentStatsRecorder(), null, null, null, true, serviceBuilder.getLowPriorityExecutor(), Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()]));
server.startListening();
controllerWrapper.awaitRunning();
controllerWrapper.getControllerService().createScope("test", 0L).get();
controller.createStream("test", "test", CONFIG).get();
@Cleanup MockClientFactory clientFactory = new MockClientFactory("test", controller, internalCF.getConnectionPool());
// Mocking pravega service by putting scale up and scale down requests for the stream
@Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().build());
// keep writing. Scale should happen
long start = System.currentTimeMillis();
char[] chars = new char[1];
Arrays.fill(chars, 'a');
String str = new String(chars);
CompletableFuture.runAsync(() -> {
while (System.currentTimeMillis() - start < Duration.ofMinutes(3).toMillis()) {
try {
test.writeEvent("0", str).get();
} catch (Throwable e) {
System.err.println("test exception writing events " + e.getMessage());
break;
}
}
});
Retry.withExpBackoff(10, 10, 100, 10000).retryingOn(NotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments("test", "test").thenAccept(streamSegments -> {
if (streamSegments.getSegments().size() > 3) {
System.err.println("Success");
log.info("Success");
System.exit(0);
} else {
throw new NotDoneException();
}
}), executor).exceptionally(e -> {
System.err.println("Failure");
log.error("Failure");
System.exit(1);
return null;
}).get();
} catch (Throwable e) {
System.err.print("Test failed with exception: " + e.getMessage());
System.exit(-1);
}
System.exit(0);
}
Aggregations