Search in sources :

Example 1 with StringToken

use of org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken in project cassandra by apache.

the class NetworkTopologyStrategyTest method tokenFactory.

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);
}
Also used : StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)

Example 2 with StringToken

use of org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken in project cassandra by apache.

the class NetworkTopologyStrategyTest method testProperties.

@Test
public void testProperties() throws IOException, ConfigurationException {
    IEndpointSnitch snitch = new PropertyFileSnitch();
    DatabaseDescriptor.setEndpointSnitch(snitch);
    TokenMetadata metadata = new TokenMetadata();
    createDummyTokens(metadata, true);
    Map<String, String> configOptions = new HashMap<String, String>();
    configOptions.put("DC1", "3");
    configOptions.put("DC2", "2");
    configOptions.put("DC3", "1");
    // Set the localhost to the tokenmetadata. Embedded cassandra way?
    NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(keyspaceName, metadata, snitch, configOptions);
    assert strategy.getReplicationFactor("DC1") == 3;
    assert strategy.getReplicationFactor("DC2") == 2;
    assert strategy.getReplicationFactor("DC3") == 1;
    // Query for the natural hosts
    ArrayList<InetAddress> endpoints = strategy.getNaturalEndpoints(new StringToken("123"));
    assert 6 == endpoints.size();
    // ensure uniqueness
    assert 6 == new HashSet<InetAddress>(endpoints).size();
}
Also used : InetAddress(java.net.InetAddress) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 3 with StringToken

use of org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangesWithNetworkTopologyStrategy.

@Test
public void testPrimaryRangesWithNetworkTopologyStrategy() 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");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.1"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.2"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.4"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.5"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D")));
}
Also used : LongToken(org.apache.cassandra.dht.Murmur3Partitioner.LongToken) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 4 with StringToken

use of org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangesWithSimpleStrategy.

@Test
public void testPrimaryRangesWithSimpleStrategy() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.2"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.3"));
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.simpleTransient(2));
    Schema.instance.load(meta);
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.1"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("A")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.2"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.3"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
}
Also used : LongToken(org.apache.cassandra.dht.Murmur3Partitioner.LongToken) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 5 with StringToken

use of org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly.

@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");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(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"))));
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Aggregations

StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)16 Test (org.junit.Test)15 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)11 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)11 InetAddress (java.net.InetAddress)9 Token (org.apache.cassandra.dht.Token)9 Range (org.apache.cassandra.dht.Range)8 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)6 HashMap (java.util.HashMap)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)3 ArrayList (java.util.ArrayList)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)1