This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 834be87da Fix failed tests (#1099)
834be87da is described below

commit 834be87da41393435fdb4935cb9464fa2864a0f7
Author: Ken Liu <[email protected]>
AuthorDate: Wed Mar 20 23:57:13 2024 +0800

    Fix failed tests (#1099)
---
 .../dubbo/samples/client/GreetingServiceIT.java    |   4 +-
 .../dubbo-samples-annotation/case-versions.conf    |   2 +-
 .../dubbo-samples-autowire/case-configuration.yml  |   4 +-
 .../case-configuration.yml                         |  33 ++-
 .../case-configuration.yml                         |   6 +-
 .../apache/dubbo/demo/provider/Application.java    |   1 -
 .../dubbo/demo/provider/EmbeddedZooKeeper.java     | 309 ---------------------
 .../src/main/resources/application.yml             |   5 -
 .../dubbo/demo/provider/EmbeddedZooKeeper.java     | 309 ---------------------
 .../apache/dubbo/demo/provider/Application.java    |   1 -
 .../dubbo/demo/provider/EmbeddedZooKeeper.java     | 309 ---------------------
 .../apache/dubbo/demo/consumer/Application.java    |   2 +-
 .../src/main/resources/application.yml             |   5 -
 .../java/org/apache/dubbo/demo/DemoServiceIT.java  |   2 +-
 .../src/main/resources/application.yml             |   5 -
 .../apache/dubbo/demo/provider/Application.java    |   1 -
 .../dubbo/demo/provider/EmbeddedZooKeeper.java     | 309 ---------------------
 .../src/main/resources/application.yml             |   5 +-
 .../dubbo/demo/provider/EmbeddedZooKeeper.java     | 309 ---------------------
 .../src/main/resources/application.yml             |   3 +-
 .../case-configuration.yml                         |   8 +-
 .../case-configuration.yml                         |   4 +-
 .../case-configuration.yml                         |  34 ++-
 .../dubbo/samples/serialization/DubboProvider.java |   2 -
 .../samples/serialization/EmbeddedZooKeeper.java   | 309 ---------------------
 25 files changed, 77 insertions(+), 1904 deletions(-)

diff --git 
a/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
 
b/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
index 050571559..df0c0862b 100644
--- 
a/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
+++ 
b/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
@@ -27,12 +27,14 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 public class GreetingServiceIT {
+    private static final String providerAddress = 
System.getProperty("dubbo.address", "localhost");
+
     @Test
     public void test() {
         ReferenceConfig<GreetingsService> reference =
                 ReferenceBuilder.<GreetingsService>newBuilder()
                         .interfaceClass(GreetingsService.class)
-                        .url("tri://localhost:50052")
+                        .url("tri://" + providerAddress + ":50052")
                         .build();
         DubboBootstrap.getInstance().reference(reference).start();
         GreetingsService service = reference.get();
diff --git a/2-advanced/dubbo-samples-annotation/case-versions.conf 
b/2-advanced/dubbo-samples-annotation/case-versions.conf
index bd23c0d86..ee2659e50 100644
--- a/2-advanced/dubbo-samples-annotation/case-versions.conf
+++ b/2-advanced/dubbo-samples-annotation/case-versions.conf
@@ -21,4 +21,4 @@
 # Spring app
 dubbo.version=3.*
 spring.version=5.*, 6.*
-java.version= [ >= 8]
+java.version= [ >= 17]
diff --git a/2-advanced/dubbo-samples-autowire/case-configuration.yml 
b/2-advanced/dubbo-samples-autowire/case-configuration.yml
index c71db322e..feec23c65 100644
--- a/2-advanced/dubbo-samples-autowire/case-configuration.yml
+++ b/2-advanced/dubbo-samples-autowire/case-configuration.yml
@@ -34,7 +34,7 @@ services:
       - dubbo.address=autowire-provider
       - dubbo.port=20880
     waitPortsBeforeRun:
-      - autowire-provider:2181
+      - zookeeper:2181
       - autowire-provider:20880
     depends_on:
-      - autowire-provider
\ No newline at end of file
+      - autowire-provider
diff --git a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml 
b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml
index 3711aeee9..86926089a 100644
--- a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml
+++ b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml
@@ -14,11 +14,32 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from: app-builtin-zookeeper.yml
+services:
+    zookeeper:
+        image: zookeeper:latest
 
-props:
-  project_name: dubbo-samples-environment-keys
-  main_class: org.apache.dubbo.samples.basic.BasicProvider
-  zookeeper_port: 2181
-  dubbo_port: 20880
+    provider:
+        type: app
+        basedir: dubbo-samples-environment-keys-provider
+        mainClass: 
org.apache.dubbo.samples.environment.keys.provider.ProviderApplication
+        systemProps:
+            - zookeeper.address=zookeeper
+        waitPortsBeforeRun:
+            - zookeeper:2181
+        checkPorts:
+            - 20880
+        checkLog: "dubbo service started"
+
+    test:
+        type: test
+        basedir: dubbo-samples-environment-keys-consumer
+        tests:
+            - "**/*IT.class"
+        systemProps:
+            - zookeeper.address=zookeeper
+        waitPortsBeforeRun:
+            - zookeeper:2181
+            - provider:20880
+        depends_on:
+            - provider
 
diff --git a/2-advanced/dubbo-samples-rpccontext/case-configuration.yml 
b/2-advanced/dubbo-samples-rpccontext/case-configuration.yml
index 3f7c3ff43..34eaaee96 100644
--- a/2-advanced/dubbo-samples-rpccontext/case-configuration.yml
+++ b/2-advanced/dubbo-samples-rpccontext/case-configuration.yml
@@ -20,7 +20,7 @@ services:
 
     dubbo-samples-rpccontext-provider2:
         type: app
-        basedir: .
+        basedir: dubbo-samples-rpccontext-provider2
         mainClass: org.apache.dubbo.samples.rpccontext.RpcContextProvider2
         systemProps:
             - zookeeper.address=zookeeper
@@ -35,7 +35,7 @@ services:
 
     dubbo-samples-rpccontext-provider:
         type: app
-        basedir: .
+        basedir: dubbo-samples-rpccontext-provider1
         mainClass: org.apache.dubbo.samples.rpccontext.RpcContextProvider1
         systemProps:
             - zookeeper.address=zookeeper
@@ -50,7 +50,7 @@ services:
 
     dubbo-samples-rpccontext-consumer:
         type: test
-        basedir: .
+        basedir: dubbo-samples-rpccontext-consumer
         tests:
             - "**/*IT.class"
         systemProps:
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
index 939d8b6ff..a95a821f4 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
+++ 
b/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -24,7 +24,6 @@ import 
org.springframework.boot.autoconfigure.SpringBootApplication;
 @EnableDubbo
 public class Application {
     public static void main(String[] args) throws Exception {
-        new EmbeddedZooKeeper(2181,false).start();
         SpringApplication.run(Application.class,args);
     }
 }
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
deleted file mode 100644
index 30d048bca..000000000
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-demo-servicediscovery-xml/servicediscovery-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.demo.provider;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/application.yml
index 800fb2bb7..f03963d32 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/application.yml
+++ 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/application.yml
@@ -18,10 +18,5 @@ dubbo:
     application:
         name: dubbo-servicediscovery-migration-consumer
         qos-enable: false
-    protocol:
-        name: dubbo
-        port: 20880
     registry:
         address: zookeeper://${zookeeper.address:127.0.0.1}:2181
-    provider:
-        token: "true"
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
deleted file mode 100644
index 30d048bca..000000000
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.demo.provider;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
index a3e7e9bf3..1d7fc64d0 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
+++ 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -24,7 +24,6 @@ import 
org.springframework.boot.autoconfigure.SpringBootApplication;
 @SpringBootApplication
 public class Application {
     public static void main(String[] args) {
-        new EmbeddedZooKeeper(2181,false).start();
         SpringApplication.run(Application.class,args);
     }
 }
diff --git 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
 
b/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
deleted file mode 100644
index 30d048bca..000000000
--- 
a/2-advanced/dubbo-samples-service-discovery/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.demo.provider;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/java/org/apache/dubbo/demo/consumer/Application.java
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/java/org/apache/dubbo/demo/consumer/Application.java
index dc237b794..47b0daeb2 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/java/org/apache/dubbo/demo/consumer/Application.java
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/java/org/apache/dubbo/demo/consumer/Application.java
@@ -30,7 +30,7 @@ public class Application implements CommandLineRunner {
         SpringApplication.run(Application.class,args);
     }
 
-    @DubboReference
+    @DubboReference(check = false)
     DemoService demoService;
     @Override
     public void run(String... args) {
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/resources/application.yml
index b9f06236e..076e240e5 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/resources/application.yml
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/main/resources/application.yml
@@ -18,10 +18,5 @@ dubbo:
     application:
         name: servicediscovery-transfer-consumer-old
         qos-enable: false
-    protocol:
-        name: dubbo
-        port: 20879
     registry:
         address: zookeeper://${zookeeper.address:127.0.0.1}:2181
-    provider:
-        token: "true"
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/test/java/org/apache/dubbo/demo/DemoServiceIT.java
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/test/java/org/apache/dubbo/demo/DemoServiceIT.java
index a34fe2914..5d1c8554b 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/test/java/org/apache/dubbo/demo/DemoServiceIT.java
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer-old/src/test/java/org/apache/dubbo/demo/DemoServiceIT.java
@@ -27,7 +27,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes =  {DubboAutoConfiguration.class})
 public class DemoServiceIT {
-    @DubboReference
+    @DubboReference(check = false)
     private DemoService demoService;
 
     @Test
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer/src/main/resources/application.yml
index a49854f76..210348cd7 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer/src/main/resources/application.yml
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-consumer/src/main/resources/application.yml
@@ -18,10 +18,5 @@ dubbo:
     application:
         name: servicediscovery-transfer-consumer
         qos-enable: false
-    protocol:
-        name: dubbo
-        port: 20880
     registry:
         address: zookeeper://${zookeeper.address:127.0.0.1}:2181
-    provider:
-        token: "true"
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/Application.java
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/Application.java
index 939d8b6ff..a95a821f4 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/Application.java
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -24,7 +24,6 @@ import 
org.springframework.boot.autoconfigure.SpringBootApplication;
 @EnableDubbo
 public class Application {
     public static void main(String[] args) throws Exception {
-        new EmbeddedZooKeeper(2181,false).start();
         SpringApplication.run(Application.class,args);
     }
 }
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
deleted file mode 100644
index 30d048bca..000000000
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.demo.provider;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/resources/application.yml
index b34b02dd2..4d65863b2 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/resources/application.yml
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider-instance/src/main/resources/application.yml
@@ -16,12 +16,13 @@
 
 dubbo:
     application:
-        name: servicediscovery-transfer-provider-instance
+        name: servicediscovery-transfer-provider
         qos-enable: false
     protocol:
         name: dubbo
-        port: 20882
+        port: 20881
     registry:
         address: zookeeper://${zookeeper.address:127.0.0.1}:2181
+        register-mode: instance
     provider:
         token: "true"
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
deleted file mode 100644
index 30d048bca..000000000
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/java/org/apache/dubbo/demo/provider/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.demo.provider;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}
diff --git 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/resources/application.yml
index 7e189ba8c..c25855138 100644
--- 
a/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/resources/application.yml
+++ 
b/2-advanced/dubbo-samples-service-discovery/servicediscovery-transfer/servicediscovery-transfer-provider/src/main/resources/application.yml
@@ -20,8 +20,9 @@ dubbo:
         qos-enable: false
     protocol:
         name: dubbo
-        port: 20881
+        port: 20880
     registry:
         address: zookeeper://${zookeeper.address:127.0.0.1}:2181
+        register-mode: interface
     provider:
         token: "true"
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/case-configuration.yml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/case-configuration.yml
index 5352a8e45..44e11ed34 100644
--- 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/case-configuration.yml
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/case-configuration.yml
@@ -20,8 +20,8 @@ services:
 
   jaxrs-provider:
     type: app
-    basedir: dubbo-samples-triple-rest-jaxrs
-    mainClass: org.apache.dubbo.rest.demo.SpringmvcRestApplication
+    basedir: .
+    mainClass: org.apache.dubbo.rest.demo.JaxrsRestApplication
     systemProps:
       - zookeeper.address=zookeeper
     waitPortsBeforeRun:
@@ -32,12 +32,12 @@ services:
 
   test:
     type: test
-    basedir: dubbo-samples-triple-rest-jaxrs
+    basedir: .
     tests:
       - "**/*IT.class"
     systemProps:
       - zookeeper.address=zookeeper
-      - dubbo.address=jaxrs-provider:50052
+      - dubbo.address=jaxrs-provider
     waitPortsBeforeRun:
       - zookeeper:2181
       - jaxrs-provider:50052
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-springmvc/case-configuration.yml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-springmvc/case-configuration.yml
index 34ff633e2..76ca90b63 100644
--- 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-springmvc/case-configuration.yml
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-springmvc/case-configuration.yml
@@ -20,7 +20,7 @@ services:
 
   springmvc-provider:
     type: app
-    basedir: dubbo-samples-triple-rest-springmvc
+    basedir: .
     mainClass: org.apache.dubbo.rest.demo.SpringmvcRestApplication
     systemProps:
       - zookeeper.address=zookeeper
@@ -32,7 +32,7 @@ services:
 
   test:
     type: test
-    basedir: dubbo-samples-triple-rest-springmvc
+    basedir: .
     tests:
       - "**/*IT.class"
     systemProps:
diff --git 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/case-configuration.yml
 
b/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/case-configuration.yml
index 04fd717f2..9fb83f154 100644
--- 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/case-configuration.yml
+++ 
b/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/case-configuration.yml
@@ -14,11 +14,33 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from: app-builtin-zookeeper.yml
+services:
+    zookeeper:
+        image: zookeeper:latest
+
+    provider:
+        type: app
+        basedir: dubbo-samples-serialization-java-provider
+        mainClass: org.apache.dubbo.samples.serialization.DubboProvider
+        systemProps:
+            - zookeeper.address=zookeeper
+        waitPortsBeforeRun:
+            - zookeeper:2181
+        checkPorts:
+            - 20880
+        checkLog: "dubbo service started"
+
+    test:
+        type: test
+        basedir: dubbo-samples-serialization-java-consumer
+        tests:
+            - "**/*IT.class"
+        systemProps:
+            - zookeeper.address=zookeeper
+        waitPortsBeforeRun:
+            - zookeeper:2181
+            - provider:20880
+        depends_on:
+            - provider
 
-props:
-  project_name: dubbo-samples-serialization-java
-  main_class: org.apache.dubbo.samples.serialization.DubboProvider
-  zookeeper_port: 2181
-  dubbo_port: 20880
 
diff --git 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/DubboProvider.java
 
b/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/DubboProvider.java
index 593aa3c9f..23e00cb8f 100644
--- 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/DubboProvider.java
+++ 
b/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/DubboProvider.java
@@ -31,8 +31,6 @@ public class DubboProvider {
                 "If you still want to use it, please follow [JEP 
290](https://openjdk.java.net/jeps/290)" +
                 "to set serialization filter to prevent deserialization 
leak.");
 
-        new EmbeddedZooKeeper(2181, false).start();
-
         SpringApplication.run(DubboProvider.class);
 
         System.out.println("dubbo service started");
diff --git 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/EmbeddedZooKeeper.java
 
b/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/EmbeddedZooKeeper.java
deleted file mode 100644
index 94573f81d..000000000
--- 
a/3-extensions/serialization/dubbo-samples-serialization/dubbo-samples-serialization-java/dubbo-samples-serialization-java-provider/src/main/java/org/apache/dubbo/samples/serialization/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,309 +0,0 @@
-
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.samples.serialization;
-
-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 org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    private static final Random RANDOM = new Random();
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = findRandomPort(30000, 65535);
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                        + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-                
-                System.setProperty("zookeeper.admin.enableServer", "false");
-
-                zkServer.runFromConfig(configuration);
-            } catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                } else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Workaround for SocketUtils.findRandomPort() deprecation.
-     *
-     * @param min min port
-     * @param max max port
-     * @return a random generated available port
-     */
-    private static int findRandomPort(int min, int max) {
-        if (min < 1024) {
-            throw new IllegalArgumentException("Max port shouldn't be less 
than 1024.");
-        }
-
-        if (max > 65535) {
-            throw new IllegalArgumentException("Max port shouldn't be greater 
than 65535.");
-        }
-
-        if (min > max) {
-            throw new IllegalArgumentException("Min port shouldn't be greater 
than max port.");
-        }
-
-        int port = 0;
-        int counter = 0;
-
-        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
-        List<Integer> randomInts = RANDOM.ints(min, max + 1)
-                .limit(max - min)
-                .mapToObj(Integer::valueOf)
-                .collect(Collectors.toList());
-
-        do {
-            if (counter > max - min) {
-                throw new IllegalStateException("Unable to find a port between 
" + min + "-" + max);
-            }
-
-            port = randomInts.get(counter);
-            counter++;
-        } while (isPortInUse(port));
-
-        return port;
-    }
-
-    private static boolean isPortInUse(int port) {
-        try (ServerSocket ignored = new ServerSocket(port)) {
-            return false;
-        } catch (IOException e) {
-            // continue
-        }
-        return true;
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to