use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class StreamCutServiceTest method testRetentionService.
@Test(timeout = 10000)
public void testRetentionService() {
List<StreamCutBucketService> bucketServices = Lists.newArrayList(service.getBuckets());
assertNotNull(bucketServices);
assertTrue(bucketServices.size() == 3);
assertTrue(streamMetadataStore.takeBucketOwnership(0, hostId, executor).join());
assertTrue(streamMetadataStore.takeBucketOwnership(1, hostId, executor).join());
assertTrue(streamMetadataStore.takeBucketOwnership(2, hostId, executor).join());
AssertExtensions.assertThrows("", () -> streamMetadataStore.takeBucketOwnership(3, hostId, executor).join(), e -> e instanceof IllegalArgumentException);
service.notify(new BucketOwnershipListener.BucketNotification(0, BucketOwnershipListener.BucketNotification.NotificationType.BucketAvailable));
String scope = "scope";
String streamName = "stream";
Stream stream = new StreamImpl(scope, streamName);
AssertExtensions.assertThrows("Null retention policy check", () -> streamMetadataStore.addUpdateStreamForAutoStreamCut(scope, streamName, null, null, executor).join(), e -> e instanceof NullPointerException);
streamMetadataStore.addUpdateStreamForAutoStreamCut(scope, streamName, RetentionPolicy.builder().build(), null, executor).join();
// verify that at least one of the buckets got the notification
int bucketId = stream.getScopedName().hashCode() % 3;
StreamCutBucketService bucketService = bucketServices.stream().filter(x -> x.getBucketId() == bucketId).findAny().get();
AtomicBoolean added = new AtomicBoolean(false);
RetryHelper.loopWithDelay(() -> !added.get(), () -> CompletableFuture.completedFuture(null).thenAccept(x -> added.set(bucketService.getRetentionFutureMap().size() > 0)), Duration.ofSeconds(1).toMillis(), executor).join();
assertTrue(bucketService.getRetentionFutureMap().containsKey(stream));
streamMetadataStore.removeStreamFromAutoStreamCut(scope, streamName, null, executor).join();
AtomicBoolean removed = new AtomicBoolean(false);
RetryHelper.loopWithDelay(() -> !removed.get(), () -> CompletableFuture.completedFuture(null).thenAccept(x -> removed.set(bucketService.getRetentionFutureMap().size() == 0)), Duration.ofSeconds(1).toMillis(), executor).join();
assertTrue(bucketService.getRetentionFutureMap().size() == 0);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ZkStoreRetentionTest method testBucketOwnership.
@Test(timeout = 10000)
public void testBucketOwnership() throws Exception {
// verify that ownership is not taken up by another host
assertFalse(streamMetadataStore.takeBucketOwnership(0, "", executor).join());
// Introduce connection failure error
zkClient.getZookeeperClient().close();
// restart
CuratorFramework zkClient2 = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), 10000, 1000, (r, e, s) -> false);
zkClient2.start();
StreamMetadataStore streamMetadataStore2 = StreamStoreFactory.createZKStore(zkClient2, executor);
String scope = "scope1";
String streamName = "stream1";
streamMetadataStore2.addUpdateStreamForAutoStreamCut(scope, streamName, RetentionPolicy.builder().build(), null, executor).join();
zkClient2.close();
zkClient.getZookeeperClient().start();
Stream stream = new StreamImpl(scope, streamName);
// verify that at least one of the buckets got the notification
List<StreamCutBucketService> bucketServices = Lists.newArrayList(service.getBuckets());
int bucketId = stream.getScopedName().hashCode() % 3;
StreamCutBucketService bucketService = bucketServices.stream().filter(x -> x.getBucketId() == bucketId).findAny().get();
AtomicBoolean added = new AtomicBoolean(false);
RetryHelper.loopWithDelay(() -> !added.get(), () -> CompletableFuture.completedFuture(null).thenAccept(x -> added.set(bucketService.getRetentionFutureMap().size() > 0)), Duration.ofSeconds(1).toMillis(), executor).join();
assertTrue(bucketService.getRetentionFutureMap().containsKey(stream));
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class StreamCutBucketService method performRetention.
private CompletableFuture<Void> performRetention(StreamImpl stream) {
log.debug("Periodic background processing for retention called for stream {}/{}", stream.getScope(), stream.getStreamName());
OperationContext context = streamMetadataStore.createContext(stream.getScope(), stream.getStreamName());
return RetryHelper.withRetriesAsync(() -> streamMetadataStore.getConfiguration(stream.getScope(), stream.getStreamName(), context, executor).thenCompose(config -> streamMetadataTasks.retention(stream.getScope(), stream.getStreamName(), config.getRetentionPolicy(), System.currentTimeMillis(), context, this.streamMetadataTasks.retrieveDelegationToken())).exceptionally(e -> {
log.warn("Exception thrown while performing auto retention for stream {} ", stream, e);
throw new CompletionException(e);
}), RetryHelper.UNCONDITIONAL_PREDICATE, 5, executor).exceptionally(e -> {
log.warn("Unable to perform retention for stream {}. Ignoring, retention will be attempted in next cycle.", stream, e);
return null;
});
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class BatchClientImplTest method testSegmentIterator.
@Test(timeout = 5000)
public void testSegmentIterator() throws ConnectionFailedException {
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CreateSegment request = (CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(GetStreamSegmentInfo.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory);
BatchClientImpl client = new BatchClientImpl(mockController, connectionFactory);
Stream stream = new StreamImpl("scope", "stream");
mockController.createScope("scope");
mockController.createStream(StreamConfiguration.builder().scope("scope").streamName("stream").scalingPolicy(ScalingPolicy.fixed(3)).build()).join();
Iterator<SegmentRange> segments = client.getSegments(stream, null, null).getIterator();
assertTrue(segments.hasNext());
assertEquals(0, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(1, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(2, segments.next().asImpl().getSegment().getSegmentNumber());
assertFalse(segments.hasNext());
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class MockController method createStream.
@Override
@Synchronized
public CompletableFuture<Boolean> createStream(StreamConfiguration streamConfig) {
Stream stream = new StreamImpl(streamConfig.getScope(), streamConfig.getStreamName());
if (createdStreams.get(stream) != null) {
return CompletableFuture.completedFuture(false);
}
if (createdScopes.get(streamConfig.getScope()) == null) {
return Futures.failedFuture(new IllegalArgumentException("Scope does not exit."));
}
createdStreams.put(stream, streamConfig);
createdScopes.get(streamConfig.getScope()).add(stream);
for (Segment segment : getSegmentsForStream(stream)) {
createSegment(segment.getScopedName(), new PravegaNodeUri(endpoint, port));
}
return CompletableFuture.completedFuture(true);
}
Aggregations