use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class TestHashStreamRanges method testConstructor.
@Test
public void testConstructor() {
NavigableMap<Long, RangeProperties> ranges = Maps.newTreeMap();
for (long hashKey = 0L; hashKey < 10L; hashKey++) {
RangeProperties props = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey).setStartHashKey(hashKey).setEndHashKey(hashKey).build();
ranges.put(hashKey, props);
}
HashStreamRanges hsr = new HashStreamRanges(ranges, 9L);
assertEquals(RangeKeyType.HASH, hsr.getKeyType());
assertEquals(ranges, hsr.getRanges());
assertEquals(9L, hsr.getMaxRangeId());
}
use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class TestStreamRanges method testNotEqual.
@Test
public void testNotEqual() {
NavigableMap<Long, RangeProperties> ranges1 = Maps.newTreeMap();
NavigableMap<Long, RangeProperties> ranges2 = Maps.newTreeMap();
for (long hashKey = 0L; hashKey < 10L; hashKey++) {
RangeProperties props1 = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey).setStartHashKey(hashKey).setEndHashKey(hashKey).build();
ranges1.put(hashKey, props1);
RangeProperties props2 = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey + 1).setStartHashKey(hashKey + 1).setEndHashKey(hashKey + 1).build();
ranges2.put(hashKey, props2);
}
HashStreamRanges hsr1 = StreamRanges.ofHash(RangeKeyType.HASH, ranges1);
HashStreamRanges hsr2 = StreamRanges.ofHash(RangeKeyType.HASH, ranges2);
assertNotEquals(hsr1, hsr2);
}
use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class TestStreamRanges method testEqual.
@Test
public void testEqual() {
NavigableMap<Long, RangeProperties> ranges1 = Maps.newTreeMap();
NavigableMap<Long, RangeProperties> ranges2 = Maps.newTreeMap();
for (long hashKey = 0L; hashKey < 10L; hashKey++) {
RangeProperties props1 = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey).setStartHashKey(hashKey).setEndHashKey(hashKey).build();
ranges1.put(hashKey, props1);
RangeProperties props2 = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey).setStartHashKey(hashKey).setEndHashKey(hashKey).build();
ranges2.put(hashKey, props2);
}
HashStreamRanges hsr1 = StreamRanges.ofHash(RangeKeyType.HASH, ranges1);
HashStreamRanges hsr2 = StreamRanges.ofHash(RangeKeyType.HASH, ranges2);
assertEquals(hsr1, hsr2);
}
use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class TestStreamRanges method testConstructor.
@Test
public void testConstructor() {
NavigableMap<Long, RangeProperties> ranges = Maps.newTreeMap();
for (long hashKey = 0L; hashKey < 10L; hashKey++) {
RangeProperties props = RangeProperties.newBuilder().setStorageContainerId(hashKey).setRangeId(hashKey).setStartHashKey(hashKey).setEndHashKey(hashKey).build();
ranges.put(hashKey, props);
}
HashStreamRanges hsr = StreamRanges.ofHash(RangeKeyType.HASH, ranges);
assertEquals(RangeKeyType.HASH, hsr.getKeyType());
assertEquals(ranges, hsr.getRanges());
assertEquals(9L, hsr.getMaxRangeId());
}
use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class ProtoUtils method split.
public static List<RangeProperties> split(long streamId, int numInitialRanges, long nextRangeId, StorageContainerPlacementPolicy placementPolicy) {
int numRanges = Math.max(2, numInitialRanges);
if (numRanges % 2 != 0) {
// round up to odd number
numRanges = numRanges + 1;
}
long rangeSize = Long.MAX_VALUE / (numRanges / 2);
long startKey = Long.MIN_VALUE;
List<RangeProperties> ranges = Lists.newArrayListWithExpectedSize(numRanges);
for (int idx = 0; idx < numRanges; ++idx) {
long endKey = startKey + rangeSize;
if (numRanges - 1 == idx) {
endKey = Long.MAX_VALUE;
}
long rangeId = nextRangeId++;
RangeProperties props = RangeProperties.newBuilder().setStartHashKey(startKey).setEndHashKey(endKey).setStorageContainerId(placementPolicy.placeStreamRange(streamId, rangeId)).setRangeId(rangeId).build();
startKey = endKey;
ranges.add(props);
}
return ranges;
}
Aggregations