本文整理汇总了Java中org.apache.cassandra.dht.BigIntegerToken类的典型用法代码示例。如果您正苦于以下问题:Java BigIntegerToken类的具体用法?Java BigIntegerToken怎么用?Java BigIntegerToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BigIntegerToken类属于org.apache.cassandra.dht包,在下文中一共展示了BigIntegerToken类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMoveLeft
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
/**
* test basic methods to move a node. For sure, it's not the best place, but it's easy to test
*
* @throws 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);
}
示例2: testMoveRight
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@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]);
}
示例3: setup
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
public void setup(Class stratClass, Map<String, String> strategyOptions) throws Exception
{
tmd = new TokenMetadata();
searchToken = new BigIntegerToken(String.valueOf(15));
strategy = getStrategyWithNewTokenMetadata(Keyspace.open("Keyspace3").getReplicationStrategy(), tmd);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(10)), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(20)), InetAddress.getByName("127.0.0.2"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(30)), InetAddress.getByName("127.0.0.3"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(40)), InetAddress.getByName("127.0.0.4"));
//tmd.updateNormalToken(new BigIntegerToken(String.valueOf(50)), InetAddress.getByName("127.0.0.5"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(60)), InetAddress.getByName("127.0.0.6"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(70)), InetAddress.getByName("127.0.0.7"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(80)), InetAddress.getByName("127.0.0.8"));
}
示例4: testMoveLeft
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
/**
* test basic methods to move a node. For sure, it's not the best place, but it's easy to test
*
* @throws 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, newToken);
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);
}
示例5: testMoveRight
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@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, newToken);
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]);
}
示例6: createInitialRing
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
/** Setup a virtual node ring */
private static Map<Token<?>, InetAddress> createInitialRing(int size) throws UnknownHostException
{
Map<Token<?>, InetAddress> tokenMap = new HashMap<Token<?>, InetAddress>();
int currentToken = TOKEN_STEP;
for(int i = 0; i < size; i++)
{
InetAddress endpoint = InetAddress.getByName("127.0.0." + String.valueOf(i + 1));
Gossiper.instance.initializeNodeUnsafe(endpoint, UUID.randomUUID(), 1);
List<Token> tokens = new ArrayList<Token>();
for (int j = 0; j < TOKENS_PER_NODE; j++)
{
Token token = new BigIntegerToken(String.valueOf(currentToken));
tokenMap.put(token, endpoint);
tokens.add(token);
currentToken += TOKEN_STEP;
}
Gossiper.instance.injectApplicationState(endpoint, ApplicationState.TOKENS, vvFactory.tokens(tokens));
StorageService.instance.onChange(endpoint, ApplicationState.STATUS, vvFactory.normal(tokens));
}
return tokenMap;
}
示例7: setup
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
public void setup(Class stratClass, Map<String, String> strategyOptions) throws Exception
{
tmd = new TokenMetadata();
searchToken = new BigIntegerToken(String.valueOf(15));
strategy = getStrategyWithNewTokenMetadata(Keyspace.open(KEYSPACE).getReplicationStrategy(), tmd);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(10)), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(20)), InetAddress.getByName("127.0.0.2"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(30)), InetAddress.getByName("127.0.0.3"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(40)), InetAddress.getByName("127.0.0.4"));
//tmd.updateNormalToken(new BigIntegerToken(String.valueOf(50)), InetAddress.getByName("127.0.0.5"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(60)), InetAddress.getByName("127.0.0.6"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(70)), InetAddress.getByName("127.0.0.7"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(80)), InetAddress.getByName("127.0.0.8"));
}
示例8: setup
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
public void setup(Class stratClass, Map<String, String> strategyOptions) throws Exception
{
tmd = new TokenMetadata();
searchToken = new BigIntegerToken(String.valueOf(15));
strategy = getStrategyWithNewTokenMetadata(Table.open("Keyspace3").getReplicationStrategy(), tmd);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(10)), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(20)), InetAddress.getByName("127.0.0.2"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(30)), InetAddress.getByName("127.0.0.3"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(40)), InetAddress.getByName("127.0.0.4"));
//tmd.updateNormalToken(new BigIntegerToken(String.valueOf(50)), InetAddress.getByName("127.0.0.5"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(60)), InetAddress.getByName("127.0.0.6"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(70)), InetAddress.getByName("127.0.0.7"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(80)), InetAddress.getByName("127.0.0.8"));
}
示例9: getPartition
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@Override
public int getPartition(AvroKey<ByteBuffer> key, Object value, int numReducers) {
if (distributeRandomly) {
return reducers.get(random.nextInt(reducers.size()));
}
final Token token = partitioner.getToken(key.datum());
BigInteger bigIntToken;
if (token instanceof BigIntegerToken) {
bigIntToken = ((BigIntegerToken) token).token.abs();
} else if (token instanceof LongToken) {
bigIntToken = BigInteger.valueOf(((LongToken) token).token).add(MURMUR3_SCALE);
} else {
throw new RuntimeException("Invalid partitioner Token type. Only BigIntegerToken and LongToken supported");
}
return reducers.get(bigIntToken.divide(rangePerReducer).intValue());
}
示例10: addEndpoint
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
private void addEndpoint(String endpointTokenID, String keyTokenID, String endpointAddress) throws UnknownHostException
{
BigIntegerToken endpointToken = new BigIntegerToken(endpointTokenID);
endpointTokens.add(endpointToken);
BigIntegerToken keyToken = new BigIntegerToken(keyTokenID);
keyTokens.add(keyToken);
InetAddress ep = InetAddress.getByName(endpointAddress);
tmd.updateNormalToken(endpointToken, ep);
}
示例11: testMoveMiddleOfRing
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@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[] toStream = ranges.left.toArray(new Range[0]);
Range[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
// build expected ranges
Range[] toStreamExpected = new Range[2];
toStreamExpected[0] = new Range(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens));
toStreamExpected[1] = new Range(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens));
Arrays.sort(toStreamExpected);
Range[] toFetchExpected = new Range[2];
toFetchExpected[0] = new Range(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
toFetchExpected[1] = new Range(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove));
Arrays.sort(toFetchExpected);
assertEquals(Arrays.equals(toStream, toStreamExpected), true);
assertEquals(Arrays.equals(toFetch, toFetchExpected), true);
}
示例12: testMoveAfterNextNeighbors
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@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[] toStream = ranges.left.toArray(new Range[0]);
Range[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
// build expected ranges
Range[] toStreamExpected = new Range[1];
toStreamExpected[0] = new Range(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens));
Arrays.sort(toStreamExpected);
Range[] toFetchExpected = new Range[2];
toFetchExpected[0] = new Range(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens));
toFetchExpected[1] = new Range(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove));
Arrays.sort(toFetchExpected);
assertEquals(Arrays.equals(toStream, toStreamExpected), true);
assertEquals(Arrays.equals(toFetch, toFetchExpected), true);
}
示例13: testMoveBeforePreviousNeighbor
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
@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[] toStream = ranges.left.toArray(new Range[0]);
Range[] toFetch = ranges.right.toArray(new Range[0]);
Arrays.sort(toStream);
Arrays.sort(toFetch);
Range[] toStreamExpected = new Range[2];
toStreamExpected[0] = new Range(getToken(movingNodeIdx, tokensAfterMove), getToken(movingNodeIdx - 1, tokensAfterMove));
toStreamExpected[1] = new Range(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens));
Arrays.sort(toStreamExpected);
Range[] toFetchExpected = new Range[1];
toFetchExpected[0] = new Range(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);
}
示例14: initTokensAfterMove
import org.apache.cassandra.dht.BigIntegerToken; //导入依赖的package包/类
private BigIntegerToken[] initTokensAfterMove(BigIntegerToken[] tokens,
int movingNodeIdx, BigIntegerToken newToken)
{
BigIntegerToken[] tokensAfterMove = tokens.clone();
tokensAfterMove[movingNodeIdx] = newToken;
return tokensAfterMove;
}