use of io.pravega.client.tables.impl.KeyValueTableSegments in project pravega by pravega.
the class ControllerImplTest method testGetCurrentSegmentsKeyValueTable.
@Test
public void testGetCurrentSegmentsKeyValueTable() throws Exception {
CompletableFuture<KeyValueTableSegments> kvtSegments;
kvtSegments = controllerClient.getCurrentSegmentsForKeyValueTable("scope1", "kvtable1");
assertTrue(kvtSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "kvtable1", 4), kvtSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "kvtable1", 5), kvtSegments.get().getSegmentForKey(0.6));
kvtSegments = controllerClient.getCurrentSegmentsForKeyValueTable("scope1", "kvtable2");
AssertExtensions.assertFutureThrows("Should throw Exception", kvtSegments, throwable -> true);
}
use of io.pravega.client.tables.impl.KeyValueTableSegments in project pravega by pravega.
the class MockController method getCurrentSegments.
private KeyValueTableSegments getCurrentSegments(KeyValueTableInfo kvt) {
List<Segment> segmentsInStream = getSegmentsForKeyValueTable(kvt);
TreeMap<Double, SegmentWithRange> segments = new TreeMap<>();
for (int i = 0; i < segmentsInStream.size(); i++) {
SegmentWithRange s = createRange(kvt.getScope(), kvt.getKeyValueTableName(), segmentsInStream.size(), i);
segments.put(s.getRange().getHigh(), s);
}
return new KeyValueTableSegments(segments);
}
use of io.pravega.client.tables.impl.KeyValueTableSegments in project pravega by pravega.
the class LocalControllerTest method testGetCurrentSegmentsKeyValueTable.
@Test(timeout = 10000)
public void testGetCurrentSegmentsKeyValueTable() throws Exception {
Controller.StreamInfo info = Controller.StreamInfo.newBuilder().setScope("scope").setStream("kvtable").build();
Controller.SegmentId segment1 = Controller.SegmentId.newBuilder().setSegmentId(1).setStreamInfo(info).build();
Controller.SegmentId segment2 = Controller.SegmentId.newBuilder().setSegmentId(2).setStreamInfo(info).build();
Controller.SegmentId segment3 = Controller.SegmentId.newBuilder().setSegmentId(3).setStreamInfo(info).build();
Controller.SegmentRange segmentRange1 = Controller.SegmentRange.newBuilder().setSegmentId(segment1).setMinKey(0.1).setMaxKey(0.3).build();
Controller.SegmentRange segmentRange2 = Controller.SegmentRange.newBuilder().setSegmentId(segment2).setMinKey(0.4).setMaxKey(0.6).build();
Controller.SegmentRange segmentRange3 = Controller.SegmentRange.newBuilder().setSegmentId(segment3).setMinKey(0.7).setMaxKey(1.0).build();
List<Controller.SegmentRange> segmentsList = new ArrayList<Controller.SegmentRange>(3);
segmentsList.add(segmentRange1);
segmentsList.add(segmentRange2);
segmentsList.add(segmentRange3);
when(this.mockControllerService.getCurrentSegmentsKeyValueTable(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(segmentsList));
KeyValueTableSegments segments = this.testController.getCurrentSegmentsForKeyValueTable("scope", "kvtable").get();
assertEquals(3, segments.getSegments().size());
}
use of io.pravega.client.tables.impl.KeyValueTableSegments in project pravega by pravega.
the class ControllerImpl method getCurrentSegmentsForKeyValueTable.
@Override
public CompletableFuture<KeyValueTableSegments> getCurrentSegmentsForKeyValueTable(String scope, String kvtName) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(kvtName, "stream");
long traceId = LoggerHelpers.traceEnter(log, "getCurrentSegmentsForKeyValueTable", scope, kvtName);
final long requestId = requestIdGenerator.get();
final CompletableFuture<SegmentRanges> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SegmentRanges> callback = new RPCAsyncCallback<>(traceId, "getCurrentSegmentsKeyValueTable", scope, kvtName);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_CURRENT_SEGMENTS_KEY_VALUE_TABLE, scope, kvtName).getCurrentSegmentsKeyValueTable(ModelHelper.createKeyValueTableInfo(scope, kvtName), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(ranges -> {
log.debug(requestId, "Received the following data from the controller {}", ranges.getSegmentRangesList());
NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
for (SegmentRange r : ranges.getSegmentRangesList()) {
Preconditions.checkState(r.getMinKey() <= r.getMaxKey(), "Min keyrange %s was not less than maximum keyRange %s for segment %s", r.getMinKey(), r.getMaxKey(), r.getSegmentId());
rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
}
return new KeyValueTableSegments(rangeMap);
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getCurrentSegmentsForKeyValueTable for {}/{} failed: ", scope, kvtName, e);
}
LoggerHelpers.traceLeave(log, "getCurrentSegmentsForKeyValueTable", traceId);
});
}
Aggregations