Search in sources :

Example 6 with BigIntegerToken

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);
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Test(org.junit.Test)

Example 7 with BigIntegerToken

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);
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Test(org.junit.Test)

Example 8 with BigIntegerToken

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);
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Test(org.junit.Test)

Example 9 with BigIntegerToken

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;
}
Also used : BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)

Example 10 with BigIntegerToken

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]);
}
Also used : Set(java.util.Set) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Test(org.junit.Test)

Aggregations

BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)31 Test (org.junit.Test)24 Token (org.apache.cassandra.dht.Token)12 InetAddress (java.net.InetAddress)11 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)11 Set (java.util.Set)6 Range (org.apache.cassandra.dht.Range)5 VersionedValue (org.apache.cassandra.gms.VersionedValue)4 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)4 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 ArrayList (java.util.ArrayList)2 IPartitioner (org.apache.cassandra.dht.IPartitioner)2 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)2 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)2