use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method testMoveMiddleOfRing.
@SuppressWarnings("unchecked")
@Test
public void testMoveMiddleOfRing() throws UnknownHostException {
// moves to another position in the middle of the ring : should stream all its data, and fetch all its new data
int movingNodeIdx = 1;
int movingNodeIdxAfterMove = 4;
BigIntegerToken newToken = new BigIntegerToken("90070591730234615865843651857942052864");
BigIntegerToken[] tokens = initTokens();
BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
// sort the results, so they can be compared
Range<Token>[] toStream = ranges.left.toArray(new Range[0]);
Range<Token>[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
// build expected ranges
Range<Token>[] toStreamExpected = new Range[2];
toStreamExpected[0] = new Range<Token>(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens));
toStreamExpected[1] = new Range<Token>(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens));
Arrays.sort(toStreamExpected);
Range<Token>[] toFetchExpected = new Range[2];
toFetchExpected[0] = new Range<Token>(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
toFetchExpected[1] = new Range<Token>(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove));
Arrays.sort(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 testMoveAfterNextNeighbors.
@SuppressWarnings("unchecked")
@Test
public void testMoveAfterNextNeighbors() throws UnknownHostException {
// moves after its next neighbor in the ring
int movingNodeIdx = 1;
int movingNodeIdxAfterMove = 2;
BigIntegerToken newToken = new BigIntegerToken("52535295865117307932921825928971026432");
BigIntegerToken[] tokens = initTokens();
BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
// sort the results, so they can be compared
Range<Token>[] toStream = ranges.left.toArray(new Range[0]);
Range<Token>[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
// build expected ranges
Range<Token>[] toStreamExpected = new Range[1];
toStreamExpected[0] = new Range<Token>(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens));
Arrays.sort(toStreamExpected);
Range<Token>[] toFetchExpected = new Range[2];
toFetchExpected[0] = new Range<Token>(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
toFetchExpected[1] = new Range<Token>(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove));
Arrays.sort(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 testMoveLeft.
/**
* test basic methods to move a node. For sure, it's not the best place, but it's easy to test
*
* @throws java.net.UnknownHostException
*/
@Test
public void testMoveLeft() throws UnknownHostException {
// Moves to the left : nothing to fetch, last part to stream
int movingNodeIdx = 1;
BigIntegerToken newToken = new BigIntegerToken("21267647932558653966460912964485513216");
BigIntegerToken[] tokens = initTokens();
BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
assertEquals(ranges.left.iterator().next().left, tokensAfterMove[movingNodeIdx]);
assertEquals(ranges.left.iterator().next().right, tokens[movingNodeIdx]);
assertEquals("No data should be fetched", ranges.right.size(), 0);
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method initTokenMetadata.
private TokenMetadata initTokenMetadata(BigIntegerToken[] tokens) throws UnknownHostException {
TokenMetadata tokenMetadataCurrent = new TokenMetadata();
int lastIPPart = 1;
for (BigIntegerToken token : tokens) tokenMetadataCurrent.updateNormalToken(token, InetAddress.getByName("254.0.0." + Integer.toString(lastIPPart++)));
return tokenMetadataCurrent;
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method testMoveRight.
@Test
public void testMoveRight() throws UnknownHostException {
// Moves to the right : last part to fetch, nothing to stream
int movingNodeIdx = 1;
BigIntegerToken newToken = new BigIntegerToken("35267647932558653966460912964485513216");
BigIntegerToken[] tokens = initTokens();
BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken);
Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx);
assertEquals("No data should be streamed", ranges.left.size(), 0);
assertEquals(ranges.right.iterator().next().left, tokens[movingNodeIdx]);
assertEquals(ranges.right.iterator().next().right, tokensAfterMove[movingNodeIdx]);
}
Aggregations