This is an automated email from the ASF dual-hosted git repository.
songxiaosheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-samples.git
The following commit(s) were added to refs/heads/main by this push:
new 82b3662 add loadbalance-peakewma samples (#11)
82b3662 is described below
commit 82b3662261ec38a6189cb79604d119c26151ceb2
Author: heliang666s <[email protected]>
AuthorDate: Sat Jun 15 12:07:25 2024 +0800
add loadbalance-peakewma samples (#11)
* add loadbalance-peakewma samples
* fix ci
* fix case-configuration.yml and case-versions.conf
* fix ci
* fix ci
* fix test case
* fix test case
* fix test case
---
.../samples-spi-loadbalance/pom.xml | 41 +++++
.../case-configuration.yml | 68 ++++++++
.../case-versions.conf | 26 +++
.../samples-spi-loadbalance-peakewma/pom.xml | 179 +++++++++++++++++++++
.../dubbo/samples/spi/loadbalance/Consumer.java | 36 +++++
.../dubbo/samples/spi/loadbalance/Provider1.java | 37 +++++
.../dubbo/samples/spi/loadbalance/Provider2.java | 37 +++++
.../samples/spi/loadbalance/api/DemoService.java | 26 +++
.../spi/loadbalance/impl/DemoServiceImpl.java | 39 +++++
.../src/main/resources/log4j2.xml | 29 ++++
.../resources/spring/configcenter-consumer.xml | 36 +++++
.../resources/spring/configcenter-provider1.xml | 37 +++++
.../resources/spring/configcenter-provider2.xml | 37 +++++
.../samples/spi/loadbalance/DemoServiceIT.java | 122 ++++++++++++++
pom.xml | 1 +
15 files changed, 751 insertions(+)
diff --git a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/pom.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/pom.xml
new file mode 100644
index 0000000..810cae4
--- /dev/null
+++ b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/pom.xml
@@ -0,0 +1,41 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-samples-spi</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>samples-spi-loadbalance</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>samples-spi-loadbalance-peakewma</module>
+ </modules>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+</project>
\ No newline at end of file
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-configuration.yml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-configuration.yml
new file mode 100644
index 0000000..fbbef9d
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-configuration.yml
@@ -0,0 +1,68 @@
+# 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:
+ zookeeper:
+ image: zookeeper:latest
+
+ dubbo-samples-loadbalance-peakewma-provider1:
+ type: app
+ basedir: .
+ mainClass: org.apache.dubbo.samples.spi.loadbalance.Provider1
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20880
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ dubbo-samples-loadbalance-peakewma-provider2:
+ type: app
+ basedir: .
+ mainClass: org.apache.dubbo.samples.spi.loadbalance.Provider2
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ checkPorts:
+ - 20881
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ - dubbo-samples-loadbalance-peakewma-provider1:20880
+ checkLog: "dubbo service started"
+ depends_on:
+ - dubbo-samples-loadbalance-peakewma-provider1
+ - zookeeper
+
+ dubbo-samples-loadbalance-peakewma-consumer:
+ type: test
+ basedir: .
+ tests:
+ - "**/*IT.class"
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ - dubbo-samples-loadbalance-peakewma-provider1:20880
+ - dubbo-samples-loadbalance-peakewma-provider2:20881
+ depends_on:
+ - dubbo-samples-loadbalance-peakewma-provider1
+ - dubbo-samples-loadbalance-peakewma-provider2
+ - zookeeper
+
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-versions.conf
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-versions.conf
new file mode 100644
index 0000000..0d52607
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/case-versions.conf
@@ -0,0 +1,26 @@
+#
+#
+# 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.2*
+spring.version= 5.*
+java.version= [>= 8]
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/pom.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/pom.xml
new file mode 100644
index 0000000..5f39a1c
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/pom.xml
@@ -0,0 +1,179 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>samples-spi-loadbalance</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>samples-spi-loadbalance-peakewma</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+
+ <zookeeper.version>3.8.4</zookeeper.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spi.version>3.2.0</spi.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.extensions</groupId>
+ <artifactId>dubbo-extensions-bom</artifactId>
+ <version>${spi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
+ <version>3.2.11</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>logback-core</artifactId>
+ <groupId>ch.qos.logback</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>logback-classic</artifactId>
+ <groupId>ch.qos.logback</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <artifactId>dubbo-extensions-dependencies-bom</artifactId>
+ <version>${spi.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <artifactId>dubbo-cluster-loadbalance-peakewma</artifactId>
+ <version>${spi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <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>${javax.annotation-api.version}</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>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Consumer.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Consumer.java
new file mode 100644
index 0000000..10ed811
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Consumer.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.spi.loadbalance;
+
+import org.apache.dubbo.samples.spi.loadbalance.api.DemoService;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class Consumer {
+
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext(new
String[]{"spring/configcenter-consumer.xml"});
+ context.start();
+ DemoService demoService = context.getBean("demoService",
DemoService.class);
+
+ String hello = demoService.sayHello("world");
+ System.out.println(hello);
+
+ }
+}
\ No newline at end of file
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider1.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider1.java
new file mode 100644
index 0000000..2222481
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider1.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.spi.loadbalance;
+
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Provider1 {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext(new
String[]{"spring/configcenter-provider1.xml"});
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+
+}
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider2.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider2.java
new file mode 100644
index 0000000..8fb2e30
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/Provider2.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.spi.loadbalance;
+
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Provider2 {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext(new
String[]{"spring/configcenter-provider2.xml"});
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+
+}
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/api/DemoService.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/api/DemoService.java
new file mode 100644
index 0000000..c67fd42
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/api/DemoService.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.spi.loadbalance.api;
+
+public interface DemoService {
+
+ String sayHello(String name);
+
+}
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/impl/DemoServiceImpl.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..0a1ef43
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/java/org/apache/dubbo/samples/spi/loadbalance/impl/DemoServiceImpl.java
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.spi.loadbalance.impl;
+
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.samples.spi.loadbalance.api.DemoService;
+
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DemoServiceImpl implements DemoService {
+
+ @Override
+ public String sayHello(String name) {
+ System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new
Date()) + "] Hello " + name +
+ ", request from consumer: " +
RpcContext.getContext().getRemoteAddress());
+ return "Hello " + name + ", response from provider: " +
RpcContext.getContext().getLocalAddress();
+ }
+
+}
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/log4j2.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..69e1321
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/log4j2.xml
@@ -0,0 +1,29 @@
+<?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.
+ -->
+<Configuration status="WARN">
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT" follow="true">
+ <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta}
%style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue}
%style{-|}{White}
%m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}"
disableAnsi="false" charset="UTF-8"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-consumer.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-consumer.xml
new file mode 100644
index 0000000..2fdbb1e
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-consumer.xml
@@ -0,0 +1,36 @@
+<?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.
+ ~
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+ http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="dubbo-spi-loadbalance-consumer"/>
+
+ <dubbo:registry
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+
+ <dubbo:config-center
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+
+ <dubbo:reference id="demoService"
interface="org.apache.dubbo.samples.spi.loadbalance.api.DemoService"
loadbalance="peakewma"/>
+
+</beans>
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider1.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider1.xml
new file mode 100644
index 0000000..4020fbe
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider1.xml
@@ -0,0 +1,37 @@
+<!--
+ ~
+ ~ 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.
+ ~
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+ http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="dubbo-spi-loadbalance-provider1"/>
+
+ <dubbo:registry
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+
+ <dubbo:config-center
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+ <dubbo:protocol name="dubbo" port="20880"/>
+ <bean id="demoService"
class="org.apache.dubbo.samples.spi.loadbalance.impl.DemoServiceImpl"/>
+
+ <dubbo:service
interface="org.apache.dubbo.samples.spi.loadbalance.api.DemoService"
ref="demoService" loadbalance="peakewma"/>
+
+</beans>
\ No newline at end of file
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider2.xml
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider2.xml
new file mode 100644
index 0000000..dc9967f
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/main/resources/spring/configcenter-provider2.xml
@@ -0,0 +1,37 @@
+<!--
+ ~
+ ~ 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.
+ ~
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+ http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="dubbo-spi-loadbalance-provider2"/>
+
+ <dubbo:registry
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+
+ <dubbo:config-center
address="zookeeper://${zookeeper.address:127.0.0.1}:${redis.port:2181}"/>
+ <dubbo:protocol name="dubbo" port="20881"/>
+ <bean id="demoService"
class="org.apache.dubbo.samples.spi.loadbalance.impl.DemoServiceImpl"/>
+
+ <dubbo:service
interface="org.apache.dubbo.samples.spi.loadbalance.api.DemoService"
ref="demoService" loadbalance="peakewma"/>
+
+</beans>
\ No newline at end of file
diff --git
a/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/test/java/org/apache/dubbo/samples/spi/loadbalance/DemoServiceIT.java
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/test/java/org/apache/dubbo/samples/spi/loadbalance/DemoServiceIT.java
new file mode 100644
index 0000000..62fce1a
--- /dev/null
+++
b/7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/samples-spi-loadbalance-peakewma/src/test/java/org/apache/dubbo/samples/spi/loadbalance/DemoServiceIT.java
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.spi.loadbalance;
+
+import org.apache.dubbo.samples.spi.loadbalance.api.DemoService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations =
"classpath*:spring/configcenter-consumer.xml")
+public class DemoServiceIT {
+ @Autowired
+ @Qualifier("demoService")
+ private DemoService demoService;
+
+ @Test
+ public void test1() throws Exception {
+ Map<String, Integer> providerCount = new HashMap<>();
+
+ for (int i = 0; i < 1000; i++) {
+ String response = demoService.sayHello("world");
+ String[] parts = response.split(":");
+ String provider = parts[parts.length - 1].trim();
+
+ // Count the number of calls for each provider
+ providerCount.put(provider, providerCount.getOrDefault(provider,
0) + 1);
+ }
+
+ // Print the number of calls for each provider and calculate the
difference
+ int provider1Calls = providerCount.getOrDefault("20880", 0);
+ int provider2Calls = providerCount.getOrDefault("20881", 0);
+
+ for (Map.Entry<String, Integer> entry : providerCount.entrySet()) {
+ System.out.println("Provider " + entry.getKey() + " calls: " +
entry.getValue());
+ }
+
+ // Assert that the absolute difference between the two provider call
counts is less than 50
+ int diff = Math.abs(provider1Calls - provider2Calls);
+ System.out.println("Difference: " + diff);
+ Assert.assertTrue("The absolute difference between provider call
counts should be less than 60", diff <= 60);
+ }
+
+ @Test
+ public void test2() throws Exception {
+ Map<String, Integer> providerCount = new HashMap<>();
+ int time = 0;
+ for (int i = 0; i < 1000; i++) {
+ String response;
+ // Make provider1 slow every 10 requests
+ if (i % 10 == 0) {
+ response = slowProviderCall(time);
+ } else {
+ response = demoService.sayHello("world");
+ }
+ String[] parts = response.split(":");
+ String provider = parts[parts.length - 1].trim();
+
+ // Count the number of calls for each provider
+ providerCount.put(provider, providerCount.getOrDefault(provider,
0) + 1);
+ }
+
+ // Print the number of calls for each provider and calculate the
difference
+ int provider1Calls = providerCount.getOrDefault("20880", 0);
+ int provider2Calls = providerCount.getOrDefault("20881", 0);
+
+ for (Map.Entry<String, Integer> entry : providerCount.entrySet()) {
+ System.out.println("Provider " + entry.getKey() + " calls: " +
entry.getValue());
+ }
+
+ // Assert that the difference between the two provider call counts is
greater than 80
+ int diff = Math.abs(provider1Calls - provider2Calls);
+ System.out.println("Difference: " + diff);
+ Assert.assertTrue("The difference between provider call counts should
be greater than 60", diff > 60);
+ }
+
+ // Simulate a slow call to provider1
+ private String slowProviderCall(int time) {
+ String ipAddress = "unknown";
+ try {
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ ipAddress = inetAddress.getHostAddress();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ // Simulate a time-consuming operation, such as a remote service
call or database query
+ Thread.sleep(500 + time);
+ time += 30;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ return "Hello world, response from provider: " + ipAddress + ":20880";
+ }
+}
diff --git a/pom.xml b/pom.xml
index b137b88..02884b5 100755
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,7 @@
<module>4-dubbo-spi-config-samples/samples-spi-configcenter</module>
<module>2-dubbo-spi-protocol-samples/samples-spi-protocol</module>
<module>3-dubbo-spi-registry-samples/samples-spi-registry</module>
+
<module>7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/</module>
</modules>
<dependencyManagement>