use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class StreamMetricsTest method testRollingTxnMetrics.
@Test(timeout = 30000)
public void testRollingTxnMetrics() throws Exception {
String scaleRollingTxnScopeName = "scaleRollingTxnScope";
String scaleRollingTxnStreamName = "scaleRollingTxnStream";
controllerWrapper.getControllerService().createScope(scaleRollingTxnScopeName, 0L).get();
if (!controller.createStream(scaleRollingTxnScopeName, scaleRollingTxnStreamName, config).get()) {
fail("Stream " + scaleRollingTxnScopeName + "/" + scaleRollingTxnStreamName + " for scale testing already existed, test failed");
}
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(scaleRollingTxnScopeName, ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + controllerPort)).build());
@Cleanup TransactionalEventStreamWriter<String> writer = clientFactory.createTransactionalEventWriter(Stream.of(scaleRollingTxnScopeName, scaleRollingTxnStreamName).getStreamName(), new JavaSerializer<>(), EventWriterConfig.builder().build());
Transaction<String> transaction = writer.beginTxn();
transaction.writeEvent("Transactional content");
// split to 3 segments
Map<Double, Double> keyRanges = new HashMap<>();
keyRanges.put(0.0, 0.25);
keyRanges.put(0.25, 0.75);
keyRanges.put(0.75, 1.0);
Stream scaleRollingTxnStream = new StreamImpl(scaleRollingTxnScopeName, scaleRollingTxnStreamName);
if (!controller.scaleStream(scaleRollingTxnStream, Collections.singletonList(0L), keyRanges, executor).getFuture().get()) {
fail("Scale stream: splitting segment into three failed, exiting");
}
assertEquals(3, (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_COUNT, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value());
assertEquals(1, (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_SPLITS, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value());
assertEquals(0, (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_MERGES, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value());
transaction.flush();
transaction.commit();
String message = "Inconsistency found between metadata and metrics";
AssertExtensions.assertEventuallyEquals(message, 3L, () -> (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_COUNT, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value(), 500, 30000);
AssertExtensions.assertEventuallyEquals(message, 2L, () -> (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_SPLITS, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value(), 200, 30000);
AssertExtensions.assertEventuallyEquals(message, 1L, () -> (long) MetricRegistryUtils.getGauge(MetricsNames.SEGMENTS_MERGES, streamTags(scaleRollingTxnScopeName, scaleRollingTxnStreamName)).value(), 200, 30000);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerWatermarkingTest method watermarkTest.
@Test(timeout = 60000)
public void watermarkTest() throws Exception {
Controller controller = controllerWrapper.getController();
String scope = "scope";
String stream = "stream";
controller.createScope(scope).join();
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
controller.createStream(scope, stream, config).join();
String markStream = NameUtils.getMarkStreamForStream(stream);
Stream streamObj = new StreamImpl(scope, stream);
WriterPosition pos1 = WriterPosition.builder().segments(Collections.singletonMap(new Segment(scope, stream, 0L), 10L)).build();
WriterPosition pos2 = WriterPosition.builder().segments(Collections.singletonMap(new Segment(scope, stream, 0L), 20L)).build();
controller.noteTimestampFromWriter("1", streamObj, 1L, pos1).join();
controller.noteTimestampFromWriter("2", streamObj, 2L, pos2).join();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
@Cleanup RevisionedStreamClient<Watermark> reader = clientFactory.createRevisionedStreamClient(markStream, new WatermarkSerializer(), SynchronizerConfig.builder().build());
AssertExtensions.assertEventuallyEquals(true, () -> {
Iterator<Entry<Revision, Watermark>> watermarks = reader.readFrom(reader.fetchOldestRevision());
return watermarks.hasNext();
}, 30000);
Iterator<Entry<Revision, Watermark>> watermarks = reader.readFrom(reader.fetchOldestRevision());
Watermark watermark = watermarks.next().getValue();
assertEquals(watermark.getLowerTimeBound(), 1L);
assertTrue(watermark.getStreamCut().entrySet().stream().anyMatch(x -> x.getKey().getSegmentId() == 0L && x.getValue() == 20L));
controller.sealStream(scope, stream).join();
controller.deleteStream(scope, stream).join();
AssertExtensions.assertFutureThrows("Mark Stream should not exist", controller.getCurrentSegments(scope, markStream), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerServiceTest method getSegmentsForNonExistentStream.
private static void getSegmentsForNonExistentStream(Controller controller) throws InterruptedException {
Stream stream = new StreamImpl("scope", "streamName");
try {
CompletableFuture<Map<Segment, Long>> segments = controller.getSegmentsAtTime(stream, System.currentTimeMillis());
assertTrue("FAILURE: Fetching positions for non existent stream", segments.get().isEmpty());
log.info("SUCCESS: Positions cannot be fetched for non existent stream");
} catch (ExecutionException | CompletionException e) {
assertTrue("FAILURE: Fetching positions for non existent stream", Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
log.info("SUCCESS: Positions cannot be fetched for non existent stream");
}
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerBootstrapTest method bootstrapTest.
@Test(timeout = 20000)
public void bootstrapTest() throws Exception {
Controller controller = controllerWrapper.getController();
// Now start Pravega service.
serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
store = serviceBuilder.createStreamSegmentService();
tableStore = serviceBuilder.createTableStoreService();
server = new PravegaConnectionListener(false, servicePort, store, tableStore, serviceBuilder.getLowPriorityExecutor());
server.startListening();
// Create test scope. This operation should succeed.
Boolean scopeStatus = controller.createScope(SCOPE).join();
Assert.assertEquals(true, scopeStatus);
// Try creating a stream. It should not complete until Pravega host has started.
// After Pravega host starts, stream should be successfully created.
StreamConfiguration streamConfiguration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
CompletableFuture<Boolean> streamStatus = controller.createStream(SCOPE, STREAM, streamConfiguration);
Assert.assertTrue(!streamStatus.isDone());
// Ensure that create stream succeeds.
Boolean status = streamStatus.join();
Assert.assertEquals(true, status);
// Now create transaction should succeed.
CompletableFuture<TxnSegments> txIdFuture = controller.createTransaction(new StreamImpl(SCOPE, STREAM), 10000);
TxnSegments id = txIdFuture.join();
Assert.assertNotNull(id);
controllerWrapper.awaitRunning();
}
Aggregations