use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class RangeTest method testIntersectionTwoWraps.
@Test
public void testIntersectionTwoWraps() {
Range<Token> wraps1 = new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("20"));
Range<Token> wraps2 = new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("90"));
Range<Token> wraps3 = new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("110"));
Range<Token> wraps4 = new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("0"));
Range<Token> wraps5 = new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("1"));
Range<Token> wraps6 = new Range<Token>(new BigIntegerToken("30"), new BigIntegerToken("10"));
assertIntersection(wraps1, wraps2, new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("20")));
assertIntersection(wraps1, wraps3, new Range<Token>(new BigIntegerToken("120"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("110")));
assertIntersection(wraps1, wraps4, new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("0")));
assertIntersection(wraps1, wraps5, new Range<Token>(new BigIntegerToken("10"), new BigIntegerToken("20")), new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("1")));
assertIntersection(wraps1, wraps6, new Range<Token>(new BigIntegerToken("100"), new BigIntegerToken("10")));
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class PendingRangeMapsTest method testWrapAroundRanges.
@Test
public void testWrapAroundRanges() throws UnknownHostException {
PendingRangeMaps pendingRangeMaps = new PendingRangeMaps();
pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1"));
pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2"));
pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3"));
pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4"));
pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5"));
pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6"));
pendingRangeMaps.addPendingRange(genRange("65", "7"), InetAddress.getByName("127.0.0.7"));
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size());
assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("7")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("10")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("20")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("25")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("35")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("45")).size());
assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size());
Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("6"));
assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1")));
assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.7")));
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class PendingRangeMapsTest method testPendingEndpoints.
@Test
public void testPendingEndpoints() throws UnknownHostException {
PendingRangeMaps pendingRangeMaps = new PendingRangeMaps();
pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1"));
pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2"));
pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3"));
pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4"));
pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5"));
pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6"));
assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size());
assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("10")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("20")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("25")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("35")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("45")).size());
assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size());
assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size());
Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15"));
assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1")));
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method testMoveBeforePreviousNeighbor.
@SuppressWarnings("unchecked")
@Test
public void testMoveBeforePreviousNeighbor() throws UnknownHostException {
// moves before its previous neighbor in the ring
int movingNodeIdx = 1;
int movingNodeIdxAfterMove = 7;
BigIntegerToken newToken = new BigIntegerToken("158873535527910577765226390751398592512");
BigIntegerToken[] tokens = initTokens();
BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
Range<Token>[] toStream = ranges.left.toArray(new Range[0]);
Range<Token>[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
Range<Token>[] toStreamExpected = new Range[2];
toStreamExpected[0] = new Range<Token>(getToken(movingNodeIdx, tokensAfterMove), getToken(movingNodeIdx - 1, tokensAfterMove));
toStreamExpected[1] = new Range<Token>(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens));
Arrays.sort(toStreamExpected);
Range<Token>[] toFetchExpected = new Range[1];
toFetchExpected[0] = new Range<Token>(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
Arrays.sort(toFetchExpected);
System.out.println("toStream : " + Arrays.toString(toStream));
System.out.println("toFetch : " + Arrays.toString(toFetch));
System.out.println("toStreamExpected : " + Arrays.toString(toStreamExpected));
System.out.println("toFetchExpected : " + Arrays.toString(toFetchExpected));
assertEquals(Arrays.equals(toStream, toStreamExpected), true);
assertEquals(Arrays.equals(toFetch, toFetchExpected), true);
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method calculateStreamAndFetchRanges.
private Pair<Set<Range<Token>>, Set<Range<Token>>> calculateStreamAndFetchRanges(BigIntegerToken[] tokens, BigIntegerToken[] tokensAfterMove, int movingNodeIdx) throws UnknownHostException {
RackInferringSnitch endpointSnitch = new RackInferringSnitch();
InetAddress movingNode = InetAddress.getByName("254.0.0." + Integer.toString(movingNodeIdx + 1));
TokenMetadata tokenMetadataCurrent = initTokenMetadata(tokens);
TokenMetadata tokenMetadataAfterMove = initTokenMetadata(tokensAfterMove);
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tokenMetadataCurrent, endpointSnitch, optsWithRF(2));
Collection<Range<Token>> currentRanges = strategy.getAddressRanges().get(movingNode);
Collection<Range<Token>> updatedRanges = strategy.getPendingAddressRanges(tokenMetadataAfterMove, tokensAfterMove[movingNodeIdx], movingNode);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = StorageService.instance.calculateStreamAndFetchRanges(currentRanges, updatedRanges);
return ranges;
}
Aggregations