This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new eee0be3 [dubbo-1689]: Enhance the test coverage part-10 :
dubbo-plugin module (#1982)
eee0be3 is described below
commit eee0be393926d87055d62b7fbeb288451b3c32c4
Author: Ian Luo <[email protected]>
AuthorDate: Mon Jun 25 19:53:11 2018 +0800
[dubbo-1689]: Enhance the test coverage part-10 : dubbo-plugin module
(#1982)
* #1689: Enhance the test coverage part-10 : dubbo-plugin module
* #1689: Enhance the test coverage part-10 : dubbo-plugin module
* fix unit test failure
* #1689: Enhance the test coverage part-10 : dubbo-plugin module
---
.../dubbo/qos/protocol/QosProtocolWrapper.java | 9 +++-
.../java/org/apache/dubbo/qos/server/Server.java | 8 ++-
.../dubbo/qos/protocol/QosProtocolWrapperTest.java | 60 ++++++++++++++++++++++
3 files changed, 74 insertions(+), 3 deletions(-)
diff --git
a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
index 05656f9..681f522 100644
---
a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
+++
b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
@@ -83,7 +83,7 @@ public class QosProtocolWrapper implements Protocol {
int port = Integer.parseInt(url.getParameter(QOS_PORT,"22222"));
boolean acceptForeignIp =
Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP,"true"));
- Server server = org.apache.dubbo.qos.server.Server.getInstance();
+ Server server = Server.getInstance();
server.setPort(port);
server.setAcceptForeignIp(acceptForeignIp);
server.start();
@@ -92,4 +92,11 @@ public class QosProtocolWrapper implements Protocol {
//throw new RpcException("fail to start qos server", throwable);
}
}
+
+ /*package*/ void stopServer() {
+ if (hasStarted.compareAndSet(true, false)) {
+ Server server = Server.getInstance();
+ server.stop();
+ }
+ }
}
diff --git
a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
index fae0ac4..4051698 100644
---
a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
+++
b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
@@ -61,7 +61,7 @@ public class Server {
private String welcome;
- private AtomicBoolean hasStarted = new AtomicBoolean();
+ private AtomicBoolean started = new AtomicBoolean();
/**
* welcome message
@@ -78,7 +78,7 @@ public class Server {
* start server, bind port
*/
public void start() throws Throwable {
- if (!hasStarted.compareAndSet(false, true)) {
+ if (!started.compareAndSet(false, true)) {
return;
}
boss = new NioEventLoopGroup(0, new DefaultThreadFactory("qos-boss",
true));
@@ -132,4 +132,8 @@ public class Server {
public String getWelcome() {
return welcome;
}
+
+ public boolean isStarted() {
+ return started.get();
+ }
}
diff --git
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
new file mode 100644
index 0000000..d01df2d
--- /dev/null
+++
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
@@ -0,0 +1,60 @@
+package org.apache.dubbo.qos.protocol;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.qos.server.Server;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class QosProtocolWrapperTest {
+ private URL url = Mockito.mock(URL.class);
+ private Invoker invoker = mock(Invoker.class);
+ private Protocol protocol = mock(Protocol.class);
+ private QosProtocolWrapper wrapper = new QosProtocolWrapper(protocol);
+ private Server server = Server.getInstance();
+
+ @Before
+ public void setUp() throws Exception {
+ when(url.getParameter(Constants.QOS_ENABLE,
"true")).thenReturn("true");
+ when(url.getParameter(Constants.QOS_PORT,
"22222")).thenReturn("12345");
+ when(url.getParameter(Constants.ACCEPT_FOREIGN_IP,
"true")).thenReturn("false");
+ when(invoker.getUrl()).thenReturn(url);
+ when(url.getProtocol()).thenReturn(Constants.REGISTRY_PROTOCOL);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (server.isStarted()) {
+ server.stop();
+ }
+ }
+
+ @Test
+ public void testExport() throws Exception {
+ wrapper.export(invoker);
+ assertThat(server.isStarted(), is(true));
+ assertThat(server.getPort(), is(12345));
+ assertThat(server.isAcceptForeignIp(), is(false));
+ verify(protocol).export(invoker);
+ }
+
+ @Test
+ public void testRefer() throws Exception {
+ wrapper.refer(BaseCommand.class, url);
+ assertThat(server.isStarted(), is(true));
+ assertThat(server.getPort(), is(12345));
+ assertThat(server.isAcceptForeignIp(), is(false));
+ verify(protocol).refer(BaseCommand.class, url);
+ }
+}