helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject [helix] 09/44: Fix unit test by starting rest sever only once.
Date Sat, 25 May 2019 01:19:43 GMT
This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git

commit fd3aca77c86261951e6e1e261e07ad4705f02e2e
Author: Lei Xia <lxia@linkedin.com>
AuthorDate: Mon Apr 1 15:55:05 2019 -0700

    Fix unit test by starting rest sever only once.
    
    RB=1615610
    G=helix-reviewers
    A=jxue
    
    Signed-off-by: Hunter Lee <hulee@linkedin.com>
---
 .../helix/rest/server/AbstractTestClass.java       | 38 +++++++++++++---------
 1 file changed, 23 insertions(+), 15 deletions(-)

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 51a64e8..2003d2b 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
@@ -119,6 +119,7 @@ public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest
{
   protected static Map<String, Map<String, Workflow>> _workflowMap = new HashMap<>();
 
   protected MockAuditLogger _auditLogger = new MockAuditLogger();
+  protected static HelixRestServer _helixRestServer;
 
   protected class MockAuditLogger implements AuditLogger {
     List<AuditLog> _auditLogList = new ArrayList<>();
@@ -172,7 +173,6 @@ public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest
{
       @Override
       public TestContainer create(final URI baseUri, DeploymentContext deploymentContext)
{
         return new TestContainer() {
-          private HelixRestServer _helixRestServer;
 
           @Override
           public ClientConfig getClientConfig() {
@@ -186,24 +186,27 @@ public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest
{
 
           @Override
           public void start() {
-            // Create namespace manifest map
-            List<HelixRestNamespace> namespaces = new ArrayList<>();
-            // Add test namespace
-            namespaces.add(new HelixRestNamespace(TEST_NAMESPACE, HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER,
-                _zkAddrTestNS, false));
-            // Add default namesapce
-            namespaces.add(new HelixRestNamespace(ZK_ADDR));
-            try {
-              _helixRestServer = new HelixRestServer(namespaces, baseUri.getPort(), baseUri.getPath(),
-                  Arrays.<AuditLogger>asList(_auditLogger));
-              _helixRestServer.start();
-            } catch (Exception ex) {
-              throw new TestContainerException(ex);
+            if (_helixRestServer == null) {
+              // Create namespace manifest map
+              List<HelixRestNamespace> namespaces = new ArrayList<>();
+              // Add test namespace
+              namespaces.add(new HelixRestNamespace(TEST_NAMESPACE,
+                  HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, _zkAddrTestNS, false));
+              // Add default namesapce
+              namespaces.add(new HelixRestNamespace(ZK_ADDR));
+              try {
+                _helixRestServer =
+                    new HelixRestServer(namespaces, baseUri.getPort(), baseUri.getPath(),
+                        Arrays.<AuditLogger>asList(new MockAuditLogger()));
+                _helixRestServer.start();
+              } catch (Exception ex) {
+                throw new TestContainerException(ex);
+              }
             }
           }
+
           @Override
           public void stop() {
-            _helixRestServer.shutdown();
           }
         };
       }
@@ -261,6 +264,11 @@ public class AbstractTestClass extends JerseyTestNg.ContainerPerClassTest
{
       TestHelper.stopZkServer(_zkServerTestNS);
       _zkServerTestNS = null;
     }
+
+    if (_helixRestServer != null) {
+      _helixRestServer.shutdown();
+      _helixRestServer = null;
+    }
   }
 
   protected void setup() throws Exception {


Mime
View raw message