Search in sources :

Example 6 with RangeProperties

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());
}
Also used : RangeProperties(org.apache.bookkeeper.stream.proto.RangeProperties) Test(org.junit.Test)

Example 7 with RangeProperties

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);
}
Also used : RangeProperties(org.apache.bookkeeper.stream.proto.RangeProperties) Test(org.junit.Test)

Example 8 with RangeProperties

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);
}
Also used : RangeProperties(org.apache.bookkeeper.stream.proto.RangeProperties) Test(org.junit.Test)

Example 9 with RangeProperties

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());
}
Also used : RangeProperties(org.apache.bookkeeper.stream.proto.RangeProperties) Test(org.junit.Test)

Example 10 with RangeProperties

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;
}
Also used : RangeProperties(org.apache.bookkeeper.stream.proto.RangeProperties) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)

Aggregations

RangeProperties (org.apache.bookkeeper.stream.proto.RangeProperties)12 Test (org.junit.Test)6 HashStreamRanges (org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 List (java.util.List)2 NavigableMap (java.util.NavigableMap)2 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)2 Bytes (org.apache.bookkeeper.common.util.Bytes)2 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufUtil (io.netty.buffer.ByteBufUtil)1 Unpooled (io.netty.buffer.Unpooled)1 Map (java.util.Map)1 Optional (java.util.Optional)1