You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by al...@apache.org on 2022/11/16 08:22:58 UTC
[dubbo-samples] branch master updated: Add empty protect test cases (#576)
This is an automated email from the ASF dual-hosted git repository.
albumenj 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 4a8b213d Add empty protect test cases (#576)
4a8b213d is described below
commit 4a8b213d5e352dc6e6334f5b0f99a22eeb4a1e9b
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Wed Nov 16 16:22:51 2022 +0800
Add empty protect test cases (#576)
---
.../case-configuration.yml | 40 ++++
.../case-versions.conf | 24 ++
.../dubbo-samples-empty-protection-nacos/pom.xml | 159 +++++++++++++
.../main/java/org/apache/dubbo/samples/Main.java | 23 ++
.../apache/dubbo/samples/api/GreetingsService.java | 23 ++
.../samples/provider/GreetingsServiceImpl.java | 27 +++
.../org/apache/dubbo/samples/empty/DefaultIT.java | 76 +++++++
.../apache/dubbo/samples/empty/NoProtectIT.java | 70 ++++++
.../org/apache/dubbo/samples/empty/ProtectIT.java | 64 ++++++
.../case-configuration.yml | 22 ++
.../case-versions.conf | 24 ++
.../dubbo-samples-empty-protection/pom.xml | 120 ++++++++++
.../apache/dubbo/samples/EmbeddedZooKeeper.java | 251 +++++++++++++++++++++
.../main/java/org/apache/dubbo/samples/Main.java | 23 ++
.../apache/dubbo/samples/api/GreetingsService.java | 23 ++
.../samples/provider/GreetingsServiceImpl.java | 27 +++
.../org/apache/dubbo/samples/empty/DefaultIT.java | 73 ++++++
.../apache/dubbo/samples/empty/NoProtectIT.java | 69 ++++++
.../org/apache/dubbo/samples/empty/ProtectIT.java | 63 ++++++
dubbo-samples-boundary-test/pom.xml | 2 +
20 files changed, 1203 insertions(+)
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-configuration.yml b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-configuration.yml
new file mode 100644
index 00000000..1c48f397
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-configuration.yml
@@ -0,0 +1,40 @@
+# 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.
+
+services:
+ nacos:
+ image: nacos/nacos-server:v2.1.2
+ environment:
+ - PREFER_HOST_MODE=hostname
+ - MODE=standalone
+ - NACOS_AUTH_ENABLE=true
+ - JVM_XMS=350m
+ - JVM_XMX=350m
+ - JVM_XMN=150m
+
+ dubbo-samples-empty-protection-nacos:
+ type: test
+ basedir: .
+ tests:
+ - "**/*IT.class"
+ systemProps:
+ - nacos.address=nacos
+ - nacos.port=8848
+ waitPortsBeforeRun:
+ - nacos:8848
+ depends_on:
+ - nacos
+
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-versions.conf b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-versions.conf
new file mode 100644
index 00000000..d718a9f3
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/case-versions.conf
@@ -0,0 +1,24 @@
+#
+#
+# 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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.*
+spring.version=4.*, 5.*
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/pom.xml b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/pom.xml
new file mode 100644
index 00000000..4da8a178
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/pom.xml
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>dubbo-samples-boundary-test</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-samples-empty-protection-nacos</artifactId>
+
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>3.0.7</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <slf4j.version>1.7.25</slf4j.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-framework-bom</artifactId>
+ <version>${spring.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <!-- For jdk 11 above JavaEE annotation -->
+ <profile>
+ <id>javax.annotation</id>
+ <activation>
+ <jdk>[1.11,)</jdk>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>apache.snapshots.https</id>
+ <name>Apache Development Snapshot Repository</name>
+ <url>https://repository.apache.org/content/repositories/snapshots</url>
+ <layout>default</layout>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>daily</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+
+</project>
\ No newline at end of file
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/Main.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/Main.java
new file mode 100644
index 00000000..bc48d411
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/Main.java
@@ -0,0 +1,23 @@
+/*
+ * 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.samples;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello world!");
+ }
+}
\ No newline at end of file
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java
new file mode 100644
index 00000000..8a3fc7d4
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java
@@ -0,0 +1,23 @@
+/*
+ * 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.samples.api;
+
+public interface GreetingsService {
+
+ String sayHi(String name);
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
new file mode 100644
index 00000000..d0d44484
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.samples.provider;
+
+import org.apache.dubbo.samples.api.GreetingsService;
+
+public class GreetingsServiceImpl implements GreetingsService {
+ @Override
+ public String sayHi(String name) {
+ return "hi, " + name;
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java
new file mode 100644
index 00000000..df4c489c
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java
@@ -0,0 +1,76 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.common.Version;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DefaultIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testDefault() throws InterruptedException {
+ LoggerFactory.setLoggerAdapter(FrameworkModel.defaultModel(), "log4j");
+ String nacosAddress = System.getProperty("nacos.address", "localhost");
+ String nacosPort = System.getProperty("nacos.port", "8848");
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?username=nacos&password=nacos"));
+ serviceConfig.export();
+ Thread.sleep(1000);
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?username=nacos&password=nacos"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ if (Version.getVersion().compareTo("3.2.0") >= 0) {
+ try {
+ greetingsService.sayHi("dubbo");
+ Assert.fail();
+ } catch (Exception e) {
+ Assert.assertTrue(e.getMessage().contains("No provider available"));
+ }
+ } else {
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+ }
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java
new file mode 100644
index 00000000..03b72272
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java
@@ -0,0 +1,70 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NoProtectIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testNoProtect() throws InterruptedException {
+ String nacosAddress = System.getProperty("nacos.address", "localhost");
+ String nacosPort = System.getProperty("nacos.port", "8848");
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?enable-empty-protection=false&username=nacos&password=nacos"));
+ serviceConfig.export();
+ Thread.sleep(1000);
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?enable-empty-protection=false&username=nacos&password=nacos"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ try {
+ greetingsService.sayHi("dubbo");
+ Assert.fail();
+ } catch (Exception e) {
+ Assert.assertTrue(e.getMessage().contains("No provider available"));
+ }
+
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java
new file mode 100644
index 00000000..3c5e7717
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection-nacos/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java
@@ -0,0 +1,64 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ProtectIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testProtect() throws InterruptedException {
+ String nacosAddress = System.getProperty("nacos.address", "localhost");
+ String nacosPort = System.getProperty("nacos.port", "8848");
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?enable-empty-protection=true&username=nacos&password=nacos"));
+ serviceConfig.export();
+ Thread.sleep(1000);
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("nacos://" + nacosAddress + ":" + nacosPort + "?enable-empty-protection=true&username=nacos&password=nacos"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-configuration.yml b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-configuration.yml
new file mode 100644
index 00000000..6ff3fd37
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-configuration.yml
@@ -0,0 +1,22 @@
+# 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.
+
+services:
+ dubbo-samples-empty-protection:
+ type: test
+ basedir: .
+ tests:
+ - "**/*IT.class"
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-versions.conf b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-versions.conf
new file mode 100644
index 00000000..d718a9f3
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/case-versions.conf
@@ -0,0 +1,24 @@
+#
+#
+# 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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.*
+spring.version=4.*, 5.*
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/pom.xml b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/pom.xml
new file mode 100644
index 00000000..fd4460b2
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/pom.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>dubbo-samples-boundary-test</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-samples-empty-protection</artifactId>
+
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>3.0.7</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-framework-bom</artifactId>
+ <version>${spring.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <!-- For jdk 11 above JavaEE annotation -->
+ <profile>
+ <id>javax.annotation</id>
+ <activation>
+ <jdk>[1.11,)</jdk>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/EmbeddedZooKeeper.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/EmbeddedZooKeeper.java
new file mode 100644
index 00000000..937c8e14
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/EmbeddedZooKeeper.java
@@ -0,0 +1,251 @@
+/*
+ * 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.samples;
+
+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 org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * 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 {
+
+ /**
+ * 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 = SocketUtils.findAvailableTcpPort();
+ }
+
+ /**
+ * 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);
+
+ zkServer.runFromConfig(configuration);
+ } catch (Exception e) {
+ if (errorHandler != null) {
+ errorHandler.handleError(e);
+ } else {
+ logger.error("Exception running embedded ZooKeeper", e);
+ }
+ }
+ }
+ }
+
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/Main.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/Main.java
new file mode 100644
index 00000000..bc48d411
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/Main.java
@@ -0,0 +1,23 @@
+/*
+ * 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.samples;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello world!");
+ }
+}
\ No newline at end of file
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java
new file mode 100644
index 00000000..8a3fc7d4
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java
@@ -0,0 +1,23 @@
+/*
+ * 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.samples.api;
+
+public interface GreetingsService {
+
+ String sayHi(String name);
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
new file mode 100644
index 00000000..d0d44484
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.samples.provider;
+
+import org.apache.dubbo.samples.api.GreetingsService;
+
+public class GreetingsServiceImpl implements GreetingsService {
+ @Override
+ public String sayHi(String name) {
+ return "hi, " + name;
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java
new file mode 100644
index 00000000..7440eb20
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/DefaultIT.java
@@ -0,0 +1,73 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.common.Version;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.EmbeddedZooKeeper;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DefaultIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testDefault() throws InterruptedException {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
+ serviceConfig.export();
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ if (Version.getVersion().compareTo("3.2.0") >= 0) {
+ try {
+ greetingsService.sayHi("dubbo");
+ Assert.fail();
+ } catch (Exception e) {
+ Assert.assertTrue(e.getMessage().contains("No provider available"));
+ }
+ } else {
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+ }
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java
new file mode 100644
index 00000000..6462316c
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/NoProtectIT.java
@@ -0,0 +1,69 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.EmbeddedZooKeeper;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NoProtectIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testNoProtect() throws InterruptedException {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181?enable-empty-protection=false"));
+ serviceConfig.export();
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181?enable-empty-protection=false"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ try {
+ greetingsService.sayHi("dubbo");
+ Assert.fail();
+ } catch (Exception e) {
+ Assert.assertTrue(e.getMessage().contains("No provider available"));
+ }
+
+ }
+}
diff --git a/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java
new file mode 100644
index 00000000..b3aeb20e
--- /dev/null
+++ b/dubbo-samples-boundary-test/dubbo-samples-empty-protection/src/test/java/org/apache/dubbo/samples/empty/ProtectIT.java
@@ -0,0 +1,63 @@
+/*
+ * 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.samples.empty;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.qos.command.impl.Offline;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.samples.EmbeddedZooKeeper;
+import org.apache.dubbo.samples.api.GreetingsService;
+import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ProtectIT {
+ @After
+ public void after() {
+ FrameworkModel.destroyAll();
+ }
+
+ @Test
+ public void testProtect() throws InterruptedException {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ServiceConfig<GreetingsService> serviceConfig = new ServiceConfig<>();
+ serviceConfig.setInterface(GreetingsService.class);
+ serviceConfig.setRef(new GreetingsServiceImpl());
+ serviceConfig.setApplication(new ApplicationConfig("provider"));
+ serviceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181?enable-empty-protection=true"));
+ serviceConfig.export();
+
+ ReferenceConfig<GreetingsService> referenceConfig = new ReferenceConfig<>();
+ referenceConfig.setInterface(GreetingsService.class);
+ referenceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181?enable-empty-protection=true"));
+ referenceConfig.setScope("remote");
+ GreetingsService greetingsService = referenceConfig.get();
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+
+ new Offline(FrameworkModel.defaultModel()).offline("org.apache.dubbo.samples.api.GreetingsService");
+ Thread.sleep(1000);
+
+ Assert.assertEquals("hi, dubbo", greetingsService.sayHi("dubbo"));
+ }
+}
diff --git a/dubbo-samples-boundary-test/pom.xml b/dubbo-samples-boundary-test/pom.xml
index c6d76ba9..a12eef18 100644
--- a/dubbo-samples-boundary-test/pom.xml
+++ b/dubbo-samples-boundary-test/pom.xml
@@ -32,6 +32,8 @@
<module>dubbo-samples-sd-merge</module>
<module>dubbo-samples-nacos-merge</module>
<module>dubbo-samples-port-unification-netty3</module>
+ <module>dubbo-samples-empty-protection</module>
+ <module>dubbo-samples-empty-protection-nacos</module>
</modules>
<repositories>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org