use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsAtTime.
@Test
public void testGetSegmentsAtTime() throws Exception {
CompletableFuture<Map<Segment, Long>> positions;
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream1"), 0);
assertEquals(2, positions.get().size());
assertEquals(10, positions.get().get(new Segment("scope1", "stream1", 0)).longValue());
assertEquals(20, positions.get().get(new Segment("scope1", "stream1", 1)).longValue());
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream2"), 0);
AssertExtensions.assertFutureThrows("Should throw Exception", positions, throwable -> true);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerImplTest method testScale.
@Test
public void testScale() throws Exception {
CompletableFuture<Boolean> scaleStream;
StreamImpl stream = new StreamImpl("scope1", "stream1");
scaleStream = controllerClient.scaleStream(stream, new ArrayList<>(), new HashMap<>(), executor).getFuture();
assertTrue(scaleStream.get());
CompletableFuture<StreamSegments> segments = controllerClient.getCurrentSegments("scope1", "stream1");
assertEquals(2, segments.get().getSegments().size());
assertEquals(new Segment("scope1", "stream1", 6), segments.get().getSegmentForKey(0.25));
assertEquals(new Segment("scope1", "stream1", 7), segments.get().getSegmentForKey(0.75));
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("UNKNOWN", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "UNKNOWN"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerImplTest method testUpdateSubscriberStreamCut.
@Test
public void testUpdateSubscriberStreamCut() throws Exception {
CompletableFuture<Boolean> updateSubscriberStatus;
UUID readerGroupId = UUID.randomUUID();
StreamCut streamCut = new StreamCutImpl(new StreamImpl("scope1", "stream1"), Collections.emptyMap());
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream1", "subscriber1", readerGroupId, 0L, streamCut);
assertTrue(updateSubscriberStatus.get());
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream2", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw exception", updateSubscriberStatus, Throwable -> true);
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream3", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw IllegalArgumentException exception", updateSubscriberStatus, throwable -> throwable instanceof IllegalArgumentException);
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream4", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw exception", updateSubscriberStatus, Throwable -> true);
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream5", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw exception", updateSubscriberStatus, throwable -> throwable instanceof IllegalArgumentException);
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream6", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw IllegalArgumentException exception", updateSubscriberStatus, throwable -> throwable instanceof IllegalArgumentException);
updateSubscriberStatus = controllerClient.updateSubscriberStreamCut("scope1", "stream6", "subscriber1", readerGroupId, 0L, streamCut);
AssertExtensions.assertFutureThrows("Server should throw IllegalArgumentException exception", updateSubscriberStatus, throwable -> throwable instanceof IllegalArgumentException);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class BucketService method handleStreamAdded.
private void handleStreamAdded(StreamNotification notification) {
StreamImpl stream;
log.info("{}: New stream {}/{} added to bucket {} ", serviceType, notification.getScope(), notification.getStream(), bucketId);
stream = new StreamImpl(notification.getScope(), notification.getStream());
long nextRun = System.currentTimeMillis() + executionPeriod.toMillis();
synchronized (lock) {
if (!knownStreams.contains(stream)) {
knownStreams.add(stream);
workQueue.add(new QueueElement(stream, nextRun));
}
}
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ZooKeeperBucketService method startBucketChangeListener.
@Override
public void startBucketChangeListener() {
PathChildrenCacheListener bucketListener = (client, event) -> {
StreamImpl stream;
switch(event.getType()) {
case CHILD_ADDED:
case CHILD_UPDATED:
stream = bucketStore.getStreamFromPath(event.getData().getPath());
notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamAdded));
break;
case CHILD_REMOVED:
stream = bucketStore.getStreamFromPath(event.getData().getPath());
notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamRemoved));
break;
case CONNECTION_LOST:
notify(new StreamNotification(null, null, NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {} on bucket", event.getType(), getBucketId());
}
};
PathChildrenCache pathChildrenCache = cacheRef.updateAndGet(existing -> {
if (existing == null) {
PathChildrenCache cache = bucketStore.getBucketPathChildrenCache(getServiceType(), getBucketId());
cache.getListenable().addListener(bucketListener);
log.info("bucket {} change notification listener registered", getBucketId());
return cache;
} else {
return existing;
}
});
try {
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
} catch (Exception e) {
log.error("{}: Starting listener on bucket {} threw exception", getServiceType(), getBucketId(), e);
throw Exceptions.sneakyThrow(e);
}
}
Aggregations