Skip to content

Commit

Permalink
Added unit tests for RebalancePlan, RebalanceBatchPlan, and AbstractZ…
Browse files Browse the repository at this point in the history
…onedRebalanceTest.

Added following rebalance test case coverage:
- RebalancePlanTest / RebalanceBatchPlanTest / AbstractZonedRebalanceTest
- no-op / shuffle / cluster expansion / zone expansion
- 2-zone / 3-zone

Also did some clean up of rebalance test utils and rebalance tests in general.
  • Loading branch information
jayjwylie committed Jun 20, 2013
1 parent 91c0b18 commit c228e5f
Show file tree
Hide file tree
Showing 10 changed files with 749 additions and 363 deletions.
Expand Up @@ -53,6 +53,8 @@
import voldemort.store.socket.SocketStoreFactory;
import voldemort.store.socket.clientrequest.ClientRequestExecutorPool;

// TODO: Drop this class (as well as all other ec2 tests) since the tests have
// not been run in over a year.
/**
*/
public class Ec2RebalanceTest extends AbstractNonZonedRebalanceTest {
Expand Down Expand Up @@ -128,7 +130,8 @@ public void ec2Cleanup() throws Exception {
}
}

@Override
// TODO: This is probably broken since it was removed from
// AbstractNonZonedRebalanceTest
protected Cluster updateCluster(Cluster template) {
List<Node> nodes = new ArrayList<Node>();
for(Map.Entry<Integer, String> entry: nodeIdsInv.entrySet()) {
Expand Down
227 changes: 203 additions & 24 deletions test/common/voldemort/ClusterTestUtils.java

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions test/common/voldemort/ServerTestUtils.java
Expand Up @@ -508,9 +508,11 @@ public static Cluster getLocalZonedCluster(int numberOfNodes,
*/
// TODO: Method should eventually accept a list of ZoneIds so that
// non-contig zone Ids can be tested.
/*-
public static Cluster getLocalZonedCluster(int numberOfZones,
int[][] nodeIdsPerZone,
int[][] partitionMap) {
if(numberOfZones < 1) {
throw new VoldemortException("The number of zones must be positive (" + numberOfZones
Expand Down Expand Up @@ -564,6 +566,65 @@ public static Cluster getLocalZonedCluster(int numberOfZones,
}
return new Cluster("cluster", nodes, zones);
}
*/

public static Cluster getLocalZonedCluster(int numberOfZones,
int[][] nodeIdsPerZone,
int[][] partitionMap,
int[] ports) {

if(numberOfZones < 1) {
throw new VoldemortException("The number of zones must be positive (" + numberOfZones
+ ")");
}
if(nodeIdsPerZone.length != numberOfZones) {
throw new VoldemortException("Mismatch between numberOfZones (" + numberOfZones
+ ") and size of nodesPerZone array ("
+ nodeIdsPerZone.length + ").");
}

int numNodes = 0;
for(int nodeIdsInZone[]: nodeIdsPerZone) {
numNodes += nodeIdsInZone.length;
}
if(partitionMap.length != numNodes) {
throw new VoldemortException("Mismatch between numNodes (" + numNodes
+ ") and size of partitionMap array (" + partitionMap
+ ").");
}

// Generate nodes
List<Node> nodes = new ArrayList<Node>();
int offset = 0;
for(int zoneId = 0; zoneId < numberOfZones; zoneId++) {
for(int nodeId: nodeIdsPerZone[zoneId]) {
List<Integer> partitions = new ArrayList<Integer>(partitionMap[nodeId].length);
for(int p: partitionMap[offset]) {
partitions.add(p);
}
nodes.add(new Node(nodeId,
"localhost",
ports[nodeId * 3],
ports[nodeId * 3 + 1],
ports[nodeId * 3 + 2],
zoneId,
partitions));
offset++;
}
}

List<Zone> zones = Lists.newArrayList();
for(int i = 0; i < numberOfZones; i++) {
LinkedList<Integer> proximityList = Lists.newLinkedList();
int zoneId = i + 1;
for(int j = 0; j < numberOfZones; j++) {
proximityList.add(zoneId % numberOfZones);
zoneId++;
}
zones.add(new Zone(i, proximityList));
}
return new Cluster("cluster", nodes, zones);
}

public static Node getLocalNode(int nodeId, List<Integer> partitions) {
int[] ports = findFreePorts(3);
Expand Down
275 changes: 92 additions & 183 deletions test/unit/voldemort/client/rebalance/AbstractNonZonedRebalanceTest.java

Large diffs are not rendered by default.

Expand Up @@ -107,10 +107,6 @@ protected Cluster startServers(Cluster cluster,
return cluster;
}

protected Cluster updateCluster(Cluster template) {
return template;
}

protected Store<ByteArray, byte[], byte[]> getSocketStore(String storeName,
String host,
int port) {
Expand Down

0 comments on commit c228e5f

Please sign in to comment.