diff --git a/src/java/voldemort/tools/PartitionAnalysisCLI.java b/src/java/voldemort/tools/PartitionAnalysisCLI.java index 89e80634b6..ba1b2e89ab 100644 --- a/src/java/voldemort/tools/PartitionAnalysisCLI.java +++ b/src/java/voldemort/tools/PartitionAnalysisCLI.java @@ -29,7 +29,6 @@ import voldemort.cluster.Cluster; import voldemort.store.StoreDefinition; -import voldemort.utils.ClusterInstance; import voldemort.utils.CmdUtils; import voldemort.utils.Utils; import voldemort.xml.ClusterMapper; @@ -109,7 +108,7 @@ public static void main(String[] args) throws Exception { Cluster currentCluster = new ClusterMapper().readCluster(new File(clusterXML)); List storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXML)); - PartitionBalance partitionBalance = new ClusterInstance(currentCluster, storeDefs).getPartitionBalance(); + PartitionBalance partitionBalance = new PartitionBalance(currentCluster, storeDefs); System.out.println(partitionBalance); } diff --git a/src/java/voldemort/tools/Repartitioner.java b/src/java/voldemort/tools/Repartitioner.java index a19b1dd842..3b09d99080 100644 --- a/src/java/voldemort/tools/Repartitioner.java +++ b/src/java/voldemort/tools/Repartitioner.java @@ -28,7 +28,6 @@ import voldemort.cluster.Cluster; import voldemort.cluster.Node; import voldemort.store.StoreDefinition; -import voldemort.utils.ClusterInstance; import voldemort.utils.ClusterUtils; import voldemort.utils.Pair; import voldemort.utils.RebalanceUtils; @@ -157,7 +156,7 @@ public static Cluster repartition(final Cluster currentCluster, final int greedySwapMaxPartitionsPerNode, final int greedySwapMaxPartitionsPerZone, final int maxContiguousPartitionsPerZone) { - PartitionBalance partitionBalance = new ClusterInstance(currentCluster, currentStoreDefs).getPartitionBalance(); + PartitionBalance partitionBalance = new PartitionBalance(currentCluster, currentStoreDefs); RebalanceUtils.dumpAnalysisToFile(outputDir, RebalanceUtils.currentClusterFileName, partitionBalance); @@ -195,7 +194,7 @@ public static Cluster repartition(final Cluster currentCluster, RebalanceUtils.validateCurrentFinalCluster(currentCluster, nextCluster); System.out.println("-------------------------\n"); - partitionBalance = new ClusterInstance(nextCluster, targetStoreDefs).getPartitionBalance(); + partitionBalance = new PartitionBalance(nextCluster, targetStoreDefs); double currentUtility = partitionBalance.getUtility(); System.out.println("Optimization number " + attempt + ": " + currentUtility + " max/min ratio"); @@ -219,7 +218,7 @@ public static Cluster repartition(final Cluster currentCluster, System.out.println("\n=========================="); System.out.println("Final distribution"); - partitionBalance = new ClusterInstance(minCluster, targetStoreDefs).getPartitionBalance(); + partitionBalance = new PartitionBalance(minCluster, targetStoreDefs); System.out.println(partitionBalance); RebalanceUtils.dumpClusterToFile(outputDir, RebalanceUtils.finalClusterFileName, minCluster); @@ -631,16 +630,14 @@ public static Cluster randomShufflePartitions(final Cluster targetCluster, List zoneIds = new ArrayList(targetCluster.getZoneIds()); Cluster returnCluster = ClusterUtils.copyCluster(targetCluster); - double currentUtility = new ClusterInstance(returnCluster, storeDefs).getPartitionBalance() - .getUtility(); + double currentUtility = new PartitionBalance(returnCluster, storeDefs).getUtility(); int successes = 0; for(int i = 0; i < randomSwapAttempts; i++) { Collections.shuffle(zoneIds, new Random(System.currentTimeMillis())); for(Integer zoneId: zoneIds) { Cluster shuffleResults = swapRandomPartitionsWithinZone(returnCluster, zoneId); - double nextUtility = new ClusterInstance(shuffleResults, storeDefs).getPartitionBalance() - .getUtility(); + double nextUtility = new PartitionBalance(shuffleResults, storeDefs).getUtility(); if(nextUtility < currentUtility) { System.out.println("Swap improved max-min ratio: " + currentUtility + " -> " + nextUtility + " (improvement " + successes @@ -681,8 +678,7 @@ public static Cluster swapGreedyRandomPartitions(final Cluster targetCluster, System.out.println("GreedyRandom : nodeIds:" + nodeIds); Cluster returnCluster = ClusterUtils.copyCluster(targetCluster); - double currentUtility = new ClusterInstance(returnCluster, storeDefs).getPartitionBalance() - .getUtility(); + double currentUtility = new PartitionBalance(returnCluster, storeDefs).getUtility(); int nodeIdA = -1; int nodeIdB = -1; int partitionIdA = -1; @@ -719,8 +715,7 @@ public static Cluster swapGreedyRandomPartitions(final Cluster targetCluster, partitionIdEh, nodeIdBee, partitionIdBee); - double swapUtility = new ClusterInstance(swapResult, storeDefs).getPartitionBalance() - .getUtility(); + double swapUtility = new PartitionBalance(swapResult, storeDefs).getUtility(); if(swapUtility < currentUtility) { currentUtility = swapUtility; System.out.println(" -> " + currentUtility); @@ -786,8 +781,7 @@ public static Cluster greedyShufflePartitions(final Cluster targetCluster, return returnCluster; } - double currentUtility = new ClusterInstance(returnCluster, storeDefs).getPartitionBalance() - .getUtility(); + double currentUtility = new PartitionBalance(returnCluster, storeDefs).getUtility(); for(int i = 0; i < greedyAttempts; i++) { Collections.shuffle(zoneIds, new Random(System.currentTimeMillis())); @@ -807,8 +801,7 @@ public static Cluster greedyShufflePartitions(final Cluster targetCluster, greedySwapMaxPartitionsPerNode, greedySwapMaxPartitionsPerZone, storeDefs); - double nextUtility = new ClusterInstance(shuffleResults, storeDefs).getPartitionBalance() - .getUtility(); + double nextUtility = new PartitionBalance(shuffleResults, storeDefs).getUtility(); if(nextUtility == currentUtility) { System.out.println("Not improving for zone: " + zoneId); diff --git a/src/java/voldemort/utils/ClusterInstance.java b/src/java/voldemort/utils/ClusterInstance.java deleted file mode 100644 index d3eef1a09b..0000000000 --- a/src/java/voldemort/utils/ClusterInstance.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013 LinkedIn, Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package voldemort.utils; - -import java.util.List; - -import voldemort.cluster.Cluster; -import voldemort.store.StoreDefinition; -import voldemort.tools.PartitionBalance; - -/** - * This class wraps up a Cluster object and a List. The methods - * are effectively helper or util style methods for analyzing partitions and so - * on which are a function of both Cluster and List. - */ -public class ClusterInstance { - - // TODO: (refactor) Improve upon the name "ClusterInstance". Object-oriented - // meaning of 'instance' is too easily confused with system notion of an - // "instance of a cluster" (the intended usage in this class name). - - private final Cluster cluster; - private final List storeDefs; - - public ClusterInstance(Cluster cluster, List storeDefs) { - this.cluster = cluster; - this.storeDefs = storeDefs; - } - - public Cluster getCluster() { - return cluster; - } - - public List getStoreDefs() { - return storeDefs; - } - - /** - * Outputs an analysis of how balanced the cluster is given the store - * definitions. The metric max/min ratio is used to describe balance. The - * max/min ratio is the ratio of largest number of store-partitions to - * smallest number of store-partitions). If the minimum number of - * store-partitions is zero, then the max/min ratio is set to max rather - * than to infinite. - * - * @return First element of pair is the max/min ratio. Second element of - * pair is a string that can be printed to dump all the gory details - * of the analysis. - */ - public PartitionBalance getPartitionBalance() { - - return new PartitionBalance(cluster, storeDefs); - } -} diff --git a/test/unit/voldemort/utils/ClusterInstanceTest.java b/test/common/voldemort/ClusterTestUtils.java similarity index 84% rename from test/unit/voldemort/utils/ClusterInstanceTest.java rename to test/common/voldemort/ClusterTestUtils.java index 3ab67cfa42..b565b0f8fc 100644 --- a/test/unit/voldemort/utils/ClusterInstanceTest.java +++ b/test/common/voldemort/ClusterTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 LinkedIn, Inc + * 2013 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -13,10 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ - -package voldemort.utils; - -import static org.junit.Assert.assertTrue; +package voldemort; import java.util.ArrayList; import java.util.Collections; @@ -24,10 +21,6 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Test; - -import voldemort.ServerTestUtils; -import voldemort.VoldemortException; import voldemort.client.RoutingTier; import voldemort.cluster.Cluster; import voldemort.cluster.Node; @@ -41,30 +34,7 @@ import com.google.common.collect.Lists; -/** - * This test focuses on constructing ClusterInstances and then invoking - * analyzeBalanceVerbose(). This method heavily exercises much of the - * partition/replicaType code paths. - * - * The positive test cases cover expected configurations: - *
    - *
  • 2 or 3 zones - *
  • 0 or 1 zones without partitions - *
  • one or more zones with new nodes ('new' meaning no partitions on that - * node) - *
- * - * The "negative test cases" cover: - *
    - *
  • Store definition mis-match with cluster in terms of number of zones. - *
  • Insufficient nodes in new zone to reach desired replication level. - *
- * - */ -public class ClusterInstanceTest { - - // TODO: Rename class/file to PartitionBalanceTest. Change tests to directly - // use PartitionBalance rather than go through ClusterInstance. +public class ClusterTestUtils { // TODO: Move these storeDefs and cluster helper test methods into // ClusterTestUtils. @@ -143,7 +113,7 @@ public static List getZZ322StoreDefs(String storageType) { */ public static List getZZStoreDefsInMemory() { List storeDefs = new LinkedList(); - storeDefs.addAll(getZZ111StoreDefs(InMemoryStorageConfiguration.TYPE_NAME)); + storeDefs.addAll(ClusterTestUtils.getZZ111StoreDefs(InMemoryStorageConfiguration.TYPE_NAME)); storeDefs.addAll(getZZ211StoreDefs(InMemoryStorageConfiguration.TYPE_NAME)); storeDefs.addAll(getZZ322StoreDefs(InMemoryStorageConfiguration.TYPE_NAME)); return storeDefs; @@ -151,7 +121,7 @@ public static List getZZStoreDefsInMemory() { public static List getZZStoreDefsBDB() { List storeDefs = new LinkedList(); - storeDefs.addAll(getZZ111StoreDefs(BdbStorageConfiguration.TYPE_NAME)); + storeDefs.addAll(ClusterTestUtils.getZZ111StoreDefs(BdbStorageConfiguration.TYPE_NAME)); storeDefs.addAll(getZZ211StoreDefs(BdbStorageConfiguration.TYPE_NAME)); storeDefs.addAll(getZZ322StoreDefs(BdbStorageConfiguration.TYPE_NAME)); return storeDefs; @@ -500,112 +470,4 @@ public static Cluster getZZClusterWithNonContiguousZoneIDsAndNonContiguousNodeID return new Cluster(cluster.getName(), nodeList, zones); } - @Test - public void testBasicThingsThatShouldWork() { - ClusterInstance ci; - - ci = new ClusterInstance(getZZCluster(), getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - - ci = new ClusterInstance(getZZZCluster(), getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } - - @Test - public void testEmptyZoneThingsThatShouldWork() { - ClusterInstance ci; - - ci = new ClusterInstance(getZECluster(), getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - - ci = new ClusterInstance(getZEZCluster(), getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - - ci = new ClusterInstance(getZEZClusterWithOnlyOneNodeInNewZone(), getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } - - @Test - public void testNewNodeThingsThatShouldWork() { - ClusterInstance ci; - - ci = new ClusterInstance(getZZClusterWithNN(), getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - - ci = new ClusterInstance(getZEZClusterWithXNN(), getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } - - @Test - public void testClusterStoreZoneCountMismatch() { - ClusterInstance ci; - boolean veCaught; - - veCaught = false; - try { - ci = new ClusterInstance(getZZCluster(), getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } catch(VoldemortException ve) { - veCaught = true; - } - assertTrue(veCaught); - - veCaught = false; - try { - ci = new ClusterInstance(getZZZCluster(), getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } catch(VoldemortException ve) { - veCaught = true; - } - assertTrue(veCaught); - } - - @Test - public void testClusterWithZoneThatCannotFullyReplicate() { - ClusterInstance ci; - - boolean veCaught = false; - try { - ci = new ClusterInstance(getZZZClusterWithOnlyOneNodeInNewZone(), - getZZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } catch(VoldemortException ve) { - veCaught = true; - } - assertTrue(veCaught); - } - - /** - * Confirm that zone Ids need not be contiguous. This tests for the ability - * to shrink zones. - */ - @Test - public void testNonContiguousZonesThatShouldWork() { - ClusterInstance ci; - - ci = new ClusterInstance(getZZClusterWithNonContiguousZoneIDsButContiguousNodeIDs(), - getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } - - // TODO: Fix handling of node Ids so that they do not need to be contiguous. - /** - * This should be a positive test. But, for now, is a negative test to - * confirm that we require nodeIds to be contiguous. This may become a - * problem if we ever shrink the number of zones. - */ - @Test - public void testNonContiguousZonesThatShouldWorkButDoNot() { - ClusterInstance ci; - - boolean veCaught = false; - try { - ci = new ClusterInstance(getZZClusterWithNonContiguousZoneIDsAndNonContiguousNodeIDs(), - getZZStoreDefsInMemory()); - ci.getPartitionBalance(); - } catch(VoldemortException ve) { - veCaught = true; - } - assertTrue(veCaught); - } } diff --git a/test/unit/voldemort/client/rebalance/RebalancePlanTest.java b/test/unit/voldemort/client/rebalance/RebalancePlanTest.java index 1b07000a2b..231bcdeb5b 100644 --- a/test/unit/voldemort/client/rebalance/RebalancePlanTest.java +++ b/test/unit/voldemort/client/rebalance/RebalancePlanTest.java @@ -23,9 +23,9 @@ import org.junit.BeforeClass; import org.junit.Test; +import voldemort.ClusterTestUtils; import voldemort.cluster.Cluster; import voldemort.store.StoreDefinition; -import voldemort.utils.ClusterInstanceTest; public class RebalancePlanTest { @@ -42,17 +42,17 @@ public class RebalancePlanTest { @BeforeClass public static void setup() { - zzCurrent = ClusterInstanceTest.getZZCluster(); - zzRebalance = ClusterInstanceTest.getZZClusterWithSwappedPartitions(); - zzClusterExpansion = ClusterInstanceTest.getZZClusterWithPP(); - zzStores = ClusterInstanceTest.getZZStoreDefsBDB(); + zzCurrent = ClusterTestUtils.getZZCluster(); + zzRebalance = ClusterTestUtils.getZZClusterWithSwappedPartitions(); + zzClusterExpansion = ClusterTestUtils.getZZClusterWithPP(); + zzStores = ClusterTestUtils.getZZStoreDefsBDB(); - zzzCurrent = ClusterInstanceTest.getZZZCluster(); + zzzCurrent = ClusterTestUtils.getZZZCluster(); - zzzRebalance = ClusterInstanceTest.getZZZClusterWithSwappedPartitions(); - zzzClusterExpansion = ClusterInstanceTest.getZZZClusterWithPPP(); - zzzZoneExpansion = ClusterInstanceTest.getZZEClusterXXP(); - zzzStores = ClusterInstanceTest.getZZZStoreDefsBDB(); + zzzRebalance = ClusterTestUtils.getZZZClusterWithSwappedPartitions(); + zzzClusterExpansion = ClusterTestUtils.getZZZClusterWithPPP(); + zzzZoneExpansion = ClusterTestUtils.getZZEClusterXXP(); + zzzStores = ClusterTestUtils.getZZZStoreDefsBDB(); } RebalancePlan makePlan(Cluster cCluster, diff --git a/test/unit/voldemort/tools/PartitionBalanceTest.java b/test/unit/voldemort/tools/PartitionBalanceTest.java new file mode 100644 index 0000000000..ffe0085cdb --- /dev/null +++ b/test/unit/voldemort/tools/PartitionBalanceTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2013 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package voldemort.tools; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import voldemort.ClusterTestUtils; +import voldemort.VoldemortException; + +/** + * This test focuses on constructing PartitionBalances. This exercises all of + * the partition/replicaType code paths. + * + * The positive test cases cover expected configurations: + *
    + *
  • 2 or 3 zones + *
  • 0 or 1 zones without partitions + *
  • one or more zones with new nodes ('new' meaning no partitions on that + * node) + *
+ * + * The "negative test cases" cover: + *
    + *
  • Store definition mis-match with cluster in terms of number of zones. + *
  • Insufficient nodes in new zone to reach desired replication level. + *
+ * + */ +public class PartitionBalanceTest { + + @Test + public void testBasicThingsThatShouldWork() { + new PartitionBalance(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZStoreDefsInMemory()); + + new PartitionBalance(ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + } + + @Test + public void testEmptyZoneThingsThatShouldWork() { + new PartitionBalance(ClusterTestUtils.getZECluster(), + ClusterTestUtils.getZZStoreDefsInMemory()); + + new PartitionBalance(ClusterTestUtils.getZEZCluster(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + + new PartitionBalance(ClusterTestUtils.getZEZClusterWithOnlyOneNodeInNewZone(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + } + + @Test + public void testNewNodeThingsThatShouldWork() { + new PartitionBalance(ClusterTestUtils.getZZClusterWithNN(), + ClusterTestUtils.getZZStoreDefsInMemory()); + + new PartitionBalance(ClusterTestUtils.getZEZClusterWithXNN(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + } + + @Test + public void testClusterStoreZoneCountMismatch() { + boolean veCaught; + + veCaught = false; + try { + new PartitionBalance(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + } catch(VoldemortException ve) { + veCaught = true; + } + assertTrue(veCaught); + + veCaught = false; + try { + new PartitionBalance(ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZStoreDefsInMemory()); + } catch(VoldemortException ve) { + veCaught = true; + } + assertTrue(veCaught); + } + + @Test + public void testClusterWithZoneThatCannotFullyReplicate() { + boolean veCaught = false; + try { + new PartitionBalance(ClusterTestUtils.getZZZClusterWithOnlyOneNodeInNewZone(), + ClusterTestUtils.getZZZStoreDefsInMemory()); + } catch(VoldemortException ve) { + veCaught = true; + } + assertTrue(veCaught); + } + + /** + * Confirm that zone Ids need not be contiguous. This tests for the ability + * to shrink zones. + */ + @Test + public void testNonContiguousZonesThatShouldWork() { + new PartitionBalance(ClusterTestUtils.getZZClusterWithNonContiguousZoneIDsButContiguousNodeIDs(), + ClusterTestUtils.getZZStoreDefsInMemory()); + } + + // TODO: Fix handling of node Ids so that they do not need to be contiguous. + /** + * This should be a positive test. But, for now, is a negative test to + * confirm that we require nodeIds to be contiguous. This may become a + * problem if we ever shrink the number of zones. + */ + @Test + public void testNonContiguousZonesThatShouldWorkButDoNot() { + boolean veCaught = false; + try { + new PartitionBalance(ClusterTestUtils.getZZClusterWithNonContiguousZoneIDsAndNonContiguousNodeIDs(), + ClusterTestUtils.getZZStoreDefsInMemory()); + } catch(VoldemortException ve) { + veCaught = true; + } + assertTrue(veCaught); + } +} diff --git a/test/unit/voldemort/tools/RepartitionerTest.java b/test/unit/voldemort/tools/RepartitionerTest.java index 6c2d1e6e21..47c221e52e 100644 --- a/test/unit/voldemort/tools/RepartitionerTest.java +++ b/test/unit/voldemort/tools/RepartitionerTest.java @@ -25,9 +25,9 @@ import org.junit.Test; +import voldemort.ClusterTestUtils; import voldemort.cluster.Cluster; import voldemort.store.StoreDefinition; -import voldemort.utils.ClusterInstanceTest; import voldemort.utils.ClusterUtils; public class RepartitionerTest { @@ -363,8 +363,8 @@ public void verifyGreedySwapsImproveBalance(Cluster currentCluster, @Test public void testRebalance() { // Two zone cluster - Cluster currentCluster = ClusterInstanceTest.getZZCluster(); - List storeDefs = ClusterInstanceTest.getZZStoreDefsInMemory(); + Cluster currentCluster = ClusterTestUtils.getZZCluster(); + List storeDefs = ClusterTestUtils.getZZStoreDefsInMemory(); verifyBalanceZoneAndNode(currentCluster, storeDefs, currentCluster, storeDefs); verifyBalanceNodesNotZones(currentCluster, storeDefs, currentCluster, storeDefs); verifyRepartitionNoop(currentCluster, storeDefs, currentCluster, storeDefs); @@ -372,8 +372,8 @@ public void testRebalance() { verifyGreedySwapsImproveBalance(currentCluster, storeDefs); // Three zone cluster - currentCluster = ClusterInstanceTest.getZZZCluster(); - storeDefs = ClusterInstanceTest.getZZZStoreDefsInMemory(); + currentCluster = ClusterTestUtils.getZZZCluster(); + storeDefs = ClusterTestUtils.getZZZStoreDefsInMemory(); verifyBalanceZoneAndNode(currentCluster, storeDefs, currentCluster, storeDefs); verifyBalanceNodesNotZones(currentCluster, storeDefs, currentCluster, storeDefs); verifyRepartitionNoop(currentCluster, storeDefs, currentCluster, storeDefs); @@ -384,17 +384,17 @@ public void testRebalance() { @Test public void testClusterExpansion() { // Two zone cluster - Cluster currentCluster = ClusterInstanceTest.getZZCluster(); - Cluster targetCluster = ClusterInstanceTest.getZZClusterWithNN(); - List storeDefs = ClusterInstanceTest.getZZStoreDefsInMemory(); + Cluster currentCluster = ClusterTestUtils.getZZCluster(); + Cluster targetCluster = ClusterTestUtils.getZZClusterWithNN(); + List storeDefs = ClusterTestUtils.getZZStoreDefsInMemory(); verifyBalanceZoneAndNode(currentCluster, storeDefs, targetCluster, storeDefs); verifyBalanceNodesNotZones(currentCluster, storeDefs, targetCluster, storeDefs); verifyRepartitionNoop(currentCluster, storeDefs, targetCluster, storeDefs); // Three zone cluster - currentCluster = ClusterInstanceTest.getZZZCluster(); - targetCluster = ClusterInstanceTest.getZZZClusterWithNNN(); - storeDefs = ClusterInstanceTest.getZZZStoreDefsInMemory(); + currentCluster = ClusterTestUtils.getZZZCluster(); + targetCluster = ClusterTestUtils.getZZZClusterWithNNN(); + storeDefs = ClusterTestUtils.getZZZStoreDefsInMemory(); verifyBalanceZoneAndNode(currentCluster, storeDefs, targetCluster, storeDefs); verifyBalanceNodesNotZones(currentCluster, storeDefs, targetCluster, storeDefs); verifyRepartitionNoop(currentCluster, storeDefs, targetCluster, storeDefs); @@ -402,11 +402,11 @@ public void testClusterExpansion() { @Test public void testZoneExpansion() { - Cluster currentCluster = ClusterInstanceTest.getZZCluster(); - List currentStoreDefs = ClusterInstanceTest.getZZStoreDefsInMemory(); + Cluster currentCluster = ClusterTestUtils.getZZCluster(); + List currentStoreDefs = ClusterTestUtils.getZZStoreDefsInMemory(); - Cluster targetCluster = ClusterInstanceTest.getZZZClusterWithNNN(); - List targetStoreDefs = ClusterInstanceTest.getZZZStoreDefsInMemory(); + Cluster targetCluster = ClusterTestUtils.getZZZClusterWithNNN(); + List targetStoreDefs = ClusterTestUtils.getZZZStoreDefsInMemory(); verifyBalanceZoneAndNode(currentCluster, currentStoreDefs, targetCluster, targetStoreDefs); // verifyBalanceNodesNotZones does not make sense for zone expansion. @@ -478,13 +478,13 @@ public void decontigRepartition(Cluster currentCluster, List cu @Test public void testDeContig() { // Two zone cluster - Cluster currentCluster = ClusterInstanceTest.getZZCluster(); - List storeDefs = ClusterInstanceTest.getZZStoreDefsInMemory(); + Cluster currentCluster = ClusterTestUtils.getZZCluster(); + List storeDefs = ClusterTestUtils.getZZStoreDefsInMemory(); decontigRepartition(currentCluster, storeDefs); // Three zone cluster - currentCluster = ClusterInstanceTest.getZZZCluster(); - storeDefs = ClusterInstanceTest.getZZZStoreDefsInMemory(); + currentCluster = ClusterTestUtils.getZZZCluster(); + storeDefs = ClusterTestUtils.getZZZStoreDefsInMemory(); decontigRepartition(currentCluster, storeDefs); } diff --git a/test/unit/voldemort/utils/RebalanceUtilsTest.java b/test/unit/voldemort/utils/RebalanceUtilsTest.java index b4ff6fd579..d35c473f95 100644 --- a/test/unit/voldemort/utils/RebalanceUtilsTest.java +++ b/test/unit/voldemort/utils/RebalanceUtilsTest.java @@ -25,6 +25,7 @@ import org.junit.Test; +import voldemort.ClusterTestUtils; import voldemort.ServerTestUtils; import voldemort.VoldemortException; import voldemort.cluster.Cluster; @@ -117,43 +118,43 @@ public void doClusterTransformationAndVerification(Cluster currentC, @Test public void testClusterTransformationAndVerification() { // Two-zone cluster: no-op - doClusterTransformationAndVerification(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZCluster()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZCluster()); // Two-zone cluster: rebalance - doClusterTransformationAndVerification(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithSwappedPartitions()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithSwappedPartitions()); // Two-zone cluster: cluster expansion - doClusterTransformationAndVerification(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithNN(), - ClusterInstanceTest.getZZClusterWithPP()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithNN(), + ClusterTestUtils.getZZClusterWithPP()); // Three-zone cluster: no-op - doClusterTransformationAndVerification(ClusterInstanceTest.getZZZCluster(), - ClusterInstanceTest.getZZZCluster(), - ClusterInstanceTest.getZZZCluster()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZCluster()); // Three-zone cluster: rebalance - doClusterTransformationAndVerification(ClusterInstanceTest.getZZZCluster(), - ClusterInstanceTest.getZZZCluster(), - ClusterInstanceTest.getZZZClusterWithSwappedPartitions()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZClusterWithSwappedPartitions()); // Three-zone cluster: cluster expansion - doClusterTransformationAndVerification(ClusterInstanceTest.getZZZCluster(), - ClusterInstanceTest.getZZZClusterWithNNN(), - ClusterInstanceTest.getZZZClusterWithPPP()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZZCluster(), + ClusterTestUtils.getZZZClusterWithNNN(), + ClusterTestUtils.getZZZClusterWithPPP()); // TODO: Fix this test to pass. This test currently fails because the // method RebalanceUtils.getClusterWithNewNodes cannot handle a new zone // coming into existence between currentCluster & targetCluster. // Two- to Three-zone clusters: zone expansion /*- - doClusterTransformationAndVerification(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZECluster(), - ClusterInstanceTest.getZZEClusterXXP()); + doClusterTransformationAndVerification(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZECluster(), + ClusterTestUtils.getZZEClusterXXP()); */ } @@ -164,9 +165,9 @@ public void testClusterTransformationAndVerificationExceptions() { // Two-zone cluster: rebalance with extra partitions in target excepted = false; try { - doClusterTransformation(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithExtraPartitions(), - ClusterInstanceTest.getZZClusterWithSwappedPartitions()); + doClusterTransformation(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithExtraPartitions(), + ClusterTestUtils.getZZClusterWithSwappedPartitions()); } catch(VoldemortException ve) { excepted = true; } @@ -175,9 +176,9 @@ public void testClusterTransformationAndVerificationExceptions() { // Two-zone cluster: rebalance with extra partitions in final excepted = false; try { - doClusterTransformation(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithExtraPartitions()); + doClusterTransformation(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithExtraPartitions()); } catch(VoldemortException ve) { excepted = true; } @@ -186,9 +187,9 @@ public void testClusterTransformationAndVerificationExceptions() { // Two-zone cluster: node ids swapped in target excepted = false; try { - doClusterTransformation(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithNNWithSwappedNodeIds(), - ClusterInstanceTest.getZZClusterWithPP()); + doClusterTransformation(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithNNWithSwappedNodeIds(), + ClusterTestUtils.getZZClusterWithPP()); } catch(VoldemortException ve) { excepted = true; } @@ -198,9 +199,9 @@ public void testClusterTransformationAndVerificationExceptions() { // same as partitions being migrated among nodes. excepted = false; try { - doClusterTransformation(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithNN(), - ClusterInstanceTest.getZZClusterWithPPWithSwappedNodeIds()); + doClusterTransformation(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithNN(), + ClusterTestUtils.getZZClusterWithPPWithSwappedNodeIds()); } catch(VoldemortException ve) { excepted = true; } @@ -209,9 +210,9 @@ public void testClusterTransformationAndVerificationExceptions() { // Two-zone cluster: too many node ids in final excepted = false; try { - doClusterTransformation(ClusterInstanceTest.getZZCluster(), - ClusterInstanceTest.getZZClusterWithNN(), - ClusterInstanceTest.getZZClusterWithPPWithTooManyNodes()); + doClusterTransformation(ClusterTestUtils.getZZCluster(), + ClusterTestUtils.getZZClusterWithNN(), + ClusterTestUtils.getZZClusterWithPPWithTooManyNodes()); } catch(VoldemortException ve) { excepted = true; }