The client and server are connected synchronously (#1006)

* fix : The client and server are connected synchronously

* fix : The client and server are connected synchronously

* fix : Increases the wait time for test cases when the server side is down
pull/1009/head
pizihao 2 years ago committed by GitHub
parent 1910ddc8a6
commit 190de72dfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -108,7 +108,7 @@ public class NettyClientConnection implements ClientConnection {
} }
@Override @Override
public void close() { public synchronized void close() {
if (this.channel == null) { if (this.channel == null) {
return; return;
} }

@ -105,12 +105,13 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement
} }
@Override @Override
public void close() { public synchronized void close() {
if (port == null) { if (port == null) {
return; return;
} }
leader.shutdownGracefully(); this.leader.shutdownGracefully();
worker.shutdownGracefully(); this.worker.shutdownGracefully();
this.channel.close();
this.future.channel().close(); this.future.channel().close();
log.info("The server is shut down and no more requests are received. The release port is {}", port.getPort()); log.info("The server is shut down and no more requests are received. The release port is {}", port.getPort());
} }
@ -146,4 +147,5 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement
super.addFirst(handler); super.addFirst(handler);
return this; return this;
} }
} }

@ -27,7 +27,7 @@ import java.io.IOException;
public class NettyServerSupportTest { public class NettyServerSupportTest {
@Test @Test
public void bind() throws IOException { public synchronized void bind() throws IOException {
NettyServerSupport support = new NettyServerSupport(() -> 8891, InstanceServerLoader.class); NettyServerSupport support = new NettyServerSupport(() -> 8891, InstanceServerLoader.class);
support.bind(); support.bind();
while (!support.isActive()) { while (!support.isActive()) {
@ -35,6 +35,7 @@ public class NettyServerSupportTest {
} }
Assert.assertTrue(support.isActive()); Assert.assertTrue(support.isActive());
support.close(); support.close();
ThreadUtil.sleep(1000L);
Assert.assertFalse(support.isActive()); Assert.assertFalse(support.isActive());
} }

Loading…
Cancel
Save