use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.
the class EndToEndTxnWithScaleTest method testTxnWithScale.
@Test(timeout = 10000)
public void testTxnWithScale() throws Exception {
StreamConfiguration config = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
Controller controller = controllerWrapper.getController();
controllerWrapper.getControllerService().createScope("test").get();
controller.createStream(config).get();
@Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ClientFactory clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutScaleGracePeriod(10000).transactionTimeoutTime(10000).build());
Transaction<String> transaction = test.beginTxn();
transaction.writeEvent("0", "txntest1");
transaction.commit();
// scale
Stream stream = new StreamImpl("test", "test");
Map<Double, Double> map = new HashMap<>();
map.put(0.0, 0.33);
map.put(0.33, 0.66);
map.put(0.66, 1.0);
Boolean result = controller.scaleStream(stream, Collections.singletonList(0), map, executorService).getFuture().get();
assertTrue(result);
transaction = test.beginTxn();
transaction.writeEvent("0", "txntest2");
transaction.commit();
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory, connectionFactory);
groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/test").build());
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().build());
EventRead<String> event = reader.readNextEvent(10000);
assertNotNull(event);
assertEquals("txntest1", event.getEvent());
event = reader.readNextEvent(10000);
assertNotNull(event);
assertEquals("txntest2", event.getEvent());
}
use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.
the class PravegaTest method createStream.
/**
* Invoke the createStream method, ensure we are able to create stream.
*
* @throws InterruptedException if interrupted
* @throws URISyntaxException If URI is invalid
* @throws ExecutionException if error in create stream
*/
@Before
public void createStream() throws InterruptedException, ExecutionException {
Service conService = Utils.createPravegaControllerService(null);
List<URI> ctlURIs = conService.getServiceDetails();
URI controllerUri = ctlURIs.get(0);
log.info("Invoking create stream with Controller URI: {}", controllerUri);
@Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerUri).build()).build(), connectionFactory.getInternalExecutor());
assertTrue(controller.createScope(STREAM_SCOPE).get());
assertTrue(controller.createStream(config).get());
}
use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.
the class SegmentHelper method sendRequestAsync.
private <ResultT> void sendRequestAsync(final WireCommand request, final ReplyProcessor replyProcessor, final CompletableFuture<ResultT> resultFuture, final ConnectionFactory connectionFactory, final PravegaNodeUri uri) {
CompletableFuture<ClientConnection> connectionFuture = connectionFactory.establishConnection(uri, replyProcessor);
connectionFuture.whenComplete((connection, e) -> {
if (connection == null) {
resultFuture.completeExceptionally(new WireCommandFailedException(new ConnectionFailedException(e), request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
} else {
try {
connection.send(request);
} catch (ConnectionFailedException cfe) {
throw new WireCommandFailedException(cfe, request.getType(), WireCommandFailedException.Reason.ConnectionFailed);
} catch (Exception e2) {
throw new RuntimeException(e2);
}
}
}).exceptionally(e -> {
Throwable cause = Exceptions.unwrap(e);
if (cause instanceof WireCommandFailedException) {
resultFuture.completeExceptionally(cause);
} else if (cause instanceof ConnectionFailedException) {
resultFuture.completeExceptionally(new WireCommandFailedException(cause, request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
} else {
resultFuture.completeExceptionally(new RuntimeException(cause));
}
return null;
});
resultFuture.whenComplete((result, e) -> {
connectionFuture.thenAccept(ClientConnection::close);
});
}
use of io.pravega.client.netty.impl.ConnectionFactory in project pravega by pravega.
the class RetentionTest method retentionTest.
@Test
public void retentionTest() throws Exception {
ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURI).build()).build(), connectionFactory.getInternalExecutor());
ClientFactory clientFactory = new ClientFactoryImpl(SCOPE, controller);
log.info("Invoking Writer test with Controller URI: {}", controllerURI);
// create a writer
EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(STREAM, new JavaSerializer<>(), EventWriterConfig.builder().build());
// write an event
String writeEvent = "event";
writer.writeEvent(writeEvent);
writer.flush();
log.debug("Writing event: {} ", writeEvent);
// sleep for 4 mins
Exceptions.handleInterrupted(() -> Thread.sleep(5 * 60 * 1000));
// create a reader
ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, controllerURI);
groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, STREAM)).build());
EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
// expectation is it should have been truncated and we should find stream to be empty
try {
String readEvent = reader.readNextEvent(6000).getEvent();
log.debug("Reading event: {} ", readEvent);
assertEquals(null, readEvent);
} catch (ReinitializationRequiredException e) {
log.error("Unexpected request to reinitialize {}", e);
Assert.fail("Unexpected request to reinitialize.Test failed.");
}
log.debug("The stream is already truncated.Simple retention test passed.");
}
Aggregations