use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ModelHelperTest method encodeSegmentWithRange.
@Test
public void encodeSegmentWithRange() {
SegmentWithRange segment = ModelHelper.encode(createSegmentRange(.25, .75));
assertEquals("testStream", segment.getSegment().getStreamName());
assertEquals("testScope", segment.getSegment().getScope());
assertEquals(.25, segment.getRange().getLow(), 0.0);
assertEquals(.75, segment.getRange().getHigh(), 0.0);
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class KeyValueTableSegmentsTests method createSegmentMap.
private TreeMap<Double, SegmentWithRange> createSegmentMap() {
final int rangeIncrease = 10;
int totalRangeLength = 0;
val ranges = new ArrayList<Integer>();
for (int i = 0; i < SEGMENT_COUNT; i++) {
int rangeLength = (ranges.size() == 0 ? 0 : ranges.get(i - 1)) + rangeIncrease;
ranges.add(rangeLength);
totalRangeLength += rangeLength;
}
val result = new TreeMap<Double, SegmentWithRange>();
int rangeLow = 0;
for (int i = 0; i < ranges.size(); i++) {
int rangeLength = ranges.get(i);
int rangeHigh = rangeLow + rangeLength;
val segment = new Segment(SCOPE_NAME, STREAM_NAME, i);
val segmentWithRange = new SegmentWithRange(segment, (double) rangeLow / totalRangeLength, (double) rangeHigh / totalRangeLength);
result.put(segmentWithRange.getRange().getHigh(), segmentWithRange);
rangeLow = rangeHigh;
}
return result;
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class AbstractControllerMetadataCommandsTest method testControllerMetadataViewReaderInfoCommand.
@Test
public void testControllerMetadataViewReaderInfoCommand() throws Exception {
final String process = UUID.randomUUID().toString();
final String readerGroup = UUID.randomUUID().toString();
final String reader = UUID.randomUUID().toString();
ZKHelper zkHelper = ZKHelper.create(SETUP_UTILS.getZkTestServer().getConnectString(), "pravega-cluster");
CheckpointStore checkpointStore = zkHelper.getCheckPointStore();
checkpointStore.addReaderGroup(process, readerGroup);
checkpointStore.addReader(process, readerGroup, reader);
Position position = new PositionImpl(ImmutableMap.of(new SegmentWithRange(Segment.fromScopedName("testScope/testStream/0"), 0, 0.5), 9999999L, new SegmentWithRange(Segment.fromScopedName("testScope/testStream/1"), 0.5, 1.0), -1L));
checkpointStore.setPosition(process, readerGroup, reader, position);
String commandResult = TestUtils.executeCommand("controller-metadata get-reader " + process + " " + readerGroup + " " + reader, STATE.get());
Assert.assertTrue(commandResult.contains("testScope/testStream"));
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ReaderGroupManagerImplTest method testCreateReaderGroupWithNewConfig.
@Test
public void testCreateReaderGroupWithNewConfig() {
ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s2"), createStreamCut("s2", 0)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
ReaderGroupConfig expectedConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
when(controller.createReaderGroup(anyString(), anyString(), any(ReaderGroupConfig.class))).thenReturn(CompletableFuture.completedFuture(expectedConfig));
// Create a ReaderGroup
ReaderGroupConfig newConfig = ReaderGroupConfig.builder().stream(createStream("s1"), createStreamCut("s1", 2)).build();
assertThrows(ConfigMismatchException.class, () -> readerGroupManager.createReaderGroup(GROUP_NAME, newConfig));
verify(clientFactory, never()).createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class));
Map<SegmentWithRange, Long> segments = ImmutableMap.<SegmentWithRange, Long>builder().put(new SegmentWithRange(new Segment(SCOPE, "s2", 0), 0.0, 1.0), 10L).build();
ReaderGroupState.ReaderGroupStateInit initState = new ReaderGroupState.ReaderGroupStateInit(expectedConfig, segments, new HashMap<>(), false);
verify(synchronizer, never()).initialize(initState);
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class MockController method getSegmentsWithRanges.
@Synchronized
List<SegmentWithRange> getSegmentsWithRanges(Stream stream) {
StreamConfiguration config = getStreamConfig(stream);
Preconditions.checkArgument(config != null, "Stream must be created first");
ScalingPolicy scalingPolicy = config.getScalingPolicy();
if (scalingPolicy.getScaleType() != ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS) {
throw new IllegalArgumentException("Dynamic scaling not supported with a mock controller");
}
List<SegmentWithRange> result = new ArrayList<>();
for (int i = 0; i < scalingPolicy.getMinNumSegments(); i++) {
result.add(createRange(stream.getScope(), stream.getStreamName(), scalingPolicy.getMinNumSegments(), i));
}
return result;
}
Aggregations