Search in sources :

Example 11 with StreamImpl

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);
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 12 with StreamImpl

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);
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 13 with StreamImpl

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);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) SubscriberStreamCut(io.pravega.controller.stream.api.grpc.v1.Controller.SubscriberStreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with StreamImpl

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));
        }
    }
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl)

Example 15 with StreamImpl

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);
    }
}
Also used : BucketStore(io.pravega.controller.store.stream.BucketStore) Slf4j(lombok.extern.slf4j.Slf4j) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ZookeeperBucketStore(io.pravega.controller.store.stream.ZookeeperBucketStore) Duration(java.time.Duration) Exceptions(io.pravega.common.Exceptions) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) IOException(java.io.IOException) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) StreamImpl(io.pravega.client.stream.impl.StreamImpl) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) IOException(java.io.IOException)

Aggregations

StreamImpl (io.pravega.client.stream.impl.StreamImpl)74 Test (org.junit.Test)50 Stream (io.pravega.client.stream.Stream)47 Cleanup (lombok.Cleanup)36 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)32 HashMap (java.util.HashMap)32 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)22 Map (java.util.Map)22 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)21 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)21 Controller (io.pravega.client.control.impl.Controller)21 ClientConfig (io.pravega.client.ClientConfig)20 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)18 Segment (io.pravega.client.segment.impl.Segment)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)16 Slf4j (lombok.extern.slf4j.Slf4j)14 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)13 CompletableFuture (java.util.concurrent.CompletableFuture)12 Before (org.junit.Before)12