use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.
the class StreamTest method testStream.
private void testStream(PersistentStreamBase<Integer> stream) throws InterruptedException, ExecutionException {
long creationTime1 = System.currentTimeMillis();
long creationTime2 = creationTime1 + 1;
final ScalingPolicy policy1 = ScalingPolicy.fixed(5);
final ScalingPolicy policy2 = ScalingPolicy.fixed(6);
final StreamConfiguration streamConfig1 = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(policy1).build();
final StreamConfiguration streamConfig2 = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(policy2).build();
CreateStreamResponse response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
stream.storeCreationTimeIfAbsent(creationTime1).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
stream.createConfigurationIfAbsent(StreamProperty.complete(streamConfig1)).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_CREATING, response.getStatus());
stream.createStateIfAbsent(State.UNKNOWN).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_CREATING, response.getStatus());
stream.updateState(State.CREATING).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.NEW, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_CREATING, response.getStatus());
stream.updateState(State.ACTIVE).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
stream.updateState(State.SEALING).get();
response = stream.checkStreamExists(streamConfig1, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime1).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
response = stream.checkStreamExists(streamConfig2, creationTime2).get();
assertEquals(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, response.getStatus());
}
use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.
the class StreamTest method testConcurrentGetSuccessorScale.
@Test(timeout = 10000)
public void testConcurrentGetSuccessorScale() throws Exception {
final ScalingPolicy policy = ScalingPolicy.fixed(1);
final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor);
final String streamName = "test";
String scopeName = "test";
store.createScope(scopeName).get();
ZKStoreHelper zkStoreHelper = new ZKStoreHelper(cli, executor);
StreamConfiguration streamConfig = StreamConfiguration.builder().scope(streamName).streamName(streamName).scalingPolicy(policy).build();
store.createStream(scopeName, streamName, streamConfig, System.currentTimeMillis(), null, executor).get();
store.setState(scopeName, streamName, State.ACTIVE, null, executor).get();
ZKStream zkStream = spy(new ZKStream("test", "test", zkStoreHelper));
List<AbstractMap.SimpleEntry<Double, Double>> newRanges;
newRanges = Arrays.asList(new AbstractMap.SimpleEntry<>(0.0, 0.5), new AbstractMap.SimpleEntry<>(0.5, 1.0));
long scale = System.currentTimeMillis();
ArrayList<Integer> sealedSegments = Lists.newArrayList(0);
StartScaleResponse response = zkStream.startScale(sealedSegments, newRanges, scale, false).join();
List<Segment> newSegments = response.getSegmentsCreated();
zkStream.updateState(State.SCALING).join();
List<Integer> newSegmentInt = newSegments.stream().map(Segment::getNumber).collect(Collectors.toList());
zkStream.scaleNewSegmentsCreated(sealedSegments, newSegmentInt, response.getActiveEpoch(), scale).get();
// history table has a partial record at this point.
// now we could have sealed the segments so get successors could be called.
final CompletableFuture<Data<Integer>> segmentTable = zkStream.getSegmentTable();
final CompletableFuture<Data<Integer>> historyTable = zkStream.getHistoryTable();
AtomicBoolean historyCalled = new AtomicBoolean(false);
AtomicBoolean segmentCalled = new AtomicBoolean(false);
// mock.. If segment table is fetched before history table, throw runtime exception so that the test fails
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> {
if (!historyCalled.get() && segmentCalled.get()) {
throw new RuntimeException();
}
historyCalled.set(true);
return historyTable;
}).when(zkStream).getHistoryTable();
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> {
if (!historyCalled.get()) {
throw new RuntimeException();
}
segmentCalled.set(true);
return segmentTable;
}).when(zkStream).getSegmentTable();
Map<Integer, List<Integer>> successors = zkStream.getSuccessorsWithPredecessors(0).get();
assertTrue(successors.containsKey(1) && successors.containsKey(2));
// reset mock so that we can resume scale operation
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> historyTable).when(zkStream).getHistoryTable();
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> segmentTable).when(zkStream).getSegmentTable();
zkStream.scaleOldSegmentsSealed(sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), newSegmentInt, response.getActiveEpoch(), scale).get();
// scale is completed, history table also has completed record now.
final CompletableFuture<Data<Integer>> segmentTable2 = zkStream.getSegmentTable();
final CompletableFuture<Data<Integer>> historyTable2 = zkStream.getHistoryTable();
// mock such that if segment table is fetched before history table, throw runtime exception so that the test fails
segmentCalled.set(false);
historyCalled.set(false);
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> {
if (!historyCalled.get() && segmentCalled.get()) {
throw new RuntimeException();
}
historyCalled.set(true);
return historyTable2;
}).when(zkStream).getHistoryTable();
doAnswer((Answer<CompletableFuture<Data<Integer>>>) invocation -> {
if (!historyCalled.get()) {
throw new RuntimeException();
}
segmentCalled.set(true);
return segmentTable2;
}).when(zkStream).getSegmentTable();
successors = zkStream.getSuccessorsWithPredecessors(0).get();
assertTrue(successors.containsKey(1) && successors.containsKey(2));
}
use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.
the class ZKStreamMetadataStoreTest method testScaleMetadata.
@Test
public void testScaleMetadata() throws Exception {
String scope = "testScopeScale";
String stream = "testStreamScale";
ScalingPolicy policy = ScalingPolicy.fixed(3);
StreamConfiguration configuration = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
SimpleEntry<Double, Double> segment1 = new SimpleEntry<>(0.0, 0.5);
SimpleEntry<Double, Double> segment2 = new SimpleEntry<>(0.5, 1.0);
List<SimpleEntry<Double, Double>> newRanges = Arrays.asList(segment1, segment2);
store.createScope(scope).get();
store.createStream(scope, stream, configuration, System.currentTimeMillis(), null, executor).get();
store.setState(scope, stream, State.ACTIVE, null, executor).get();
List<ScaleMetadata> scaleIncidents = store.getScaleMetadata(scope, stream, null, executor).get();
assertTrue(scaleIncidents.size() == 1);
assertTrue(scaleIncidents.get(0).getSegments().size() == 3);
// scale
scale(scope, stream, scaleIncidents.get(0).getSegments(), newRanges);
scaleIncidents = store.getScaleMetadata(scope, stream, null, executor).get();
assertTrue(scaleIncidents.size() == 2);
assertTrue(scaleIncidents.get(0).getSegments().size() == 2);
assertTrue(scaleIncidents.get(1).getSegments().size() == 3);
// scale again
scale(scope, stream, scaleIncidents.get(0).getSegments(), newRanges);
scaleIncidents = store.getScaleMetadata(scope, stream, null, executor).get();
assertTrue(scaleIncidents.size() == 3);
assertTrue(scaleIncidents.get(0).getSegments().size() == 2);
assertTrue(scaleIncidents.get(1).getSegments().size() == 2);
// scale again
scale(scope, stream, scaleIncidents.get(0).getSegments(), newRanges);
scaleIncidents = store.getScaleMetadata(scope, stream, null, executor).get();
assertTrue(scaleIncidents.size() == 4);
assertTrue(scaleIncidents.get(0).getSegments().size() == 2);
assertTrue(scaleIncidents.get(1).getSegments().size() == 2);
}
use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.
the class ZkStreamTest method testTransaction.
@Test(timeout = 10000)
public void testTransaction() throws Exception {
final ScalingPolicy policy = ScalingPolicy.fixed(5);
final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor);
final String streamName = "testTx";
store.createScope(SCOPE).get();
final Predicate<Throwable> operationNotAllowedPredicate = ex -> Exceptions.unwrap(ex) instanceof StoreException.IllegalStateException;
StreamConfiguration streamConfig = StreamConfiguration.builder().scope(SCOPE).streamName(streamName).scalingPolicy(policy).build();
store.createStream(SCOPE, streamName, streamConfig, System.currentTimeMillis(), null, executor).get();
store.setState(SCOPE, streamName, State.ACTIVE, null, executor).get();
OperationContext context = store.createContext(ZkStreamTest.SCOPE, streamName);
UUID txnId1 = UUID.randomUUID();
VersionedTransactionData tx = store.createTransaction(SCOPE, streamName, txnId1, 10000, 600000, 30000, context, executor).get();
Assert.assertEquals(txnId1, tx.getId());
UUID txnId2 = UUID.randomUUID();
VersionedTransactionData tx2 = store.createTransaction(SCOPE, streamName, txnId2, 10000, 600000, 30000, context, executor).get();
Assert.assertEquals(txnId2, tx2.getId());
store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.<Integer>empty(), context, executor).get();
assert store.transactionStatus(SCOPE, streamName, tx.getId(), context, executor).get().equals(TxnStatus.COMMITTING);
// Test to ensure that sealTransaction is idempotent.
Assert.assertEquals(TxnStatus.COMMITTING, store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.empty(), context, executor).join().getKey());
// Test to ensure that COMMITTING transaction cannot be aborted.
testAbortFailure(store, SCOPE, streamName, tx.getEpoch(), tx.getId(), context, operationNotAllowedPredicate);
CompletableFuture<TxnStatus> f1 = store.commitTransaction(SCOPE, streamName, tx.getEpoch(), tx.getId(), context, executor);
store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.<Integer>empty(), context, executor).get();
assert store.transactionStatus(SCOPE, streamName, tx2.getId(), context, executor).get().equals(TxnStatus.ABORTING);
// Test to ensure that sealTransaction is idempotent.
Assert.assertEquals(TxnStatus.ABORTING, store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.empty(), context, executor).join().getKey());
// Test to ensure that ABORTING transaction cannot be committed.
testCommitFailure(store, SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, operationNotAllowedPredicate);
CompletableFuture<TxnStatus> f2 = store.abortTransaction(SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, executor);
CompletableFuture.allOf(f1, f2).get();
assert store.transactionStatus(SCOPE, streamName, tx.getId(), context, executor).get().equals(TxnStatus.COMMITTED);
assert store.transactionStatus(SCOPE, streamName, tx2.getId(), context, executor).get().equals(TxnStatus.ABORTED);
// Test to ensure that sealTransaction, to commit it, on committed transaction does not throw an error.
Assert.assertEquals(TxnStatus.COMMITTED, store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.empty(), context, executor).join().getKey());
// Test to ensure that commitTransaction is idempotent.
Assert.assertEquals(TxnStatus.COMMITTED, store.commitTransaction(SCOPE, streamName, tx.getEpoch(), tx.getId(), context, executor).join());
// Test to ensure that sealTransaction, to abort it, and abortTransaction on committed transaction throws error.
testAbortFailure(store, SCOPE, streamName, tx.getEpoch(), tx.getId(), context, operationNotAllowedPredicate);
// Test to ensure that sealTransaction, to abort it, on aborted transaction does not throw an error.
Assert.assertEquals(TxnStatus.ABORTED, store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.empty(), context, executor).join().getKey());
// Test to ensure that abortTransaction is idempotent.
Assert.assertEquals(TxnStatus.ABORTED, store.abortTransaction(SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, executor).join());
// Test to ensure that sealTransaction, to abort it, and abortTransaction on committed transaction throws error.
testCommitFailure(store, SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, operationNotAllowedPredicate);
assert store.commitTransaction(ZkStreamTest.SCOPE, streamName, 0, UUID.randomUUID(), null, executor).handle((ok, ex) -> {
if (ex.getCause() instanceof StoreException.DataNotFoundException) {
return true;
} else {
throw new RuntimeException("assert failed");
}
}).get();
assert store.abortTransaction(ZkStreamTest.SCOPE, streamName, 0, UUID.randomUUID(), null, executor).handle((ok, ex) -> {
if (ex.getCause() instanceof StoreException.DataNotFoundException) {
return true;
} else {
throw new RuntimeException("assert failed");
}
}).get();
assert store.transactionStatus(ZkStreamTest.SCOPE, streamName, UUID.randomUUID(), context, executor).get().equals(TxnStatus.UNKNOWN);
}
use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.
the class ControllerRestApiTest method restApiTests.
@Test(timeout = 300000)
public void restApiTests() {
Service conService = Utils.createPravegaControllerService(null);
List<URI> ctlURIs = conService.getServiceDetails();
URI controllerRESTUri = ctlURIs.get(1);
Invocation.Builder builder;
Response response;
restServerURI = "http://" + controllerRESTUri.getHost() + ":" + controllerRESTUri.getPort();
log.info("REST Server URI: {}", restServerURI);
// TEST REST server status, ping test
resourceURl = new StringBuilder(restServerURI).append("/ping").toString();
webTarget = client.target(resourceURl);
builder = webTarget.request();
response = builder.get();
assertEquals("Ping test", OK.getStatusCode(), response.getStatus());
log.info("REST Server is running. Ping successful.");
final String scope1 = RandomStringUtils.randomAlphanumeric(10);
final String stream1 = RandomStringUtils.randomAlphanumeric(10);
// TEST CreateScope POST http://controllerURI:Port/v1/scopes
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes").toString();
webTarget = client.target(resourceURl);
final CreateScopeRequest createScopeRequest = new CreateScopeRequest();
createScopeRequest.setScopeName(scope1);
builder = webTarget.request(MediaType.APPLICATION_JSON_TYPE);
response = builder.post(Entity.json(createScopeRequest));
assertEquals("Create scope status", CREATED.getStatusCode(), response.getStatus());
Assert.assertEquals("Create scope response", scope1, response.readEntity(ScopeProperty.class).getScopeName());
log.info("Create scope: {} successful ", scope1);
// TEST CreateStream POST http://controllerURI:Port/v1/scopes/{scopeName}/streams
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams").toString();
webTarget = client.target(resourceURl);
CreateStreamRequest createStreamRequest = new CreateStreamRequest();
ScalingConfig scalingConfig = new ScalingConfig();
scalingConfig.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS);
scalingConfig.setTargetRate(2);
scalingConfig.scaleFactor(2);
scalingConfig.minSegments(2);
RetentionConfig retentionConfig = new RetentionConfig();
retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
retentionConfig.setValue(123L);
createStreamRequest.setStreamName(stream1);
createStreamRequest.setScalingPolicy(scalingConfig);
createStreamRequest.setRetentionPolicy(retentionConfig);
builder = webTarget.request(MediaType.APPLICATION_JSON_TYPE);
response = builder.post(Entity.json(createStreamRequest));
assertEquals("Create stream status", CREATED.getStatusCode(), response.getStatus());
final StreamProperty streamPropertyResponse = response.readEntity(StreamProperty.class);
assertEquals("Scope name in response", scope1, streamPropertyResponse.getScopeName());
assertEquals("Stream name in response", stream1, streamPropertyResponse.getStreamName());
log.info("Create stream: {} successful", stream1);
// Test listScopes GET http://controllerURI:Port/v1/scopes/{scopeName}/streams
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes").toString();
webTarget = client.target(resourceURl);
builder = webTarget.request();
response = builder.get();
assertEquals("List scopes", OK.getStatusCode(), response.getStatus());
log.info("List scopes successful");
// Test listStream GET /v1/scopes/scope1/streams
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams").toString();
webTarget = client.target(resourceURl);
builder = webTarget.request();
response = builder.get();
assertEquals("List streams", OK.getStatusCode(), response.getStatus());
Assert.assertEquals("List streams size", 1, response.readEntity(StreamsList.class).getStreams().size());
log.info("List streams successful");
// Test getScope
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1).toString();
response = client.target(resourceURl).request().get();
assertEquals("Get scope status", OK.getStatusCode(), response.getStatus());
assertEquals("Get scope scope1 response", scope1, response.readEntity(ScopeProperty.class).getScopeName());
log.info("Get scope successful");
// Test updateStream
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1).toString();
UpdateStreamRequest updateStreamRequest = new UpdateStreamRequest();
ScalingConfig scalingConfig1 = new ScalingConfig();
scalingConfig1.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS);
scalingConfig1.setTargetRate(2);
// update existing scaleFactor from 2 to 3
scalingConfig1.scaleFactor(3);
// update existing minSegments from 2 to 4
scalingConfig1.minSegments(4);
updateStreamRequest.setScalingPolicy(scalingConfig1);
updateStreamRequest.setRetentionPolicy(retentionConfig);
response = client.target(resourceURl).request(MediaType.APPLICATION_JSON_TYPE).put(Entity.json(updateStreamRequest));
assertEquals("Update stream status", OK.getStatusCode(), response.getStatus());
assertEquals("Verify updated property", 4, response.readEntity(StreamProperty.class).getScalingPolicy().getMinSegments().intValue());
log.info("Update stream successful");
// Test getStream
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1).toString();
response = client.target(resourceURl).request().get();
assertEquals("Get stream status", OK.getStatusCode(), response.getStatus());
assertEquals("Get stream stream1 response", stream1, response.readEntity(StreamProperty.class).getStreamName());
log.info("Get stream successful");
// Test updateStreamState
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1 + "/state").toString();
StreamState streamState = new StreamState();
streamState.setStreamState(StreamState.StreamStateEnum.SEALED);
response = client.target(resourceURl).request(MediaType.APPLICATION_JSON_TYPE).put(Entity.json(streamState));
assertEquals("UpdateStreamState status", OK.getStatusCode(), response.getStatus());
assertEquals("UpdateStreamState status in response", streamState.getStreamState(), response.readEntity(StreamState.class).getStreamState());
log.info("Update stream state successful");
// Test deleteStream
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1).toString();
response = client.target(resourceURl).request().delete();
assertEquals("DeleteStream status", NO_CONTENT.getStatusCode(), response.getStatus());
log.info("Delete stream successful");
// Test deleteScope
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1).toString();
response = client.target(resourceURl).request().delete();
assertEquals("Get scope status", NO_CONTENT.getStatusCode(), response.getStatus());
log.info("Delete Scope successful");
// Test reader groups APIs.
// Prepare the streams and readers using the admin client.
final String testScope = RandomStringUtils.randomAlphanumeric(10);
final String testStream1 = RandomStringUtils.randomAlphanumeric(10);
final String testStream2 = RandomStringUtils.randomAlphanumeric(10);
URI controllerUri = ctlURIs.get(0);
try (StreamManager streamManager = new StreamManagerImpl(ClientConfig.builder().controllerURI(controllerUri).build())) {
log.info("Creating scope: {}", testScope);
streamManager.createScope(testScope);
log.info("Creating stream: {}", testStream1);
StreamConfiguration streamConf1 = StreamConfiguration.builder().scope(testScope).streamName(testStream1).scalingPolicy(ScalingPolicy.fixed(1)).build();
streamManager.createStream(testScope, testStream1, streamConf1);
log.info("Creating stream: {}", testStream2);
StreamConfiguration streamConf2 = StreamConfiguration.builder().scope(testScope).streamName(testStream2).scalingPolicy(ScalingPolicy.fixed(1)).build();
streamManager.createStream(testScope, testStream2, streamConf2);
}
final String readerGroupName1 = RandomStringUtils.randomAlphanumeric(10);
final String readerGroupName2 = RandomStringUtils.randomAlphanumeric(10);
final String reader1 = RandomStringUtils.randomAlphanumeric(10);
final String reader2 = RandomStringUtils.randomAlphanumeric(10);
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
Controller controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerUri).build()).build(), executor);
try (ClientFactory clientFactory = new ClientFactoryImpl(testScope, controller);
ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(testScope, ClientConfig.builder().controllerURI(controllerUri).build())) {
final ReaderGroupConfig config = ReaderGroupConfig.builder().stream(Stream.of(testScope, testStream1)).stream(Stream.of(testScope, testStream2)).build();
readerGroupManager.createReaderGroup(readerGroupName1, config);
readerGroupManager.createReaderGroup(readerGroupName2, config);
clientFactory.createReader(reader1, readerGroupName1, new JavaSerializer<Long>(), ReaderConfig.builder().build());
clientFactory.createReader(reader2, readerGroupName1, new JavaSerializer<Long>(), ReaderConfig.builder().build());
}
// Verify the reader group info using REST APIs.
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + testScope + "/readergroups").toString();
response = client.target(resourceURl).request().get();
assertEquals("Get readergroups status", OK.getStatusCode(), response.getStatus());
ReaderGroupsList readerGroupsList = response.readEntity(ReaderGroupsList.class);
assertEquals("Get readergroups size", 2, readerGroupsList.getReaderGroups().size());
assertTrue(readerGroupsList.getReaderGroups().contains(new ReaderGroupsListReaderGroups().readerGroupName(readerGroupName1)));
assertTrue(readerGroupsList.getReaderGroups().contains(new ReaderGroupsListReaderGroups().readerGroupName(readerGroupName2)));
log.info("Get readergroups successful");
// Test fetching readergroup info.
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + testScope + "/readergroups/" + readerGroupName1).toString();
response = client.target(resourceURl).request().get();
assertEquals("Get readergroup properties status", OK.getStatusCode(), response.getStatus());
ReaderGroupProperty readerGroupProperty = response.readEntity(ReaderGroupProperty.class);
assertEquals("Get readergroup name", readerGroupName1, readerGroupProperty.getReaderGroupName());
assertEquals("Get readergroup scope name", testScope, readerGroupProperty.getScopeName());
assertEquals("Get readergroup streams size", 2, readerGroupProperty.getStreamList().size());
assertTrue(readerGroupProperty.getStreamList().contains(testStream1));
assertTrue(readerGroupProperty.getStreamList().contains(testStream2));
assertEquals("Get readergroup onlinereaders size", 2, readerGroupProperty.getOnlineReaderIds().size());
assertTrue(readerGroupProperty.getOnlineReaderIds().contains(reader1));
assertTrue(readerGroupProperty.getOnlineReaderIds().contains(reader2));
// Test readergroup or scope not found.
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + testScope + "/readergroups/" + "unknownreadergroup").toString();
response = client.target(resourceURl).request().get();
assertEquals("Get readergroup properties status", NOT_FOUND.getStatusCode(), response.getStatus());
resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + "unknownscope" + "/readergroups/" + readerGroupName1).toString();
response = client.target(resourceURl).request().get();
assertEquals("Get readergroup properties status", NOT_FOUND.getStatusCode(), response.getStatus());
log.info("Get readergroup properties successful");
log.info("Test restApiTests passed successfully!");
}
Aggregations