http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalanceNonRack.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalanceNonRack.java b/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalanceNonRack.java deleted file mode 100644 index 9672483..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalanceNonRack.java +++ /dev/null @@ -1,216 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -import org.apache.helix.ConfigAccessor; -import org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy; -import org.apache.helix.integration.manager.ClusterControllerManager; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.model.BuiltInStateModelDefinitions; -import org.apache.helix.model.ClusterConfig; -import org.apache.helix.model.ExternalView; -import org.apache.helix.model.HelixConfigScope; -import org.apache.helix.model.IdealState; -import org.apache.helix.model.IdealState.RebalanceMode; -import org.apache.helix.model.InstanceConfig; -import org.apache.helix.model.builder.HelixConfigScopeBuilder; -import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterStateVerifier; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class TestCrushAutoRebalanceNonRack extends ZkIntegrationTestBase { - final int NUM_NODE = 6; - protected static final int START_PORT = 12918; - protected static final int _PARTITIONS = 20; - - protected final String CLASS_NAME = getShortClassName(); - protected final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + CLASS_NAME; - protected ClusterControllerManager _controller; - - protected ClusterSetup _setupTool = null; - List<MockParticipantManager> _participants = new ArrayList<MockParticipantManager>(); - Map<String, String> _nodeToTagMap = new HashMap<String, String>(); - List<String> _nodes = new ArrayList<String>(); - List<String> _allDBs = new ArrayList<String>(); - int _replica = 3; - - @BeforeClass - public void beforeClass() throws Exception { - System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - - String namespace = "/" + CLUSTER_NAME; - if (_gZkClient.exists(namespace)) { - _gZkClient.deleteRecursive(namespace); - } - _setupTool = new ClusterSetup(_gZkClient); - _setupTool.addCluster(CLUSTER_NAME, true); - - ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient); - HelixConfigScope clusterScope = - new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER) - .forCluster(CLUSTER_NAME).build(); - - Map<String, String> configs = new HashMap<String, String>(); - configs.put(ClusterConfig.ClusterConfigProperty.TOPOLOGY.name(), "/instance"); - configs.put(ClusterConfig.ClusterConfigProperty.FAULT_ZONE_TYPE.name(), "instance"); - configAccessor.set(clusterScope, configs); - - for (int i = 0; i < NUM_NODE; i++) { - String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); - _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); - _nodes.add(storageNodeName); - String tag = "tag-" + i % 2; - _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, tag); - _nodeToTagMap.put(storageNodeName, tag); - HelixConfigScope instanceScope = - new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT) - .forCluster(CLUSTER_NAME).forParticipant(storageNodeName).build(); - configAccessor - .set(instanceScope, InstanceConfig.InstanceConfigProperty.DOMAIN.name(), "instance=" + storageNodeName); - } - - // start dummy participants - for (String node : _nodes) { - MockParticipantManager participant = - new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, node); - participant.syncStart(); - _participants.add(participant); - } - - // start controller - String controllerName = CONTROLLER_PREFIX + "_0"; - _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); - _controller.syncStart(); - } - - @DataProvider(name = "rebalanceStrategies") - public static String [][] rebalanceStrategies() { - return new String[][] { {"CrushRebalanceStrategy", CrushRebalanceStrategy.class.getName()}}; - } - - @Test(dataProvider = "rebalanceStrategies", enabled=true) - public void test(String rebalanceStrategyName, String rebalanceStrategyClass) - throws Exception { - System.out.println("Test " + rebalanceStrategyName); - List<String> testDBs = new ArrayList<String>(); - String[] testModels = { BuiltInStateModelDefinitions.OnlineOffline.name(), - BuiltInStateModelDefinitions.MasterSlave.name(), - BuiltInStateModelDefinitions.LeaderStandby.name() - }; - int i = 0; - for (String stateModel : testModels) { - String db = "Test-DB-" + rebalanceStrategyName + "-" + i++; - _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, - RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass); - _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica); - testDBs.add(db); - _allDBs.add(db); - } - Thread.sleep(300); - - boolean result = ClusterStateVerifier.verifyByZkCallback( - new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME)); - Assert.assertTrue(result); - - for (String db : testDBs) { - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db); - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - validateIsolation(is, ev); - } - } - - @Test(dataProvider = "rebalanceStrategies", enabled=true) - public void testWithInstanceTag( - String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception { - List<String> testDBs = new ArrayList<String>(); - Set<String> tags = new HashSet<String>(_nodeToTagMap.values()); - int i = 0; - for (String tag : tags) { - String db = "Test-DB-Tag-" + rebalanceStrategyName + "-" + i++; - _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, - BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.FULL_AUTO + "", - rebalanceStrategyClass); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db); - is.setInstanceGroupTag(tag); - _setupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, db, is); - _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica); - testDBs.add(db); - _allDBs.add(db); - } - Thread.sleep(300); - - boolean result = ClusterStateVerifier.verifyByZkCallback( - new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME)); - Assert.assertTrue(result); - - for (String db : testDBs) { - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db); - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - validateIsolation(is, ev); - } - } - - /** - * Validate each partition is different instances and with necessary tagged instances. - */ - private void validateIsolation(IdealState is, ExternalView ev) { - int replica = Integer.valueOf(is.getReplicas()); - String tag = is.getInstanceGroupTag(); - - for (String partition : is.getPartitionSet()) { - Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); - Set<String> instancesInEV = assignmentMap.keySet(); - Assert.assertEquals(instancesInEV.size(), replica); - for (String instance : instancesInEV) { - if (tag != null) { - InstanceConfig config = - _setupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, instance); - Assert.assertTrue(config.containsTag(tag)); - } - } - } - } - - @AfterClass - public void afterClass() throws Exception { - /** - * shutdown order: 1) disconnect the controller 2) disconnect participants - */ - _controller.syncStop(); - for (MockParticipantManager participant : _participants) { - participant.syncStop(); - } - _setupTool.deleteCluster(CLUSTER_NAME); - System.out.println("END " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - } -}
http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalance.java deleted file mode 100644 index f431285..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalance.java +++ /dev/null @@ -1,452 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -import org.apache.helix.controller.rebalancer.DelayedAutoRebalancer; -import org.apache.helix.controller.rebalancer.strategy.AutoRebalanceStrategy; -import org.apache.helix.integration.manager.ClusterControllerManager; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.model.BuiltInStateModelDefinitions; -import org.apache.helix.model.ExternalView; -import org.apache.helix.model.IdealState; -import org.apache.helix.model.IdealState.RebalanceMode; -import org.apache.helix.model.StateModelDefinition; -import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier; -import org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class TestDelayedAutoRebalance extends ZkIntegrationTestBase { - final int NUM_NODE = 5; - protected static final int START_PORT = 12918; - protected static final int _PARTITIONS = 5; - - protected final String CLASS_NAME = getShortClassName(); - protected final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + CLASS_NAME; - protected ClusterControllerManager _controller; - - protected ClusterSetup _setupTool = null; - List<MockParticipantManager> _participants = new ArrayList<MockParticipantManager>(); - int _replica = 3; - HelixClusterVerifier _clusterVerifier; - List<String> _testDBs = new ArrayList<String>(); - - @BeforeClass - public void beforeClass() throws Exception { - System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - - String namespace = "/" + CLUSTER_NAME; - if (_gZkClient.exists(namespace)) { - _gZkClient.deleteRecursive(namespace); - } - _setupTool = new ClusterSetup(_gZkClient); - _setupTool.addCluster(CLUSTER_NAME, true); - - for (int i = 0; i < NUM_NODE; i++) { - String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); - _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); - - // start dummy participants - MockParticipantManager participant = - new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName); - participant.syncStart(); - _participants.add(participant); - } - - // start controller - String controllerName = CONTROLLER_PREFIX + "_0"; - _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); - _controller.syncStart(); - - _clusterVerifier = - new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build(); - } - - protected String[] TestStateModels = { - BuiltInStateModelDefinitions.MasterSlave.name(), - BuiltInStateModelDefinitions.OnlineOffline.name(), - BuiltInStateModelDefinitions.LeaderStandby.name() - }; - - /** - * The partition movement should be delayed (not happen immediately) after one single node goes offline. - * @throws Exception - */ - @Test - public void testDelayedPartitionMovement() throws Exception { - Map<String, IdealState> idealStates = new HashMap<String, IdealState>(); - Map<String, ExternalView> externalViewsBefore = new HashMap<String, ExternalView>(); - - int minActiveReplica = _replica - 1; - int i = 0; - for (String stateModel : TestStateModels) { - String db = "Test-DB-" + i++; - IdealState idealState = - createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, - minActiveReplica, 100000); - _testDBs.add(db); - idealStates.put(db, idealState); - } - - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - externalViewsBefore.put(db, ev); - } - - // bring down one node, no partition should be moved. - _participants.get(0).syncStop(); - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(idealStates.get(db), ev, minActiveReplica); - validateNoPartitionMove(idealStates.get(db), externalViewsBefore.get(db), ev, - _participants.get(0).getInstanceName()); - } - } - - /** - * Test when two nodes go offline, the minimal active replica should be maintained. - * @throws Exception - */ - @Test - public void testMinimalActiveReplicaMaintain() throws Exception { - Map<String, IdealState> idealStates = new HashMap<String, IdealState>(); - Map<String, ExternalView> externalViewsBefore = new HashMap<String, ExternalView>(); - - int minActiveReplica = _replica - 1; - int i = 0; - for (String stateModel : TestStateModels) { - String db = "Test-DB-" + i++; - IdealState idealState = - createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, - minActiveReplica, 100000); - _testDBs.add(db); - idealStates.put(db, idealState); - } - - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - externalViewsBefore.put(db, ev); - } - - // bring down one node, no partition should be moved. - _participants.get(0).syncStop(); - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, minActiveReplica); - validateNoPartitionMove(idealStates.get(db), externalViewsBefore.get(db), ev, - _participants.get(0).getInstanceName()); - } - - // bring down another node, the minimal active replica for each partition should be maintained. - _participants.get(3).syncStop(); - Thread.sleep(1000); - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, minActiveReplica); - } - } - - /** - * The partititon should be moved to other nodes after the delay time - */ - @Test - public void testPartitionMovementAfterDelayTime() throws Exception { - Map<String, IdealState> idealStates = new HashMap<String, IdealState>(); - - enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true); - - long delay = 4000; - int minActiveReplica = _replica - 1; - - int i = 0; - for (String stateModel : TestStateModels) { - String db = "Test-DB-" + i++; - IdealState idealState = - createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, - minActiveReplica, delay); - _testDBs.add(db); - idealStates.put(db, idealState); - } - Assert.assertTrue(_clusterVerifier.verify(60 * 1000)); - - // bring down one node, no partition should be moved. - _participants.get(0).syncStop(); - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, minActiveReplica); - } - - Thread.sleep(delay + 10000); - // after delay time, it should maintain required number of replicas. - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, _replica); - } - } - - @Test - public void testDisableResourceDelayRebalance() throws Exception { - Map<String, IdealState> idealStates = new HashMap<String, IdealState>(); - Map<String, ExternalView> externalViewsBefore = new HashMap<String, ExternalView>(); - - int minActiveReplica = _replica - 1; - int i = 0; - for (String stateModel : TestStateModels) { - String db = "Test-DB-" + i++; - IdealState idealState = - createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, - minActiveReplica, 100000); - _testDBs.add(db); - idealStates.put(db, idealState); - } - - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - externalViewsBefore.put(db, ev); - } - - // bring down one node, no partition should be moved. - _participants.get(0).syncStop(); - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, minActiveReplica); - validateNoPartitionMove(is, externalViewsBefore.get(db), ev, - _participants.get(0).getInstanceName()); - } - - // disable delay rebalance for one db, partition should be moved immediately - String testDb = _testDBs.get(0); - IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, testDb); - idealState.setDelayRebalanceDisabled(true); - _setupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, testDb, idealState); - Thread.sleep(1000); - - // once delay rebalance is disabled, it should maintain required number of replicas. - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, testDb); - idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb); - validateMinActiveAndTopStateReplica(idealState, ev, _replica); - } - - @Test - public void testDisableDelayRebalanceInCluster() throws Exception { - Map<String, IdealState> idealStates = new HashMap<String, IdealState>(); - disableDelayRebalanceInCluster(_gZkClient, CLUSTER_NAME, true); - - int minActiveReplica = _replica - 1; - int i = 0; - for (String stateModel : TestStateModels) { - String db = "Test-DB-" + i++; - IdealState idealState = - createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, - minActiveReplica, 100000); - _testDBs.add(db); - idealStates.put(db, idealState); - } - - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - // bring down one node, no partition should be moved. - _participants.get(0).syncStop(); - Thread.sleep(1000); - Assert.assertTrue(_clusterVerifier.verify()); - - // disable delay rebalance for the entire cluster. - disableDelayRebalanceInCluster(_gZkClient, CLUSTER_NAME, true); - Thread.sleep(1000); - for (String db : _testDBs) { - ExternalView ev = - _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db); - IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState( - CLUSTER_NAME, db); - validateMinActiveAndTopStateReplica(is, ev, _replica); - } - - disableDelayRebalanceInCluster(_gZkClient, CLUSTER_NAME, false); - } - - @AfterMethod - public void afterTest() { - // delete all DBs create in last test - for (String db : _testDBs) { - _setupTool.dropResourceFromCluster(CLUSTER_NAME, db); - } - } - - @BeforeMethod - public void beforeTest() { - // restart any participant that has been disconnected from last test. - for (int i = 0; i < _participants.size(); i++) { - if (!_participants.get(i).isConnected()) { - _participants.set(i, new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, - _participants.get(i).getInstanceName())); - _participants.get(i).syncStart(); - } - } - } - - protected IdealState createResourceWithDelayedRebalance(String clusterName, String db, - String stateModel, int numPartition, int replica, int minActiveReplica, long delay) { - return createResourceWithDelayedRebalance(clusterName, db, stateModel, numPartition, replica, - minActiveReplica, delay, AutoRebalanceStrategy.class.getName()); - } - - protected IdealState createResourceWithDelayedRebalance(String clusterName, String db, - String stateModel, int numPartition, int replica, int minActiveReplica, long delay, - String rebalanceStrategy) { - _setupTool.addResourceToCluster(clusterName, db, numPartition, stateModel, - RebalanceMode.FULL_AUTO + "", rebalanceStrategy); - - IdealState idealState = - _setupTool.getClusterManagementTool().getResourceIdealState(clusterName, db); - idealState.setMinActiveReplicas(minActiveReplica); - idealState.setRebalanceDelay(delay); - idealState.setRebalancerClassName(DelayedAutoRebalancer.class.getName()); - _setupTool.getClusterManagementTool().setResourceIdealState(clusterName, db, idealState); - _setupTool.rebalanceStorageCluster(clusterName, db, replica); - idealState = - _setupTool.getClusterManagementTool().getResourceIdealState(clusterName, db); - - return idealState; - } - - /** - * Validate instances for each partition is on different zone and with necessary tagged instances. - */ - protected void validateNoPartitionMove(IdealState is, ExternalView evBefore, ExternalView evAfter, - String offlineInstance) { - for (String partition : is.getPartitionSet()) { - Map<String, String> assignmentsBefore = evBefore.getRecord().getMapField(partition); - Map<String, String> assignmentsAfter = evAfter.getRecord().getMapField(partition); - - Set<String> instancesBefore = new HashSet<String>(assignmentsBefore.keySet()); - Set<String> instancesAfter = new HashSet<String>(assignmentsAfter.keySet()); - instancesBefore.remove(offlineInstance); - - Assert.assertEquals(instancesBefore, instancesAfter, String - .format("%s has been moved to new instances, before: %s, after: %s, offline instance:", - partition, assignmentsBefore.toString(), assignmentsAfter.toString(), - offlineInstance)); - } - } - - /** - * Validate there should be always minimal active replica and top state replica for each partition - */ - protected void validateMinActiveAndTopStateReplica(IdealState is, ExternalView ev, - int minActiveReplica) { - StateModelDefinition stateModelDef = - BuiltInStateModelDefinitions.valueOf(is.getStateModelDefRef()).getStateModelDefinition(); - String topState = stateModelDef.getStatesPriorityList().get(0); - int replica = Integer.valueOf(is.getReplicas()); - - Map<String, Integer> stateCount = - StateModelDefinition.getStateCountMap(stateModelDef, NUM_NODE, replica); - Set<String> activeStates = stateCount.keySet(); - - for (String partition : is.getPartitionSet()) { - Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); - Assert.assertNotNull(assignmentMap, - is.getResourceName() + "'s best possible assignment is null for partition " + partition); - Assert.assertTrue(!assignmentMap.isEmpty(), - is.getResourceName() + "'s partition " + partition + " has no best possible map in IS."); - - boolean hasTopState = false; - int activeReplica = 0; - for (String state : assignmentMap.values()) { - if (topState.equalsIgnoreCase(state)) { - hasTopState = true; - } - if (activeStates.contains(state)) { - activeReplica++; - } - } - Assert.assertTrue(hasTopState, String.format("%s missing %s replica", partition, topState)); - Assert.assertTrue(activeReplica >= minActiveReplica, String - .format("%s has less active replica %d then required %d", partition, activeReplica, - minActiveReplica)); - } - } - - @AfterClass - public void afterClass() throws Exception { - /** - * shutdown order: 1) disconnect the controller 2) disconnect participants - */ - _controller.syncStop(); - for (MockParticipantManager participant : _participants) { - participant.syncStop(); - } - _setupTool.deleteCluster(CLUSTER_NAME); - System.out.println("END " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalanceWithRackaware.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalanceWithRackaware.java b/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalanceWithRackaware.java deleted file mode 100644 index af11966..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDelayedAutoRebalanceWithRackaware.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -import org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy; -import org.apache.helix.integration.manager.ClusterControllerManager; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.model.IdealState; -import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier; -import org.testng.annotations.BeforeClass; - -import java.util.Date; - -public class TestDelayedAutoRebalanceWithRackaware extends TestDelayedAutoRebalance { - final int NUM_NODE = 9; - - @BeforeClass - public void beforeClass() throws Exception { - System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - - String namespace = "/" + CLUSTER_NAME; - if (_gZkClient.exists(namespace)) { - _gZkClient.deleteRecursive(namespace); - } - _setupTool = new ClusterSetup(_gZkClient); - _setupTool.addCluster(CLUSTER_NAME, true); - - for (int i = 0; i < NUM_NODE; i++) { - String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); - _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); - String zone = "zone-" + i % 3; - _setupTool.getClusterManagementTool().setInstanceZoneId(CLUSTER_NAME, storageNodeName, zone); - - // start dummy participants - MockParticipantManager participant = - new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName); - participant.syncStart(); - _participants.add(participant); - } - - // start controller - String controllerName = CONTROLLER_PREFIX + "_0"; - _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); - _controller.syncStart(); - - _clusterVerifier = - new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build(); - } - - @Override - protected IdealState createResourceWithDelayedRebalance(String clusterName, String db, - String stateModel, int numPartition, int replica, int minActiveReplica, long delay) { - return createResourceWithDelayedRebalance(clusterName, db, stateModel, numPartition, replica, - minActiveReplica, delay, CrushRebalanceStrategy.class.getName()); - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java index ce22119..b9097b3 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java @@ -42,7 +42,7 @@ import org.apache.helix.model.ExternalView; import org.apache.helix.model.LiveInstance; import org.apache.helix.participant.CustomCodeCallbackHandler; import org.apache.helix.participant.HelixCustomCodeRunner; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDisableExternalView.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableExternalView.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableExternalView.java index 62087db..a17f987 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableExternalView.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableExternalView.java @@ -31,7 +31,7 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java index f66a1ed..6b6c280 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java @@ -22,7 +22,7 @@ package org.apache.helix.integration; import org.apache.helix.integration.common.ZkStandAloneCMTestBase; import org.apache.helix.manager.zk.ZKHelixAdmin; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java index 3d363f6..32f581f 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java @@ -42,7 +42,7 @@ import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.DataProvider; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDisableResource.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableResource.java index 22bdd39..116aed5 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableResource.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableResource.java @@ -38,7 +38,7 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java index 3ed6d56..515c640 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java @@ -31,8 +31,8 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.LiveInstance; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java index 5bab520..3095a2b 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java @@ -30,8 +30,8 @@ import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.LiveInstance; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java index eb86fc0..d7894d9 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java @@ -262,6 +262,7 @@ public class TestDrop extends ZkIntegrationTestBase { Assert.assertEquals(disabledPartitions.get(0), "TestDB0_4"); // ExteranlView should have TestDB0_4->localhost_12918_>ERROR + Thread.sleep(2000); ExternalView ev = accessor.getProperty(keyBuilder.externalView("TestDB0")); Set<String> partitions = ev.getPartitionSet(); Assert.assertEquals(partitions.size(), 1, "Should have TestDB0_4->localhost_12918->ERROR"); @@ -437,6 +438,7 @@ public class TestDrop extends ZkIntegrationTestBase { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.assertTrue(verifier.verify()); + Thread.sleep(2000); assertEmptyCSandEV(clusterName, "schemata", participants); // clean up http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java index 48763db..7f0b77c 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java @@ -23,7 +23,7 @@ import org.apache.helix.TestHelper; import org.apache.helix.integration.common.ZkStandAloneCMTestBase; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestEntropyFreeNodeBounce.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestEntropyFreeNodeBounce.java b/helix-core/src/test/java/org/apache/helix/integration/TestEntropyFreeNodeBounce.java index e031d45..dc38369 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestEntropyFreeNodeBounce.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestEntropyFreeNodeBounce.java @@ -44,9 +44,9 @@ import org.apache.helix.participant.statemachine.StateModel; import org.apache.helix.participant.statemachine.StateModelFactory; import org.apache.helix.participant.statemachine.StateModelInfo; import org.apache.helix.participant.statemachine.Transition; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.ZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier.ZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java index 69034b7..deef1bc 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java @@ -31,7 +31,7 @@ import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZKHelixAdmin; import org.apache.helix.mock.participant.ErrTransition; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java index d6b72fb..9fdc2e6 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java @@ -30,9 +30,9 @@ import org.apache.helix.integration.common.ZkIntegrationTestBase; import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZkBaseDataAccessor; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.MasterNbInExtViewVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier; import org.apache.zookeeper.data.Stat; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java index a6df990..0015137 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java @@ -37,7 +37,7 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.LiveInstance; import org.apache.helix.participant.CustomCodeCallbackHandler; import org.apache.helix.participant.HelixCustomCodeRunner; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java index 34af958..211cca1 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java @@ -27,7 +27,7 @@ import org.apache.helix.HelixManager; import org.apache.helix.integration.common.ZkStandAloneCMTestBase; import org.apache.helix.model.ExternalView; import org.apache.helix.model.InstanceConfig; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestInstanceHistory.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestInstanceHistory.java b/helix-core/src/test/java/org/apache/helix/integration/TestInstanceHistory.java deleted file mode 100644 index 64703b8..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestInstanceHistory.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -import org.apache.helix.HelixManager; -import org.apache.helix.HelixManagerFactory; -import org.apache.helix.InstanceType; -import org.apache.helix.PropertyKey; -import org.apache.helix.model.ParticipantHistory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.List; - -public class TestInstanceHistory extends ZkStandAloneCMTestBase { - - @Test() public void testInstanceHistory() throws Exception { - HelixManager manager = HelixManagerFactory - .getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR); - manager.connect(); - - PropertyKey.Builder keyBuilder = new PropertyKey.Builder(CLUSTER_NAME); - PropertyKey propertyKey = keyBuilder.participantHistory(_participants[0].getInstanceName()); - ParticipantHistory history = manager.getHelixDataAccessor().getProperty(propertyKey); - Assert.assertNotNull(history); - List<String> list = history.getRecord().getListField("HISTORY"); - Assert.assertEquals(list.size(), 1); - - for (int i = 0; i <= 12; i++) { - _participants[0].disconnect(); - _participants[0].connect(); - } - - history = manager.getHelixDataAccessor().getProperty(propertyKey); - Assert.assertNotNull(history); - list = history.getRecord().getListField("HISTORY"); - Assert.assertEquals(list.size(), 10); - manager.disconnect(); - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java index 47f7e96..01c89fe 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java @@ -36,9 +36,9 @@ import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.model.InstanceConfig; import org.apache.helix.model.StateModelDefinition; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.helix.tools.StateModelConfigGenerator; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; // Helix-50: integration test for generate message based on state priority http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidResourceRebalance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidResourceRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidResourceRebalance.java index 18324f1..7b56f5d 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidResourceRebalance.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidResourceRebalance.java @@ -30,7 +30,7 @@ import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.model.builder.HelixConfigScopeBuilder; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestNodeOfflineTimeStamp.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestNodeOfflineTimeStamp.java b/helix-core/src/test/java/org/apache/helix/integration/TestNodeOfflineTimeStamp.java deleted file mode 100644 index cfff20b..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestNodeOfflineTimeStamp.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -import org.apache.helix.HelixDataAccessor; -import org.apache.helix.PropertyKey; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.model.ParticipantHistory; -import org.testng.Assert; -import org.testng.annotations.Test; - -public class TestNodeOfflineTimeStamp extends ZkStandAloneCMTestBase { - final String className = getShortClassName(); - - @Test - public void testNodeShutdown() throws Exception { - for (MockParticipantManager participant : _participants) { - ParticipantHistory history = getInstanceHistory(participant.getInstanceName()); - Assert.assertNotNull(history); - Assert.assertEquals(history.getLastOfflineTime(), Long.valueOf(ParticipantHistory.ONLINE)); - } - - long shutdownTime = System.currentTimeMillis(); - _participants[0].syncStop(); - ParticipantHistory history = getInstanceHistory(_participants[0].getInstanceName()); - long recordTime = history.getLastOfflineTime(); - - Assert.assertTrue(Math.abs(shutdownTime - recordTime) <= 500L); - - _participants[0].reset(); - _participants[0].syncStart(); - - history = getInstanceHistory(_participants[0].getInstanceName()); - Assert.assertEquals(history.getLastOfflineTime(), Long.valueOf(ParticipantHistory.ONLINE)); - } - - private ParticipantHistory getInstanceHistory(String instance) { - HelixDataAccessor accessor = _manager.getHelixDataAccessor(); - PropertyKey propertyKey = accessor.keyBuilder().participantHistory(instance); - return accessor.getProperty(propertyKey); - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestPartitionLevelTransitionConstraint.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestPartitionLevelTransitionConstraint.java b/helix-core/src/test/java/org/apache/helix/integration/TestPartitionLevelTransitionConstraint.java index d706f8a..563f688 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestPartitionLevelTransitionConstraint.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestPartitionLevelTransitionConstraint.java @@ -44,7 +44,7 @@ import org.apache.helix.model.StateModelDefinition; import org.apache.helix.model.builder.ConstraintItemBuilder; import org.apache.helix.participant.statemachine.StateModel; import org.apache.helix.participant.statemachine.StateModelFactory; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java index af7deb4..badf572 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java @@ -33,8 +33,8 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.manager.zk.ZkClient; import org.apache.helix.model.PauseSignal; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestReelectedPipelineCorrectness.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestReelectedPipelineCorrectness.java b/helix-core/src/test/java/org/apache/helix/integration/TestReelectedPipelineCorrectness.java index 123a214..a1f1868 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestReelectedPipelineCorrectness.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestReelectedPipelineCorrectness.java @@ -31,8 +31,8 @@ import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.model.LiveInstance; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java index 8f16002..5177564 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java @@ -35,7 +35,7 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.helix.tools.DefaultIdealStateCalculator; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java index a1bd759..a24e488 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java @@ -30,7 +30,7 @@ import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.mock.participant.ErrTransition; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java index 4429e12..295c1c0 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java @@ -37,7 +37,7 @@ import org.apache.helix.mock.participant.ErrTransition; import org.apache.helix.model.LiveInstance; import org.apache.helix.model.Message; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java index fd71d3e..2246c6e 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java @@ -30,7 +30,7 @@ import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.mock.participant.ErrTransition; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestResourceWithSamePartitionKey.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResourceWithSamePartitionKey.java b/helix-core/src/test/java/org/apache/helix/integration/TestResourceWithSamePartitionKey.java index 75bfc43..bbb46eb 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestResourceWithSamePartitionKey.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestResourceWithSamePartitionKey.java @@ -33,7 +33,7 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.IdealState; import org.apache.helix.model.IdealState.RebalanceMode; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java index 0dea690..36ff05d 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java @@ -33,8 +33,8 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestSemiAutoRebalance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSemiAutoRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestSemiAutoRebalance.java deleted file mode 100644 index b24b0fe..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestSemiAutoRebalance.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.helix.HelixDataAccessor; -import org.apache.helix.PropertyKey; -import org.apache.helix.integration.manager.ClusterControllerManager; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.manager.zk.ZKHelixDataAccessor; -import org.apache.helix.model.ExternalView; -import org.apache.helix.model.IdealState; -import org.apache.helix.model.MasterSlaveSMD; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class TestSemiAutoRebalance extends ZkIntegrationTestBase { - protected final String CLASS_NAME = getShortClassName(); - protected final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + CLASS_NAME; - - protected static final int PARTICIPANT_NUMBER = 5; - protected static final int PARTICIPANT_START_PORT = 12918; - - protected static final String DB_NAME = "TestDB"; - protected static final int PARTITION_NUMBER = 20; - protected static final int REPLICA_NUMBER = 3; - protected static final String STATE_MODEL = "MasterSlave"; - - protected List<MockParticipantManager> _participants = new ArrayList<MockParticipantManager>(); - protected ClusterControllerManager _controller; - - protected HelixDataAccessor _accessor; - protected PropertyKey.Builder _keyBuilder; - - @BeforeClass - public void beforeClass() - throws InterruptedException { - System.out.println( - "START " + getShortClassName() + " at " + new Date(System.currentTimeMillis())); - - String namespace = "/" + CLUSTER_NAME; - if (_gZkClient.exists(namespace)) { - _gZkClient.deleteRecursive(namespace); - } - - // setup storage cluster - _gSetupTool.addCluster(CLUSTER_NAME, true); - _gSetupTool.addResourceToCluster(CLUSTER_NAME, DB_NAME, PARTITION_NUMBER, STATE_MODEL, - IdealState.RebalanceMode.SEMI_AUTO.toString()); - - _accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor); - _keyBuilder = _accessor.keyBuilder(); - - List<String> instances = new ArrayList<String>(); - for (int i = 0; i < PARTICIPANT_NUMBER; i++) { - String instance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + i); - _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance); - instances.add(instance); - } - - _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, DB_NAME, REPLICA_NUMBER); - - // start dummy participants - for (int i = 0; i < PARTICIPANT_NUMBER; i++) { - MockParticipantManager participant = - new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(i)); - participant.syncStart(); - _participants.add(participant); - } - - // start controller - String controllerName = CONTROLLER_PREFIX + "_0"; - _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); - _controller.syncStart(); - - Thread.sleep(1000); - - // verify ideal state and external view - IdealState idealState = _accessor.getProperty(_keyBuilder.idealStates(DB_NAME)); - Assert.assertNotNull(idealState); - Assert.assertEquals(idealState.getNumPartitions(), PARTITION_NUMBER); - for (String partition : idealState.getPartitionSet()) { - List<String> preferenceList = idealState.getPreferenceList(partition); - Assert.assertNotNull(preferenceList); - Assert.assertEquals(preferenceList.size(), REPLICA_NUMBER); - } - - ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME)); - Assert.assertNotNull(externalView); - Assert.assertEquals(externalView.getPartitionSet().size(), PARTITION_NUMBER); - for (String partition : externalView.getPartitionSet()) { - Map<String, String> stateMap = externalView.getStateMap(partition); - Assert.assertEquals(stateMap.size(), REPLICA_NUMBER); - - int masters = 0; - for (String state : stateMap.values()) { - if (state.equals(MasterSlaveSMD.States.MASTER.name())) { - ++masters; - } - } - Assert.assertEquals(masters, 1); - } - } - - @Test - public void testAddParticipant() - throws InterruptedException { - String newInstance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + _participants.size()); - _gSetupTool.addInstanceToCluster(CLUSTER_NAME, newInstance); - - MockParticipantManager newParticipant = - new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, newInstance); - newParticipant.syncStart(); - - Thread.sleep(1000); - - List<String> instances = _accessor.getChildNames(_keyBuilder.instanceConfigs()); - Assert.assertEquals(instances.size(), _participants.size() + 1); - Assert.assertTrue(instances.contains(newInstance)); - - List<String> liveInstances = _accessor.getChildNames(_keyBuilder.liveInstances()); - Assert.assertEquals(liveInstances.size(), _participants.size() + 1); - Assert.assertTrue(liveInstances.contains(newInstance)); - - // nothing for new participant - ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME)); - Assert.assertNotNull(externalView); - for (String partition : externalView.getPartitionSet()) { - Map<String, String> stateMap = externalView.getStateMap(partition); - Assert.assertFalse(stateMap.containsKey(newInstance)); - } - - // clear - newParticipant.syncStop(); - _gSetupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, newInstance, false); - Thread.sleep(500); - _gSetupTool.dropInstanceFromCluster(CLUSTER_NAME, newInstance); - - instances = _accessor.getChildNames(_keyBuilder.instanceConfigs()); - Assert.assertEquals(instances.size(), _participants.size()); - - liveInstances = _accessor.getChildNames(_keyBuilder.liveInstances()); - Assert.assertEquals(liveInstances.size(), _participants.size()); - } - - @Test(dependsOnMethods = "testAddParticipant") - public void testStopAndReStartParticipant() - throws InterruptedException { - MockParticipantManager participant = _participants.get(0); - String instance = participant.getInstanceName(); - - Map<String, MasterSlaveSMD.States> affectedPartitions = - new HashMap<String, MasterSlaveSMD.States>(); - - ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME)); - - for (String partition : externalView.getPartitionSet()) { - Map<String, String> stateMap = externalView.getStateMap(partition); - if (stateMap.containsKey(instance)) { - affectedPartitions.put(partition, MasterSlaveSMD.States.valueOf(stateMap.get(instance))); - } - } - - stopParticipant(participant, affectedPartitions); - - // create a new participant - participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance); - _participants.set(0, participant); - startParticipant(participant, affectedPartitions); - } - - private void stopParticipant( - MockParticipantManager participant, Map<String, MasterSlaveSMD.States> affectedPartitions) - throws InterruptedException { - participant.syncStop(); - - Thread.sleep(1000); - - ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME)); - // No re-assignment of partition, if a MASTER is removed, one of SLAVE would be prompted - for (Map.Entry<String, MasterSlaveSMD.States> entry : affectedPartitions.entrySet()) { - Map<String, String> stateMap = externalView.getStateMap(entry.getKey()); - Assert.assertEquals(stateMap.size(), REPLICA_NUMBER - 1); - Assert.assertTrue(stateMap.values().contains(MasterSlaveSMD.States.MASTER.toString())); - } - } - - private void startParticipant( - MockParticipantManager participant, Map<String, MasterSlaveSMD.States> affectedPartitions) - throws InterruptedException { - String instance = participant.getInstanceName(); - participant.syncStart(); - - Thread.sleep(2000); - - ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME)); - // Everything back to the initial state - for (Map.Entry<String, MasterSlaveSMD.States> entry : affectedPartitions.entrySet()) { - Map<String, String> stateMap = externalView.getStateMap(entry.getKey()); - Assert.assertEquals(stateMap.size(), REPLICA_NUMBER); - - Assert.assertTrue(stateMap.containsKey(instance)); - Assert.assertEquals(stateMap.get(instance), entry.getValue().toString()); - } - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java index 567fe25..70a654e 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java @@ -30,8 +30,8 @@ import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.mock.participant.MockTransition; import org.apache.helix.model.Message; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier.BestPossAndExtViewZkVerifier; +import org.apache.helix.tools.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java index cf83b28..ef830e6 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java @@ -31,7 +31,7 @@ import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.model.LiveInstance; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java index 03d0659..3753558 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java @@ -27,7 +27,7 @@ import org.apache.helix.integration.common.ZkIntegrationTestBase; import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeoutWithResource.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeoutWithResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeoutWithResource.java deleted file mode 100644 index 1599133..0000000 --- a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeoutWithResource.java +++ /dev/null @@ -1,192 +0,0 @@ -package org.apache.helix.integration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.helix.HelixDataAccessor; -import org.apache.helix.HelixManager; -import org.apache.helix.HelixManagerFactory; -import org.apache.helix.InstanceType; -import org.apache.helix.NotificationContext; -import org.apache.helix.PropertyKey; -import org.apache.helix.PropertyKey.Builder; -import org.apache.helix.ZNRecord; -import org.apache.helix.api.config.StateTransitionTimeoutConfig; -import org.apache.helix.integration.manager.ClusterControllerManager; -import org.apache.helix.integration.manager.MockParticipantManager; -import org.apache.helix.messaging.handling.MessageHandler.ErrorCode; -import org.apache.helix.mock.participant.MockMSStateModel; -import org.apache.helix.mock.participant.MockTransition; -import org.apache.helix.mock.participant.SleepTransition; -import org.apache.helix.model.ExternalView; -import org.apache.helix.model.IdealState; -import org.apache.helix.model.Message; -import org.apache.helix.model.ResourceConfig; -import org.apache.helix.participant.statemachine.StateModelFactory; -import org.apache.helix.participant.statemachine.StateModelInfo; -import org.apache.helix.participant.statemachine.StateTransitionError; -import org.apache.helix.participant.statemachine.Transition; -import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; -import org.apache.log4j.Logger; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class TestStateTransitionTimeoutWithResource extends ZkStandAloneCMTestBase { - private static Logger LOG = Logger.getLogger(TestStateTransitionTimeout.class); - private HelixManager _manager; - - @Override - @BeforeClass - public void beforeClass() throws Exception { - System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); - - String namespace = "/" + CLUSTER_NAME; - if (_gZkClient.exists(namespace)) { - _gZkClient.deleteRecursive(namespace); - } - _setupTool = new ClusterSetup(ZK_ADDR); - - // setup storage cluster - _setupTool.addCluster(CLUSTER_NAME, true); - _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL); - - for (int i = 0; i < NODE_NR; i++) { - String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); - _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); - } - _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 3); - - // Set the timeout values - StateTransitionTimeoutConfig stateTransitionTimeoutConfig = - new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB)); - stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300); - ResourceConfig resourceConfig = new ResourceConfig(TEST_DB); - resourceConfig.setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig); - - _manager = HelixManagerFactory - .getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR); - _manager.connect(); - PropertyKey.Builder keyBuilder = _manager.getHelixDataAccessor().keyBuilder(); - _manager.getHelixDataAccessor().setProperty(keyBuilder.resourceConfig(TEST_DB), resourceConfig); - - } - - @StateModelInfo(initialState = "OFFLINE", states = { - "MASTER", "SLAVE", "ERROR" - }) - public static class TimeOutStateModel extends MockMSStateModel { - boolean _sleep = false; - StateTransitionError _error; - int _errorCallcount = 0; - - public TimeOutStateModel(MockTransition transition, boolean sleep) { - super(transition); - _sleep = sleep; - } - - @Transition(to = "MASTER", from = "SLAVE") - public void onBecomeMasterFromSlave(Message message, NotificationContext context) - throws InterruptedException { - LOG.info("Become MASTER from SLAVE"); - if (_transition != null && _sleep) { - _transition.doTransition(message, context); - } - } - - @Override - public void rollbackOnError(Message message, NotificationContext context, - StateTransitionError error) { - _error = error; - _errorCallcount++; - } - } - - public static class SleepStateModelFactory extends StateModelFactory<TimeOutStateModel> { - Set<String> partitionsToSleep = new HashSet<String>(); - int _sleepTime; - - public SleepStateModelFactory(int sleepTime) { - _sleepTime = sleepTime; - } - - public void setPartitions(Collection<String> partitions) { - partitionsToSleep.addAll(partitions); - } - - public void addPartition(String partition) { - partitionsToSleep.add(partition); - } - - @Override - public TimeOutStateModel createNewStateModel(String resource, String stateUnitKey) { - return new TimeOutStateModel(new SleepTransition(_sleepTime), - partitionsToSleep.contains(stateUnitKey)); - } - } - - @Test - public void testStateTransitionTimeOut() throws Exception { - Map<String, SleepStateModelFactory> factories = new HashMap<String, SleepStateModelFactory>(); - IdealState idealState = - _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB); - for (int i = 0; i < NODE_NR; i++) { - String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); - SleepStateModelFactory factory = new SleepStateModelFactory(1000); - factories.put(instanceName, factory); - for (String p : idealState.getPartitionSet()) { - if (idealState.getPreferenceList(p).get(0).equals(instanceName)) { - factory.addPartition(p); - } - } - - _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); - _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory); - _participants[i].syncStart(); - } - String controllerName = CONTROLLER_PREFIX + "_0"; - _controller = - new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); - _controller.syncStart(); - - boolean result = ClusterStateVerifier.verifyByZkCallback( - new ClusterStateVerifier.MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME)); - Assert.assertTrue(result); - HelixDataAccessor accessor = _participants[0].getHelixDataAccessor(); - - Builder kb = accessor.keyBuilder(); - ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB)); - for (String p : idealState.getPartitionSet()) { - String idealMaster = idealState.getPreferenceList(p).get(0); - Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals("ERROR")); - - TimeOutStateModel model = factories.get(idealMaster).getStateModel(TEST_DB, p); - Assert.assertEquals(model._errorCallcount, 1); - Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT); - } - } -} http://git-wip-us.apache.org/repos/asf/helix/blob/fa587f0b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java index e926d5c..e086671 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java @@ -26,7 +26,7 @@ import org.apache.helix.integration.common.ZkStandAloneCMTestBase; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZKHelixAdmin; import org.apache.helix.model.IdealState; -import org.apache.helix.tools.ClusterVerifiers.ClusterStateVerifier; +import org.apache.helix.tools.ClusterStateVerifier; import org.testng.Assert; import org.testng.annotations.Test;