You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ee...@apache.org on 2010/07/31 17:42:28 UTC
svn commit: r981069 [2/2] - in /cassandra/trunk: conf/ interface/
src/java/org/apache/cassandra/avro/ src/java/org/apache/cassandra/client/
src/java/org/apache/cassandra/config/
src/java/org/apache/cassandra/db/migration/ src/java/org/apache/cassandra/...
Modified: cassandra/trunk/test/unit/org/apache/cassandra/locator/ReplicationStrategyEndpointCacheTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/locator/ReplicationStrategyEndpointCacheTest.java?rev=981069&r1=981068&r2=981069&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/locator/ReplicationStrategyEndpointCacheTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/locator/ReplicationStrategyEndpointCacheTest.java Sat Jul 31 15:42:27 2010
@@ -21,10 +21,9 @@ package org.apache.cassandra.locator;
import java.lang.reflect.Constructor;
import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
+import org.apache.cassandra.service.StorageService;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
@@ -39,12 +38,12 @@ public class ReplicationStrategyEndpoint
private Token searchToken;
private AbstractReplicationStrategy strategy;
- public void setup(Class stratClass) throws Exception
+ public void setup(Class stratClass, Map<String, String> strategyOptions) throws Exception
{
tmd = new TokenMetadata();
searchToken = new BigIntegerToken(String.valueOf(15));
- Constructor constructor = stratClass.getConstructor(TokenMetadata.class, IEndpointSnitch.class);
- strategy = (AbstractReplicationStrategy) constructor.newInstance(tmd, new PropertyFileSnitch());
+
+ strategy = getStrategyWithNewTokenMetadata(StorageService.instance.getReplicationStrategy("Keyspace3"), 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"));
@@ -59,73 +58,73 @@ public class ReplicationStrategyEndpoint
@Test
public void testEndpointsWereCached() throws Exception
{
- runEndpointsWereCachedTest(FakeRackUnawareStrategy.class);
- runEndpointsWereCachedTest(FakeRackAwareStrategy.class);
- runEndpointsWereCachedTest(FakeDatacenterShardStrategy.class);
+ runEndpointsWereCachedTest(FakeRackUnawareStrategy.class, null);
+ runEndpointsWereCachedTest(FakeRackAwareStrategy.class, null);
+ runEndpointsWereCachedTest(FakeDatacenterShardStrategy.class, new HashMap<String, String>());
}
- public void runEndpointsWereCachedTest(Class stratClass) throws Exception
+ public void runEndpointsWereCachedTest(Class stratClass, Map<String, String> configOptions) throws Exception
{
- setup(stratClass);
- assert strategy.getNaturalEndpoints(searchToken, "Keyspace3").equals(strategy.getNaturalEndpoints(searchToken, "Keyspace3"));
+ setup(stratClass, configOptions);
+ assert strategy.getNaturalEndpoints(searchToken).equals(strategy.getNaturalEndpoints(searchToken));
}
@Test
public void testCacheRespectsTokenChanges() throws Exception
{
- runCacheRespectsTokenChangesTest(RackUnawareStrategy.class);
- runCacheRespectsTokenChangesTest(RackAwareStrategy.class);
- runCacheRespectsTokenChangesTest(DatacenterShardStrategy.class);
+ runCacheRespectsTokenChangesTest(RackUnawareStrategy.class, null);
+ runCacheRespectsTokenChangesTest(RackAwareStrategy.class, null);
+ runCacheRespectsTokenChangesTest(DatacenterShardStrategy.class, new HashMap<String, String>());
}
- public void runCacheRespectsTokenChangesTest(Class stratClass) throws Exception
+ public void runCacheRespectsTokenChangesTest(Class stratClass, Map<String, String> configOptions) throws Exception
{
- setup(stratClass);
+ setup(stratClass, configOptions);
ArrayList<InetAddress> initial;
ArrayList<InetAddress> endpoints;
- endpoints = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
// test token addition, in DC2 before existing token
- initial = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ initial = strategy.getNaturalEndpoints(searchToken);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(35)), InetAddress.getByName("127.0.0.5"));
- endpoints = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
assert !endpoints.equals(initial);
// test token removal, newly created token
- initial = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ initial = strategy.getNaturalEndpoints(searchToken);
tmd.removeEndpoint(InetAddress.getByName("127.0.0.5"));
- endpoints = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
assert !endpoints.contains(InetAddress.getByName("127.0.0.5"));
assert !endpoints.equals(initial);
// test token change
- initial = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ initial = strategy.getNaturalEndpoints(searchToken);
//move .8 after search token but before other DC3
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(25)), InetAddress.getByName("127.0.0.8"));
- endpoints = strategy.getNaturalEndpoints(searchToken, "Keyspace3");
+ endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
- assert !endpoints.equals(initial);
+ assert !endpoints.equals(initial);
}
protected static class FakeRackUnawareStrategy extends RackUnawareStrategy
{
private boolean called = false;
- public FakeRackUnawareStrategy(TokenMetadata tokenMetadata, IEndpointSnitch snitch)
+ public FakeRackUnawareStrategy(String table, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> configOptions)
{
- super(tokenMetadata, snitch);
+ super(table, tokenMetadata, snitch, configOptions);
}
@Override
- public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata, String table)
+ public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata)
{
assert !called : "calculateNaturalEndpoints was already called, result should have been cached";
called = true;
- return super.calculateNaturalEndpoints(token, metadata, table);
+ return super.calculateNaturalEndpoints(token, metadata);
}
}
@@ -133,17 +132,17 @@ public class ReplicationStrategyEndpoint
{
private boolean called = false;
- public FakeRackAwareStrategy(TokenMetadata tokenMetadata, IEndpointSnitch snitch)
+ public FakeRackAwareStrategy(String table, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> configOptions)
{
- super(tokenMetadata, snitch);
+ super(table, tokenMetadata, snitch, configOptions);
}
@Override
- public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata, String table)
+ public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata)
{
assert !called : "calculateNaturalEndpoints was already called, result should have been cached";
called = true;
- return super.calculateNaturalEndpoints(token, metadata, table);
+ return super.calculateNaturalEndpoints(token, metadata);
}
}
@@ -151,17 +150,28 @@ public class ReplicationStrategyEndpoint
{
private boolean called = false;
- public FakeDatacenterShardStrategy(TokenMetadata tokenMetadata, IEndpointSnitch snitch) throws ConfigurationException
+ public FakeDatacenterShardStrategy(String table, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> configOptions) throws ConfigurationException
{
- super(tokenMetadata, snitch);
+ super(table, tokenMetadata, snitch, configOptions);
}
@Override
- public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata, String table)
+ public Set<InetAddress> calculateNaturalEndpoints(Token token, TokenMetadata metadata)
{
assert !called : "calculateNaturalEndpoints was already called, result should have been cached";
called = true;
- return super.calculateNaturalEndpoints(token, metadata, table);
+ return super.calculateNaturalEndpoints(token, metadata);
}
}
+
+ private AbstractReplicationStrategy getStrategyWithNewTokenMetadata(AbstractReplicationStrategy strategy, TokenMetadata newTmd) throws ConfigurationException
+ {
+ return AbstractReplicationStrategy.createReplicationStrategy(
+ strategy.table,
+ strategy.getClass().getName(),
+ newTmd,
+ strategy.snitch,
+ strategy.configOptions);
+ }
+
}
Modified: cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java?rev=981069&r1=981068&r2=981069&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java Sat Jul 31 15:42:27 2010
@@ -188,9 +188,9 @@ public class AntiEntropyServiceTest exte
addTokens(1 + (2 * DatabaseDescriptor.getReplicationFactor(tablename)));
AbstractReplicationStrategy ars = StorageService.instance.getReplicationStrategy(tablename);
Set<InetAddress> expected = new HashSet<InetAddress>();
- for (Range replicaRange : ars.getAddressRanges(tablename).get(FBUtilities.getLocalAddress()))
+ for (Range replicaRange : ars.getAddressRanges().get(FBUtilities.getLocalAddress()))
{
- expected.addAll(ars.getRangeAddresses(tmd, tablename).get(replicaRange));
+ expected.addAll(ars.getRangeAddresses(tmd).get(replicaRange));
}
expected.remove(FBUtilities.getLocalAddress());
assertEquals(expected, AntiEntropyService.getNeighbors(tablename));
Modified: cassandra/trunk/test/unit/org/apache/cassandra/service/MoveTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/service/MoveTest.java?rev=981069&r1=981068&r2=981069&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/service/MoveTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/service/MoveTest.java Sat Jul 31 15:42:27 2010
@@ -23,6 +23,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
+import org.apache.cassandra.config.ConfigurationException;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -36,7 +37,6 @@ import org.apache.cassandra.locator.Abst
import org.apache.cassandra.locator.RackUnawareStrategy;
import org.apache.cassandra.locator.SimpleSnitch;
import org.apache.cassandra.locator.TokenMetadata;
-import org.apache.cassandra.utils.Pair;
public class MoveTest extends CleanupHelper
{
@@ -63,10 +63,8 @@ public class MoveTest extends CleanupHel
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategies = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -74,52 +72,53 @@ public class MoveTest extends CleanupHel
createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, RING_SIZE);
- final Map<Pair<String, Token>, List<InetAddress>> expectedEndpoints = new HashMap<Pair<String, Token>, List<InetAddress>>();
+ Map<Token, List<InetAddress>> expectedEndpoints = new HashMap<Token, List<InetAddress>>();
for (String table : DatabaseDescriptor.getNonSystemTables())
{
for (Token token : keyTokens)
{
List<InetAddress> endpoints = new ArrayList<InetAddress>();
- Pair<String, Token> key = new Pair<String, Token>(table, token);
Iterator<Token> tokenIter = TokenMetadata.ringIterator(tmd.sortedTokens(), token);
while (tokenIter.hasNext())
{
endpoints.add(tmd.getEndpoint(tokenIter.next()));
}
- expectedEndpoints.put(key, endpoints);
+ expectedEndpoints.put(token, endpoints);
}
}
// Third node leaves
- ss.onChange(hosts.get(LEAVING_NODE), StorageService.MOVE_STATE, new ApplicationState(StorageService.STATE_LEAVING + StorageService.Delimiter + partitioner.getTokenFactory().toString(endpointTokens.get(LEAVING_NODE))));
+ ss.onChange(hosts.get(LEAVING_NODE),
+ StorageService.MOVE_STATE,
+ new ApplicationState(StorageService.STATE_LEAVING + StorageService.Delimiter + partitioner.getTokenFactory().toString(endpointTokens.get(LEAVING_NODE))));
assertTrue(tmd.isLeaving(hosts.get(LEAVING_NODE)));
+ AbstractReplicationStrategy strategy;
for (String table : DatabaseDescriptor.getNonSystemTables())
{
+ strategy = getStrategy(table, tmd);
for (Token token : keyTokens)
{
- Pair<String, Token> key = new Pair<String, Token>(table, token);
int replicationFactor = DatabaseDescriptor.getReplicationFactor(table);
- HashSet<InetAddress> actual = new HashSet<InetAddress>(tmd.getWriteEndpoints(token, table, testStrategy.calculateNaturalEndpoints(token, tmd, table)));
+ HashSet<InetAddress> actual = new HashSet<InetAddress>(tmd.getWriteEndpoints(token, table, strategy.calculateNaturalEndpoints(token, tmd)));
HashSet<InetAddress> expected = new HashSet<InetAddress>();
for (int i = 0; i < replicationFactor; i++)
{
- expected.add(expectedEndpoints.get(key).get(i));
+ expected.add(expectedEndpoints.get(token).get(i));
}
// if the leaving node is in the endpoint list,
// then we should expect it plus one extra for when it's gone
if (expected.contains(hosts.get(LEAVING_NODE)))
- expected.add(expectedEndpoints.get(key).get(replicationFactor));
+ expected.add(expectedEndpoints.get(token).get(replicationFactor));
assertEquals("mismatched endpoint sets", expected, actual);
}
}
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategies);
}
/**
@@ -127,17 +126,15 @@ public class MoveTest extends CleanupHel
* simultaneously
*/
@Test
- public void testSimultaneousMove() throws UnknownHostException
+ public void testSimultaneousMove() throws UnknownHostException, ConfigurationException
{
StorageService ss = StorageService.instance;
final int RING_SIZE = 10;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategy = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -150,7 +147,7 @@ public class MoveTest extends CleanupHel
final int[] LEAVING = new int[] {6, 8, 9};
for (int leaving : LEAVING)
ss.onChange(hosts.get(leaving), StorageService.MOVE_STATE, new ApplicationState(StorageService.STATE_LEAVING + StorageService.Delimiter + partitioner.getTokenFactory().toString(endpointTokens.get(leaving))));
-
+
// boot two new nodes with keyTokens.get(5) and keyTokens.get(7)
InetAddress boot1 = InetAddress.getByName("127.0.1.1");
ss.onChange(boot1, StorageService.MOVE_STATE, new ApplicationState(StorageService.STATE_BOOTSTRAPPING + StorageService.Delimiter + partitioner.getTokenFactory().toString(keyTokens.get(5))));
@@ -160,7 +157,11 @@ public class MoveTest extends CleanupHel
Collection<InetAddress> endpoints = null;
/* don't require test update every time a new keyspace is added to test/conf/cassandra.yaml */
- List<String> tables = Arrays.asList("Keyspace1", "Keyspace2", "Keyspace3", "Keyspace4");
+ Map<String, AbstractReplicationStrategy> tableStrategyMap = new HashMap<String, AbstractReplicationStrategy>();
+ for (int i=1; i<=4; i++)
+ {
+ tableStrategyMap.put("Keyspace" + i, getStrategy("Keyspace" + i, tmd));
+ }
// pre-calculate the results.
Map<String, Multimap<Token, InetAddress>> expectedEndpoints = new HashMap<String, Multimap<Token, InetAddress>>();
@@ -209,11 +210,14 @@ public class MoveTest extends CleanupHel
expectedEndpoints.get("Keyspace4").putAll(new BigIntegerToken("85"), makeAddrs("127.0.0.10", "127.0.0.1", "127.0.0.2", "127.0.0.3"));
expectedEndpoints.get("Keyspace4").putAll(new BigIntegerToken("95"), makeAddrs("127.0.0.1", "127.0.0.2", "127.0.0.3"));
- for (String table : tables)
+ for (Map.Entry<String, AbstractReplicationStrategy> tableStrategy : tableStrategyMap.entrySet())
{
+ String table = tableStrategy.getKey();
+ AbstractReplicationStrategy strategy = tableStrategy.getValue();
+
for (int i = 0; i < keyTokens.size(); i++)
{
- endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, testStrategy.getNaturalEndpoints(keyTokens.get(i), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, strategy.getNaturalEndpoints(keyTokens.get(i)));
assertTrue(expectedEndpoints.get(table).get(keyTokens.get(i)).size() == endpoints.size());
assertTrue(expectedEndpoints.get(table).get(keyTokens.get(i)).containsAll(endpoints));
}
@@ -224,7 +228,7 @@ public class MoveTest extends CleanupHel
// tokens 5, 15 and 25 should go three nodes
for (int i=0; i<3; ++i)
{
- endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, testStrategy.getNaturalEndpoints(keyTokens.get(i), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, strategy.getNaturalEndpoints(keyTokens.get(i)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(i+1)));
assertTrue(endpoints.contains(hosts.get(i+2)));
@@ -232,7 +236,7 @@ public class MoveTest extends CleanupHel
}
// token 35 should go to nodes 4, 5, 6, 7 and boot1
- endpoints = tmd.getWriteEndpoints(keyTokens.get(3), table, testStrategy.getNaturalEndpoints(keyTokens.get(3), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(3), table, strategy.getNaturalEndpoints(keyTokens.get(3)));
assertTrue(endpoints.size() == 5);
assertTrue(endpoints.contains(hosts.get(4)));
assertTrue(endpoints.contains(hosts.get(5)));
@@ -241,7 +245,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(boot1));
// token 45 should go to nodes 5, 6, 7, 0, boot1 and boot2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(4), table, testStrategy.getNaturalEndpoints(keyTokens.get(4), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(4), table, strategy.getNaturalEndpoints(keyTokens.get(4)));
assertTrue(endpoints.size() == 6);
assertTrue(endpoints.contains(hosts.get(5)));
assertTrue(endpoints.contains(hosts.get(6)));
@@ -251,7 +255,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(boot2));
// token 55 should go to nodes 6, 7, 8, 0, 1, boot1 and boot2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(5), table, testStrategy.getNaturalEndpoints(keyTokens.get(5), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(5), table, strategy.getNaturalEndpoints(keyTokens.get(5)));
assertTrue(endpoints.size() == 7);
assertTrue(endpoints.contains(hosts.get(6)));
assertTrue(endpoints.contains(hosts.get(7)));
@@ -262,7 +266,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(boot2));
// token 65 should go to nodes 7, 8, 9, 0, 1 and boot2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(6), table, testStrategy.getNaturalEndpoints(keyTokens.get(6), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(6), table, strategy.getNaturalEndpoints(keyTokens.get(6)));
assertTrue(endpoints.size() == 6);
assertTrue(endpoints.contains(hosts.get(7)));
assertTrue(endpoints.contains(hosts.get(8)));
@@ -272,7 +276,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(boot2));
// token 75 should to go nodes 8, 9, 0, 1, 2 and boot2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(7), table, testStrategy.getNaturalEndpoints(keyTokens.get(7), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(7), table, strategy.getNaturalEndpoints(keyTokens.get(7)));
assertTrue(endpoints.size() == 6);
assertTrue(endpoints.contains(hosts.get(8)));
assertTrue(endpoints.contains(hosts.get(9)));
@@ -282,7 +286,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(boot2));
// token 85 should go to nodes 9, 0, 1 and 2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(8), table, testStrategy.getNaturalEndpoints(keyTokens.get(8), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(8), table, strategy.getNaturalEndpoints(keyTokens.get(8)));
assertTrue(endpoints.size() == 4);
assertTrue(endpoints.contains(hosts.get(9)));
assertTrue(endpoints.contains(hosts.get(0)));
@@ -290,7 +294,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(hosts.get(2)));
// token 95 should go to nodes 0, 1 and 2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(9), table, testStrategy.getNaturalEndpoints(keyTokens.get(9), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(9), table, strategy.getNaturalEndpoints(keyTokens.get(9)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(hosts.get(1)));
@@ -324,11 +328,14 @@ public class MoveTest extends CleanupHel
expectedEndpoints.get("Keyspace4").get(new BigIntegerToken("75")).removeAll(makeAddrs("127.0.0.10"));
expectedEndpoints.get("Keyspace4").get(new BigIntegerToken("85")).removeAll(makeAddrs("127.0.0.10"));
- for (String table : tables)
+ for (Map.Entry<String, AbstractReplicationStrategy> tableStrategy : tableStrategyMap.entrySet())
{
+ String table = tableStrategy.getKey();
+ AbstractReplicationStrategy strategy = tableStrategy.getValue();
+
for (int i = 0; i < keyTokens.size(); i++)
{
- endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, testStrategy.getNaturalEndpoints(keyTokens.get(i), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, strategy.getNaturalEndpoints(keyTokens.get(i)));
assertTrue(expectedEndpoints.get(table).get(keyTokens.get(i)).size() == endpoints.size());
assertTrue(expectedEndpoints.get(table).get(keyTokens.get(i)).containsAll(endpoints));
}
@@ -339,7 +346,7 @@ public class MoveTest extends CleanupHel
// tokens 5, 15 and 25 should go three nodes
for (int i=0; i<3; ++i)
{
- endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, testStrategy.getNaturalEndpoints(keyTokens.get(i), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, strategy.getNaturalEndpoints(keyTokens.get(i)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(i+1)));
assertTrue(endpoints.contains(hosts.get(i+2)));
@@ -347,21 +354,21 @@ public class MoveTest extends CleanupHel
}
// token 35 goes to nodes 4, 5 and boot1
- endpoints = tmd.getWriteEndpoints(keyTokens.get(3), table, testStrategy.getNaturalEndpoints(keyTokens.get(3), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(3), table, strategy.getNaturalEndpoints(keyTokens.get(3)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(4)));
assertTrue(endpoints.contains(hosts.get(5)));
assertTrue(endpoints.contains(boot1));
// token 45 goes to nodes 5, boot1 and node7
- endpoints = tmd.getWriteEndpoints(keyTokens.get(4), table, testStrategy.getNaturalEndpoints(keyTokens.get(4), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(4), table, strategy.getNaturalEndpoints(keyTokens.get(4)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(5)));
assertTrue(endpoints.contains(boot1));
assertTrue(endpoints.contains(hosts.get(7)));
// token 55 goes to boot1, 7, boot2, 8 and 0
- endpoints = tmd.getWriteEndpoints(keyTokens.get(5), table, testStrategy.getNaturalEndpoints(keyTokens.get(5), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(5), table, strategy.getNaturalEndpoints(keyTokens.get(5)));
assertTrue(endpoints.size() == 5);
assertTrue(endpoints.contains(boot1));
assertTrue(endpoints.contains(hosts.get(7)));
@@ -370,7 +377,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(hosts.get(0)));
// token 65 goes to nodes 7, boot2, 8, 0 and 1
- endpoints = tmd.getWriteEndpoints(keyTokens.get(6), table, testStrategy.getNaturalEndpoints(keyTokens.get(6), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(6), table, strategy.getNaturalEndpoints(keyTokens.get(6)));
assertTrue(endpoints.size() == 5);
assertTrue(endpoints.contains(hosts.get(7)));
assertTrue(endpoints.contains(boot2));
@@ -379,7 +386,7 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(hosts.get(1)));
// token 75 goes to nodes boot2, 8, 0, 1 and 2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(7), table, testStrategy.getNaturalEndpoints(keyTokens.get(7), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(7), table, strategy.getNaturalEndpoints(keyTokens.get(7)));
assertTrue(endpoints.size() == 5);
assertTrue(endpoints.contains(boot2));
assertTrue(endpoints.contains(hosts.get(8)));
@@ -388,14 +395,14 @@ public class MoveTest extends CleanupHel
assertTrue(endpoints.contains(hosts.get(2)));
// token 85 goes to nodes 0, 1 and 2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(8), table, testStrategy.getNaturalEndpoints(keyTokens.get(8), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(8), table, strategy.getNaturalEndpoints(keyTokens.get(8)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(hosts.get(1)));
assertTrue(endpoints.contains(hosts.get(2)));
// token 95 goes to nodes 0, 1 and 2
- endpoints = tmd.getWriteEndpoints(keyTokens.get(9), table, testStrategy.getNaturalEndpoints(keyTokens.get(9), table));
+ endpoints = tmd.getWriteEndpoints(keyTokens.get(9), table, strategy.getNaturalEndpoints(keyTokens.get(9)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(hosts.get(1)));
@@ -403,7 +410,6 @@ public class MoveTest extends CleanupHel
}
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategy);
}
@Test
@@ -413,10 +419,8 @@ public class MoveTest extends CleanupHel
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategy = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -472,7 +476,6 @@ public class MoveTest extends CleanupHel
assertTrue(tmd.getBootstrapTokens().isEmpty());
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategy);
}
@Test
@@ -482,10 +485,8 @@ public class MoveTest extends CleanupHel
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategy = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -516,7 +517,6 @@ public class MoveTest extends CleanupHel
assertTrue(tmd.getToken(hosts.get(2)).equals(keyTokens.get(4)));
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategy);
}
@Test
@@ -526,10 +526,8 @@ public class MoveTest extends CleanupHel
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategy = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -566,7 +564,6 @@ public class MoveTest extends CleanupHel
assertFalse(tmd.isLeaving(hosts.get(2)));
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategy);
}
@Test
@@ -576,10 +573,8 @@ public class MoveTest extends CleanupHel
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
- AbstractReplicationStrategy testStrategy = new RackUnawareStrategy(tmd, new SimpleSnitch());
IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
- Map<String, AbstractReplicationStrategy> oldStrategy = ss.setReplicationStrategyUnsafe(createReplacements(testStrategy));
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
@@ -608,7 +603,6 @@ public class MoveTest extends CleanupHel
assertFalse(tmd.isLeaving(hosts.get(2)));
ss.setPartitionerUnsafe(oldPartitioner);
- ss.setReplicationStrategyUnsafe(oldStrategy);
}
/**
@@ -643,4 +637,15 @@ public class MoveTest extends CleanupHel
addrs.add(InetAddress.getByName(host));
return addrs;
}
+
+ private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
+ {
+ return AbstractReplicationStrategy.createReplicationStrategy(
+ table,
+ "org.apache.cassandra.locator.RackUnawareStrategy",
+ tmd,
+ new SimpleSnitch(),
+ null);
+ }
+
}