Repository: helix Updated Branches: refs/heads/master b5e5e4919 -> be619d462
Fix ZK configurations in the tests. Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/be619d46 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/be619d46 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/be619d46 Branch: refs/heads/master Commit: be619d462883dbab67b8d6b2e75d1b7d3b8a161b Parents: 0558344 Author: Jiajun Wang <[email protected]> Authored: Wed Jun 6 17:07:31 2018 -0700 Committer: jiajunwang <[email protected]> Committed: Thu Jul 12 13:45:17 2018 -0700 ---------------------------------------------------------------------- .../org/apache/helix/webapp/AdminTestBase.java | 12 +-- .../helix/integration/TestZkConnectionLost.java | 88 +++++++++++--------- .../helix/rest/server/AbstractTestClass.java | 37 ++++---- 3 files changed, 75 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/be619d46/helix-admin-webapp/src/test/java/org/apache/helix/webapp/AdminTestBase.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/AdminTestBase.java b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/AdminTestBase.java index 65e084f..1daf330 100644 --- a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/AdminTestBase.java +++ b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/AdminTestBase.java @@ -19,8 +19,6 @@ package org.apache.helix.webapp; * under the License. */ -import java.util.logging.Level; - import org.I0Itec.zkclient.ZkServer; import org.apache.helix.TestHelper; import org.apache.helix.manager.zk.ZNRecordSerializer; @@ -28,14 +26,16 @@ import org.apache.helix.manager.zk.ZkClient; import org.apache.helix.tools.ClusterSetup; import org.apache.helix.util.ZKClientPool; import org.apache.helix.webapp.AdminTestHelper.AdminThread; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.restlet.Client; import org.restlet.data.Protocol; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.AssertJUnit; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; +import java.util.logging.Level; + public class AdminTestBase { private static Logger LOG = LoggerFactory.getLogger(AdminTestBase.class); public static final String ZK_ADDR = "localhost:2187"; @@ -60,8 +60,8 @@ public class AdminTestBase { ZKClientPool.reset(); _gZkClient = - new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, - ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer()); + new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, + new ZNRecordSerializer()); _gSetupTool = new ClusterSetup(_gZkClient); // start admin http://git-wip-us.apache.org/repos/asf/helix/blob/be619d46/helix-core/src/test/java/org/apache/helix/integration/TestZkConnectionLost.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestZkConnectionLost.java b/helix-core/src/test/java/org/apache/helix/integration/TestZkConnectionLost.java index 85b8554..319f540 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestZkConnectionLost.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestZkConnectionLost.java @@ -2,13 +2,9 @@ package org.apache.helix.integration; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; import org.I0Itec.zkclient.ZkServer; import org.apache.helix.HelixException; +import org.apache.helix.SystemPropertyKeys; import org.apache.helix.TestHelper; import org.apache.helix.integration.manager.ClusterControllerManager; import org.apache.helix.integration.manager.MockParticipantManager; @@ -29,6 +25,12 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicReference; + public class TestZkConnectionLost extends TaskTestBase { private static final Logger LOG = LoggerFactory.getLogger(TestZkConnectionLost.class); @@ -65,53 +67,63 @@ public class TestZkConnectionLost extends TaskTestBase { @Test public void testLostZkConnection() throws Exception { - System.setProperty("helixmanager.waitForConnectedTimeout", "1000"); - System.setProperty("zk.session.timeout", "1000"); - String queueName = TestHelper.getTestMethodName(); + System.setProperty(SystemPropertyKeys.ZK_WAIT_CONNECTED_TIMEOUT, "1000"); + System.setProperty(SystemPropertyKeys.ZK_SESSION_TIMEOUT, "1000"); + try { + String queueName = TestHelper.getTestMethodName(); - startParticipants(_zkAddr); + startParticipants(_zkAddr); - // Create a queue - LOG.info("Starting job-queue: " + queueName); - JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 6000); - createAndEnqueueJob(queueBuild, 3); + // Create a queue + LOG.info("Starting job-queue: " + queueName); + JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 6000); + createAndEnqueueJob(queueBuild, 3); - _driver.start(queueBuild.build()); + _driver.start(queueBuild.build()); - restartZkServer(); + restartZkServer(); - WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName); - String scheduledQueue = wCtx.getLastScheduledSingleWorkflow(); - _driver.pollForWorkflowState(scheduledQueue, 30000, TaskState.COMPLETED); + WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName); + String scheduledQueue = wCtx.getLastScheduledSingleWorkflow(); + _driver.pollForWorkflowState(scheduledQueue, 30000, TaskState.COMPLETED); + } finally { + System.clearProperty(SystemPropertyKeys.ZK_WAIT_CONNECTED_TIMEOUT); + System.clearProperty(SystemPropertyKeys.ZK_SESSION_TIMEOUT); + } } @Test(dependsOnMethods = { "testLostZkConnection" }, enabled = false) - public void testLostZkConnectionNegative() - throws Exception { - System.setProperty("helixmanager.waitForConnectedTimeout", "10"); - System.setProperty("zk.session.timeout", "1000"); - String queueName = TestHelper.getTestMethodName(); + public void testLostZkConnectionNegative() throws Exception { + System.setProperty(SystemPropertyKeys.ZK_WAIT_CONNECTED_TIMEOUT, "10"); + System.setProperty(SystemPropertyKeys.ZK_SESSION_TIMEOUT, "1000"); - stopParticipants(); - startParticipants(_zkAddr); + try { + String queueName = TestHelper.getTestMethodName(); - LOG.info("Starting job-queue: " + queueName); - JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 6000); - createAndEnqueueJob(queueBuild, 3); + stopParticipants(); + startParticipants(_zkAddr); - _driver.start(queueBuild.build()); + LOG.info("Starting job-queue: " + queueName); + JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 6000); + createAndEnqueueJob(queueBuild, 3); - restartZkServer(); + _driver.start(queueBuild.build()); - WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName); - // ensure job 1 is started before stop it - String scheduledQueue = wCtx.getLastScheduledSingleWorkflow(); + restartZkServer(); - try{ - _driver.pollForWorkflowState(scheduledQueue, 30000, TaskState.COMPLETED); - Assert.fail("Test failure!"); - } catch (HelixException ex) { - // test succeed + WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName); + // ensure job 1 is started before stop it + String scheduledQueue = wCtx.getLastScheduledSingleWorkflow(); + + try { + _driver.pollForWorkflowState(scheduledQueue, 30000, TaskState.COMPLETED); + Assert.fail("Test failure!"); + } catch (HelixException ex) { + // test succeed + } + } finally { + System.clearProperty(SystemPropertyKeys.ZK_WAIT_CONNECTED_TIMEOUT); + System.clearProperty(SystemPropertyKeys.ZK_SESSION_TIMEOUT); } } http://git-wip-us.apache.org/repos/asf/helix/blob/be619d46/helix-rest/src/test/java/org/apache/helix/rest/server/AbstractTestClass.java ---------------------------------------------------------------------- diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/AbstractTestClass.java b/helix-rest/src/test/java/org/apache/helix/rest/server/AbstractTestClass.java index 8b86c17..0f7a43d 100644 --- a/helix-rest/src/test/java/org/apache/helix/rest/server/AbstractTestClass.java +++ b/helix-rest/src/test/java/org/apache/helix/rest/server/AbstractTestClass.java @@ -19,20 +19,6 @@ package org.apache.helix.rest.server; * under the License. */ -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.Response; import org.I0Itec.zkclient.ZkServer; import org.apache.helix.AccessOption; import org.apache.helix.BaseDataAccessor; @@ -74,6 +60,21 @@ import org.testng.Assert; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; + public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest { protected static final String ZK_ADDR = "localhost:2123"; protected static final String WORKFLOW_PREFIX = "Workflow_"; @@ -201,10 +202,10 @@ public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest { java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger(""); topJavaLogger.setLevel(Level.WARNING); - _gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, - ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer()); - _gZkClientTestNS = new ZkClient(_zkAddrTestNS, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, - new ZNRecordSerializer()); + _gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT, + ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); + _gZkClientTestNS = new ZkClient(_zkAddrTestNS, ZkClient.DEFAULT_SESSION_TIMEOUT, + ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); _gSetupTool = new ClusterSetup(_gZkClient); _configAccessor = new ConfigAccessor(_gZkClient); _baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
