You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/11 12:54:55 UTC

[GitHub] [dubbo] AlbumenJ commented on a change in pull request #8246: Add integration testcase for testing ServiceConfig and RegistryProtocol

AlbumenJ commented on a change in pull request #8246:
URL: https://github.com/apache/dubbo/pull/8246#discussion_r667477686



##########
File path: dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/ZooKeeperServerTesting.java
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+package org.apache.dubbo;
+
+import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * The zookeeper server is just for testing.
+ * <p>
+ * Note: It can only be used if the following conditions are satisfied
+ * <p>1. Integration testcase instead of unit testcase
+ * <p>2. You can use only one zookeeper instance per Package, because the zookeeper is a static global instance.
+ */
+public class ZooKeeperServerTesting {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZooKeeperServerTesting.class);
+
+    /**
+     * Define a static zookeeper instance.
+     */
+    private static volatile InnerZooKeeper INSTANCE;
+
+    /**
+     * Start the zookeeper instance.
+     */
+    public static void start() {
+        if (INSTANCE == null) {
+            INSTANCE = new InnerZooKeeper(NetUtils.getAvailablePort());
+            INSTANCE.start();
+        }
+    }
+
+    /**
+     * Returns the zookeeper server's port.
+     */
+    public static int getPort(){
+        return INSTANCE.getClientPort();
+    }
+
+    /**
+     * Shutdown the zookeeper instance.
+     */
+    public static void shutdown() {
+        if (INSTANCE != null) {
+            INSTANCE.shutdown();

Review comment:
       set INSTANCE as null after shutdown




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org