本文整理汇总了Java中org.apache.cassandra.dht.StringToken类的典型用法代码示例。如果您正苦于以下问题:Java StringToken类的具体用法?Java StringToken怎么用?Java StringToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringToken类属于org.apache.cassandra.dht包,在下文中一共展示了StringToken类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly() throws Exception
{
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
metadata.clearUnsafe();
// DC1
metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
// DC2
metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));
Map<String, String> configOptions = new HashMap<>();
configOptions.put("DC2", "2");
Keyspace.clear("Keyspace1");
KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
Schema.instance.setKeyspaceDefinition(meta);
// endpoints in DC1 should not have primary range
Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
assertTrue(primaryRanges.isEmpty());
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
InetAddress.getByName("127.0.0.2"));
assertTrue(primaryRanges.isEmpty());
// endpoints in DC2 should have primary ranges which also cover DC1
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
assertTrue(primaryRanges.size() == 2);
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
assertTrue(primaryRanges.size() == 2);
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
}
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:39,代码来源:StorageServiceServerTest.java
示例2: testLargeCluster
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testLargeCluster() throws UnknownHostException, ConfigurationException
{
int[] dcRacks = new int[]{2, 4, 8};
int[] dcEndpoints = new int[]{128, 256, 512};
int[] dcReplication = new int[]{2, 6, 6};
IEndpointSnitch snitch = new RackInferringSnitch();
DatabaseDescriptor.setEndpointSnitch(snitch);
TokenMetadata metadata = new TokenMetadata();
Map<String, String> configOptions = new HashMap<String, String>();
Multimap<InetAddress, Token> tokens = HashMultimap.create();
int totalRF = 0;
for (int dc = 0; dc < dcRacks.length; ++dc)
{
totalRF += dcReplication[dc];
configOptions.put(Integer.toString(dc), Integer.toString(dcReplication[dc]));
for (int rack = 0; rack < dcRacks[dc]; ++rack)
{
for (int ep = 1; ep <= dcEndpoints[dc]/dcRacks[dc]; ++ep)
{
byte[] ipBytes = new byte[]{10, (byte)dc, (byte)rack, (byte)ep};
InetAddress address = InetAddress.getByAddress(ipBytes);
StringToken token = new StringToken(String.format("%02x%02x%02x", ep, rack, dc));
logger.debug("adding node " + address + " at " + token);
tokens.put(address, token);
}
}
}
metadata.updateNormalTokens(tokens);
NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(keyspaceName, metadata, snitch, configOptions);
for (String testToken : new String[]{"123456", "200000", "000402", "ffffff", "400200"})
{
List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata);
Set<InetAddress> epSet = new HashSet<InetAddress>(endpoints);
Assert.assertEquals(totalRF, endpoints.size());
Assert.assertEquals(totalRF, epSet.size());
logger.debug(testToken + ": " + endpoints.toString());
}
}
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:45,代码来源:NetworkTopologyStrategyTest.java
示例3: tokenFactory
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
public void tokenFactory(TokenMetadata metadata, String token, byte[] bytes) throws UnknownHostException
{
Token token1 = new StringToken(token);
InetAddress add1 = InetAddress.getByAddress(bytes);
metadata.updateNormalToken(token1, add1);
}
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:7,代码来源:NetworkTopologyStrategyTest.java
示例4: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy() throws Exception
{
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
metadata.clearUnsafe();
// DC1
metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
// DC2
metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));
Map<String, String> configOptions = new HashMap<>();
configOptions.put("DC1", "1");
configOptions.put("DC2", "1");
Keyspace.clear("Keyspace1");
KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
Schema.instance.setKeyspaceDefinition(meta);
Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
InetAddress.getByName("127.0.0.1"));
assertEquals(2, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
assertEquals(2, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
assertEquals(2, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
assertEquals(2, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
}
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:44,代码来源:StorageServiceServerTest.java
示例5: testPrimaryRangeForEndpointWithinDCWithVnodes
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithVnodes() throws Exception
{
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
metadata.clearUnsafe();
// DC1
Multimap<InetAddress, Token> dc1 = HashMultimap.create();
dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("A"));
dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("E"));
dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("H"));
dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("C"));
dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("I"));
dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("J"));
metadata.updateNormalTokens(dc1);
// DC2
Multimap<InetAddress, Token> dc2 = HashMultimap.create();
dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("B"));
dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("G"));
dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("L"));
dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("D"));
dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("F"));
dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("K"));
metadata.updateNormalTokens(dc2);
Map<String, String> configOptions = new HashMap<>();
configOptions.put("DC1", "1");
configOptions.put("DC2", "2");
Keyspace.clear("Keyspace1");
KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
Schema.instance.setKeyspaceDefinition(meta);
// endpoints in DC1 should have primary ranges which also cover DC2
Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
assertEquals(8, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
// endpoints in DC1 should have primary ranges which also cover DC2
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
assertEquals(4, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
// endpoints in DC2 should have primary ranges which also cover DC1
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
assertEquals(4, primaryRanges.size());
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
// because /127.0.0.4 holds token "B" which is the next to token "A" from /127.0.0.1,
// the node covers range (L, A]
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
assertTrue(primaryRanges.size() == 8);
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
// ranges from /127.0.0.1
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
// the next token to "H" in DC2 is "K" in /127.0.0.5, so (G, H] goes to /127.0.0.5
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
// ranges from /127.0.0.2
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
}
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:79,代码来源:StorageServiceServerTest.java
示例6: testLargeCluster
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testLargeCluster() throws UnknownHostException, ConfigurationException
{
int[] dcRacks = new int[]{2, 4, 8};
int[] dcEndpoints = new int[]{128, 256, 512};
int[] dcReplication = new int[]{2, 6, 6};
IEndpointSnitch snitch = new RackInferringSnitch();
DatabaseDescriptor.setEndpointSnitch(snitch);
TokenMetadata metadata = new TokenMetadata();
Map<String, String> configOptions = new HashMap<String, String>();
Multimap<InetAddress, Token> tokens = HashMultimap.create();
int totalRF = 0;
for (int dc = 0; dc < dcRacks.length; ++dc)
{
totalRF += dcReplication[dc];
configOptions.put(Integer.toString(dc), Integer.toString(dcReplication[dc]));
for (int rack = 0; rack < dcRacks[dc]; ++rack)
{
for (int ep = 1; ep <= dcEndpoints[dc]/dcRacks[dc]; ++ep)
{
byte[] ipBytes = new byte[]{10, (byte)dc, (byte)rack, (byte)ep};
InetAddress address = InetAddress.getByAddress(ipBytes);
StringToken token = new StringToken(String.format("%02x%02x%02x", ep, rack, dc));
logger.debug("adding node {} at {}", address, token);
tokens.put(address, token);
}
}
}
metadata.updateNormalTokens(tokens);
NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(keyspaceName, metadata, snitch, configOptions);
for (String testToken : new String[]{"123456", "200000", "000402", "ffffff", "400200"})
{
List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata);
Set<InetAddress> epSet = new HashSet<InetAddress>(endpoints);
Assert.assertEquals(totalRF, endpoints.size());
Assert.assertEquals(totalRF, epSet.size());
logger.debug("{}: {}", testToken, endpoints);
}
}
开发者ID:daidong,项目名称:GraphTrek,代码行数:45,代码来源:NetworkTopologyStrategyTest.java
示例7: testLargeCluster
import org.apache.cassandra.dht.StringToken; //导入依赖的package包/类
@Test
public void testLargeCluster() throws UnknownHostException, ConfigurationException
{
int[] dcRacks = new int[]{2, 4, 8};
int[] dcEndpoints = new int[]{128, 256, 512};
int[] dcReplication = new int[]{2, 6, 6};
IEndpointSnitch snitch = new RackInferringSnitch();
DatabaseDescriptor.setEndpointSnitch(snitch);
TokenMetadata metadata = new TokenMetadata();
Map<String, String> configOptions = new HashMap<String, String>();
Multimap<InetAddress, Token> tokens = HashMultimap.create();
int totalRF = 0;
for (int dc = 0; dc < dcRacks.length; ++dc)
{
totalRF += dcReplication[dc];
configOptions.put(Integer.toString(dc), Integer.toString(dcReplication[dc]));
for (int rack = 0; rack < dcRacks[dc]; ++rack)
{
for (int ep = 1; ep <= dcEndpoints[dc]/dcRacks[dc]; ++ep)
{
byte[] ipBytes = new byte[]{10, (byte)dc, (byte)rack, (byte)ep};
InetAddress address = InetAddress.getByAddress(ipBytes);
StringToken token = new StringToken(String.format("%02x%02x%02x", ep, rack, dc));
logger.debug("adding node " + address + " at " + token);
tokens.put(address, token);
}
}
}
metadata.updateNormalTokens(tokens);
NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(table, metadata, snitch, configOptions);
for (String testToken : new String[]{"123456", "200000", "000402", "ffffff", "400200"})
{
List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata);
Set<InetAddress> epSet = new HashSet<InetAddress>(endpoints);
Assert.assertEquals(totalRF, endpoints.size());
Assert.assertEquals(totalRF, epSet.size());
logger.debug(testToken + ": " + endpoints.toString());
}
}
开发者ID:dprguiuc,项目名称:Cassandra-Wasef,代码行数:45,代码来源:NetworkTopologyStrategyTest.java
注:本文中的org.apache.cassandra.dht.StringToken类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论