use of io.pravega.controller.store.ZKScope in project pravega by pravega.
the class ZKStreamMetadataStore method createStream.
@Override
public CompletableFuture<CreateStreamResponse> createStream(String scope, String name, StreamConfiguration configuration, long createTimestamp, OperationContext ctx, Executor executor) {
OperationContext context = getOperationContext(ctx);
ZKScope zkScope = (ZKScope) getScope(scope, context);
ZKStream zkStream = (ZKStream) getStream(scope, name, context);
return super.createStream(scope, name, configuration, createTimestamp, context, executor).thenCompose(status -> zkScope.getNextStreamPosition().thenCompose(zkStream::createStreamPositionNodeIfAbsent).thenCompose(v -> zkStream.getStreamPosition()).thenCompose(id -> zkScope.addStreamToScope(name, id)).thenApply(x -> status));
}
use of io.pravega.controller.store.ZKScope in project pravega by pravega.
the class ZKStreamMetadataStore method deleteStream.
@Override
public CompletableFuture<Void> deleteStream(String scope, String name, OperationContext context, Executor executor) {
ZKScope zkScope = (ZKScope) getScope(scope, context);
ZKStream zkStream = (ZKStream) getStream(scope, name, context);
return Futures.exceptionallyExpecting(zkStream.getStreamPosition().thenCompose(id -> zkScope.removeStreamFromScope(name, id)), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, null).thenCompose(v -> super.deleteStream(scope, name, context, executor));
}
use of io.pravega.controller.store.ZKScope in project pravega by pravega.
the class ZKStreamMetadataStoreTest method listStreamsInScopes.
@Test
public void listStreamsInScopes() throws Exception {
// list stream in scope
String scope = "scopeList";
ZKStreamMetadataStore zkStore = spy((ZKStreamMetadataStore) store);
store.createScope(scope, null, executor).get();
LinkedBlockingQueue<Integer> nextPositionList = new LinkedBlockingQueue<>();
nextPositionList.put(0);
nextPositionList.put(2);
nextPositionList.put(10000);
nextPositionList.put((int) Math.pow(10, 8));
nextPositionList.put((int) Math.pow(10, 9));
ZKScope myScope = spy((ZKScope) zkStore.getScope(scope, null));
doAnswer(x -> CompletableFuture.completedFuture(nextPositionList.poll())).when(myScope).getNextStreamPosition();
doAnswer(x -> myScope).when(zkStore).getScope(scope, null);
String stream1 = "stream1";
String stream2 = "stream2";
String stream3 = "stream3";
String stream4 = "stream4";
String stream5 = "stream5";
// add three streams and then list them. We should get 2 + 1 + 0
zkStore.createStream(scope, stream1, configuration1, System.currentTimeMillis(), null, executor).get();
zkStore.setState(scope, stream1, State.ACTIVE, null, executor).get();
zkStore.createStream(scope, stream2, configuration2, System.currentTimeMillis(), null, executor).get();
zkStore.setState(scope, stream2, State.ACTIVE, null, executor).get();
zkStore.createStream(scope, stream3, configuration2, System.currentTimeMillis(), null, executor).get();
zkStore.setState(scope, stream3, State.ACTIVE, null, executor).get();
Pair<List<String>, String> streamInScope = store.listStream(scope, "", 2, executor, null).get();
assertEquals("List streams in scope", 2, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream1));
assertTrue(streamInScope.getKey().contains(stream2));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
assertEquals("List streams in scope", 1, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream3));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
assertEquals("List streams in scope", 0, streamInScope.getKey().size());
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
// add 4th stream
zkStore.createStream(scope, stream4, configuration2, System.currentTimeMillis(), null, executor).get();
zkStore.setState(scope, stream4, State.ACTIVE, null, executor).get();
// list on previous token we should get 1 entry
streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
assertEquals("List streams in scope", 1, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream4));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
// add 5th stream
zkStore.createStream(scope, stream5, configuration2, System.currentTimeMillis(), null, executor).get();
zkStore.setState(scope, stream5, State.ACTIVE, null, executor).get();
// delete stream 1
store.deleteStream(scope, stream1, null, executor).join();
// start listing with empty/default continuation token
streamInScope = store.listStream(scope, "", 2, executor, null).get();
assertEquals("List streams in scope", 2, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream2));
assertTrue(streamInScope.getKey().contains(stream3));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
assertEquals("List streams in scope", 2, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream4));
assertTrue(streamInScope.getKey().contains(stream5));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
// delete stream 3
store.deleteStream(scope, stream3, null, executor).join();
// start listing with empty/default continuation token
streamInScope = store.listStream(scope, "", 2, executor, null).get();
assertEquals("List streams in scope", 2, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream2));
assertTrue(streamInScope.getKey().contains(stream4));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
assertEquals("List streams in scope", 1, streamInScope.getKey().size());
assertTrue(streamInScope.getKey().contains(stream5));
assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
}
Aggregations