use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class PropertyFileSnitchTest method setup.
@Before
public void setup() throws ConfigurationException, IOException {
String confFile = FBUtilities.resourceToFile(PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME);
effectiveFile = Paths.get(confFile);
backupFile = Paths.get(confFile + ".bak");
restoreOrigConfigFile();
InetAddress[] hosts = { // this exists in the config file
InetAddress.getByName("127.0.0.1"), // this exists in the config file
InetAddress.getByName("127.0.0.2"), // this does not exist in the config file
InetAddress.getByName("127.0.0.9") };
IPartitioner partitioner = new RandomPartitioner();
valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
tokenMap = new HashMap<>();
for (InetAddress host : hosts) {
Set<Token> tokens = Collections.singleton(partitioner.getRandomToken());
Gossiper.instance.initializeNodeUnsafe(host, UUID.randomUUID(), 1);
Gossiper.instance.injectApplicationState(host, ApplicationState.TOKENS, valueFactory.tokens(tokens));
setNodeShutdown(host);
tokenMap.put(host, tokens);
}
}
use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class SimpleStrategyTest method testStringEndpoints.
@Test
public void testStringEndpoints() throws UnknownHostException {
IPartitioner partitioner = OrderPreservingPartitioner.instance;
List<Token> endpointTokens = new ArrayList<Token>();
List<Token> keyTokens = new ArrayList<Token>();
for (int i = 0; i < 5; i++) {
endpointTokens.add(new StringToken(String.valueOf((char) ('a' + i * 2))));
keyTokens.add(partitioner.getToken(ByteBufferUtil.bytes(String.valueOf((char) ('a' + i * 2 + 1)))));
}
verifyGetNaturalEndpoints(endpointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0]));
}
use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class LeaveAndBootstrapTest method testStateJumpToNormal.
@Test
public void testStateJumpToNormal() throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = RandomPartitioner.instance;
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
List<InetAddress> hosts = new ArrayList<InetAddress>();
List<UUID> hostIds = new ArrayList<UUID>();
// create a ring or 5 nodes
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);
// node 2 leaves
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(endpointTokens.get(2))));
assertTrue(tmd.isLeaving(hosts.get(2)));
assertEquals(endpointTokens.get(2), tmd.getToken(hosts.get(2)));
// back to normal
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(2))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(2))));
assertTrue(tmd.getSizeOfLeavingEndpoints() == 0);
assertEquals(keyTokens.get(2), tmd.getToken(hosts.get(2)));
// node 3 goes through leave and left and then jumps to normal at its new token
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(2))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.left(Collections.singleton(keyTokens.get(2)), Gossiper.computeExpireTime()));
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(4))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(4))));
assertTrue(tmd.getBootstrapTokens().isEmpty());
assertTrue(tmd.getSizeOfLeavingEndpoints() == 0);
assertEquals(keyTokens.get(4), tmd.getToken(hosts.get(2)));
}
use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class RepairSessionTest method testConviction.
@Test
public void testConviction() throws Exception {
InetAddress remote = InetAddress.getByName("127.0.0.2");
Gossiper.instance.initializeNodeUnsafe(remote, UUID.randomUUID(), 1);
// Set up RepairSession
UUID parentSessionId = UUIDGen.getTimeUUID();
UUID sessionId = UUID.randomUUID();
IPartitioner p = Murmur3Partitioner.instance;
Range<Token> repairRange = new Range<>(p.getToken(ByteBufferUtil.bytes(0)), p.getToken(ByteBufferUtil.bytes(100)));
Set<InetAddress> endpoints = Sets.newHashSet(remote);
RepairSession session = new RepairSession(parentSessionId, sessionId, Arrays.asList(repairRange), "Keyspace1", RepairParallelism.SEQUENTIAL, endpoints, ActiveRepairService.UNREPAIRED_SSTABLE, false, false, "Standard1");
// perform convict
session.convict(remote, Double.MAX_VALUE);
// RepairSession should throw ExecutorException with the cause of IOException when getting its value
try {
session.get();
fail();
} catch (ExecutionException ex) {
assertEquals(IOException.class, ex.getCause().getClass());
}
}
use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.
the class LeaveAndBootstrapTest method testStateJumpToLeaving.
@Test
public void testStateJumpToLeaving() throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = RandomPartitioner.instance;
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
List<InetAddress> hosts = new ArrayList<InetAddress>();
List<UUID> hostIds = new ArrayList<UUID>();
// create a ring or 5 nodes
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);
// node 2 leaves with _different_ token
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(0))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(0))));
assertEquals(keyTokens.get(0), tmd.getToken(hosts.get(2)));
assertTrue(tmd.isLeaving(hosts.get(2)));
assertNull(tmd.getEndpoint(endpointTokens.get(2)));
// go to boostrap
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));
assertFalse(tmd.isLeaving(hosts.get(2)));
assertEquals(1, tmd.getBootstrapTokens().size());
assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(1)));
// jump to leaving again
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(1))));
assertEquals(hosts.get(2), tmd.getEndpoint(keyTokens.get(1)));
assertTrue(tmd.isLeaving(hosts.get(2)));
assertTrue(tmd.getBootstrapTokens().isEmpty());
// go to state left
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));
assertFalse(tmd.isMember(hosts.get(2)));
assertFalse(tmd.isLeaving(hosts.get(2)));
}
Aggregations