Search in sources :

Example 1 with RackInferringSnitch

use of org.apache.cassandra.locator.RackInferringSnitch in project cassandra by apache.

the class BootStrapperTest method testAllocateTokensNetworkStrategy.

public void testAllocateTokensNetworkStrategy(int rackCount, int replicas) throws UnknownHostException {
    IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();
    try {
        DatabaseDescriptor.setEndpointSnitch(new RackInferringSnitch());
        int vn = 16;
        String ks = "BootStrapperTestNTSKeyspace" + rackCount + replicas;
        String dc = "1";
        // Register peers with expected DC for NetworkTopologyStrategy.
        TokenMetadata metadata = StorageService.instance.getTokenMetadata();
        metadata.clearUnsafe();
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.1.0.99"));
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.15.0.99"));
        SchemaLoader.createKeyspace(ks, KeyspaceParams.nts(dc, replicas, "15", 15), SchemaLoader.standardCFMD(ks, "Standard1"));
        TokenMetadata tm = StorageService.instance.getTokenMetadata();
        tm.clearUnsafe();
        for (int i = 0; i < rackCount; ++i) generateFakeEndpoints(tm, 10, vn, dc, Integer.toString(i));
        InetAddress addr = InetAddress.getByName("127." + dc + ".0.99");
        allocateTokensForNode(vn, ks, tm, addr);
    // Note: Not matching replication factor in second datacentre, but this should not affect us.
    } finally {
        DatabaseDescriptor.setEndpointSnitch(oldSnitch);
    }
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) RackInferringSnitch(org.apache.cassandra.locator.RackInferringSnitch)

Aggregations

InetAddress (java.net.InetAddress)1 IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)1 RackInferringSnitch (org.apache.cassandra.locator.RackInferringSnitch)1 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)1