use of io.pravega.client.stream.impl.Controller in project pravega by pravega.
the class EndToEndWithScaleTest method testScale.
@Test(timeout = 30000)
public void testScale() 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().controllerURI(URI.create("tcp://localhost")).build());
@Cleanup ClientFactory clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().build());
writer.writeEvent("0", "txntest1").get();
// 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, executor).getFuture().get();
assertTrue(result);
writer.writeEvent("0", "txntest2").get();
@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.stream.impl.Controller in project pravega by pravega.
the class AutoScaleTest method scaleDownTest.
/**
* Invoke the simple scale down Test, produce no into a stream.
* The test will periodically check if a scale event has occured by talking to controller via
* controller client.
*
* @throws InterruptedException if interrupted
* @throws URISyntaxException If URI is invalid
*/
private CompletableFuture<Void> scaleDownTest() {
final ControllerImpl controller = getController();
final AtomicBoolean exit = new AtomicBoolean(false);
// overall wait for test to complete in 260 seconds (4.2 minutes) or scale down, whichever happens first.
return Retry.withExpBackoff(10, 10, 30, Duration.ofSeconds(10).toMillis()).retryingOn(ScaleOperationNotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments(SCOPE, SCALE_DOWN_STREAM_NAME).thenAccept(x -> {
if (x.getSegments().size() == 2) {
throw new ScaleOperationNotDoneException();
} else {
log.info("scale down done successfully");
exit.set(true);
}
}), EXECUTOR_SERVICE);
}
use of io.pravega.client.stream.impl.Controller in project pravega by pravega.
the class AutoScaleTest 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 {
// create a scope
Controller controller = getController();
Boolean createScopeStatus = controller.createScope(SCOPE).get();
log.debug("create scope status {}", createScopeStatus);
// create a stream
Boolean createStreamStatus = controller.createStream(CONFIG_UP).get();
log.debug("create stream status for scale up stream {}", createStreamStatus);
createStreamStatus = controller.createStream(CONFIG_DOWN).get();
log.debug("create stream status for scaledown stream {}", createStreamStatus);
log.debug("scale down stream starting segments:" + controller.getCurrentSegments(SCOPE, SCALE_DOWN_STREAM_NAME).get().getSegments().size());
Map<Double, Double> keyRanges = new HashMap<>();
keyRanges.put(0.0, 0.5);
keyRanges.put(0.5, 1.0);
Boolean status = controller.scaleStream(new StreamImpl(SCOPE, SCALE_DOWN_STREAM_NAME), Collections.singletonList(0), keyRanges, EXECUTOR_SERVICE).getFuture().get();
assertTrue(status);
createStreamStatus = controller.createStream(CONFIG_TXN).get();
log.debug("create stream status for txn stream {}", createStreamStatus);
}
use of io.pravega.client.stream.impl.Controller in project pravega by pravega.
the class AutoScaleTest method scaleUpTxnTest.
/**
* Invoke the scale up Test with transactional writes. Produce traffic from multiple writers in parallel.
* Each writer writes using transactions.
* Transactions are committed quickly to give
* The test will periodically check if a scale event has occured by talking to controller via
* controller client.
*
* @throws InterruptedException if interrupted
* @throws URISyntaxException If URI is invalid
*/
private CompletableFuture<Void> scaleUpTxnTest() {
ControllerImpl controller = getController();
final AtomicBoolean exit = new AtomicBoolean(false);
ClientFactory clientFactory = getClientFactory();
startNewTxnWriter(clientFactory, exit);
// overall wait for test to complete in 260 seconds (4.2 minutes) or scale up, whichever happens first.
return Retry.withExpBackoff(10, 10, 30, Duration.ofSeconds(10).toMillis()).retryingOn(ScaleOperationNotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments(SCOPE, SCALE_UP_TXN_STREAM_NAME).thenAccept(x -> {
if (x.getSegments().size() == 1) {
throw new ScaleOperationNotDoneException();
} else {
log.info("txn test scale up done successfully");
exit.set(true);
}
}), EXECUTOR_SERVICE);
}
use of io.pravega.client.stream.impl.Controller in project pravega by pravega.
the class ControllerFailoverTest method failoverTest.
@Test(timeout = 180000)
public void failoverTest() throws InterruptedException, ExecutionException {
String scope = "testFailoverScope" + RandomStringUtils.randomAlphabetic(5);
String stream = "testFailoverStream" + RandomStringUtils.randomAlphabetic(5);
int initialSegments = 2;
List<Integer> segmentsToSeal = Collections.singletonList(0);
Map<Double, Double> newRangesToCreate = new HashMap<>();
newRangesToCreate.put(0.0, 0.25);
newRangesToCreate.put(0.25, 0.5);
long lease = 29000;
long maxExecutionTime = 60000;
long scaleGracePeriod = 30000;
// Connect with first controller instance.
final Controller controller1 = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURIDirect).build()).build(), EXECUTOR_SERVICE);
// Create scope, stream, and a transaction with high timeout value.
controller1.createScope(scope).join();
log.info("Scope {} created successfully", scope);
createStream(controller1, scope, stream, ScalingPolicy.fixed(initialSegments));
log.info("Stream {}/{} created successfully", scope, stream);
long txnCreationTimestamp = System.nanoTime();
StreamImpl stream1 = new StreamImpl(scope, stream);
TxnSegments txnSegments = controller1.createTransaction(stream1, lease, scaleGracePeriod).join();
log.info("Transaction {} created successfully, beginTime={}", txnSegments.getTxnId(), txnCreationTimestamp);
// Initiate scale operation. It will block until ongoing transaction is complete.
controller1.startScale(stream1, segmentsToSeal, newRangesToCreate).join();
// Ensure that scale is not yet done.
boolean scaleStatus = controller1.checkScaleStatus(stream1, 0).join();
log.info("Status of scale operation isDone={}", scaleStatus);
Assert.assertTrue(!scaleStatus);
// Now stop the controller instance executing scale operation.
Futures.getAndHandleExceptions(controllerService1.scaleService(1), ExecutionException::new);
log.info("Successfully stopped one instance of controller service");
List<URI> conUris = controllerService1.getServiceDetails();
// Fetch all the RPC endpoints and construct the client URIs.
final List<String> uris = conUris.stream().filter(uri -> Utils.DOCKER_BASED ? uri.getPort() == Utils.DOCKER_CONTROLLER_PORT : uri.getPort() == Utils.MARATHON_CONTROLLER_PORT).map(URI::getAuthority).collect(Collectors.toList());
controllerURIDirect = URI.create("tcp://" + String.join(",", uris));
log.info("Controller Service direct URI: {}", controllerURIDirect);
// Connect to another controller instance.
final Controller controller2 = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURIDirect).build()).build(), EXECUTOR_SERVICE);
// Fetch status of transaction.
log.info("Fetching status of transaction {}, time elapsed since its creation={}", txnSegments.getTxnId(), System.nanoTime() - txnCreationTimestamp);
Transaction.Status status = controller2.checkTransactionStatus(stream1, txnSegments.getTxnId()).join();
log.info("Transaction {} status={}", txnSegments.getTxnId(), status);
if (status == Transaction.Status.OPEN) {
// Abort the ongoing transaction.
log.info("Trying to abort transaction {}, by sending request to controller at {}", txnSegments.getTxnId(), controllerURIDirect);
controller2.abortTransaction(stream1, txnSegments.getTxnId()).join();
}
// Note: if scale does not complete within desired time, test will timeout.
while (!scaleStatus) {
scaleStatus = controller2.checkScaleStatus(stream1, 0).join();
Thread.sleep(30000);
}
// Ensure that the stream has 3 segments now.
log.info("Checking whether scale operation succeeded by fetching current segments");
StreamSegments streamSegments = controller2.getCurrentSegments(scope, stream).join();
log.info("Current segment count=", streamSegments.getSegments().size());
Assert.assertEquals(initialSegments - segmentsToSeal.size() + newRangesToCreate.size(), streamSegments.getSegments().size());
}
Aggregations