mirror of https://github.com/grpc/grpc-java.git
Fix shutting down a never-started ServerImpl
This commit is contained in:
parent
7d1e65c111
commit
e45c0c53d0
|
|
@ -132,13 +132,21 @@ public final class ServerImpl extends Server {
|
||||||
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
|
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
|
||||||
*/
|
*/
|
||||||
public ServerImpl shutdown() {
|
public ServerImpl shutdown() {
|
||||||
|
boolean shutdownTransportServer;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
|
shutdownTransportServer = started;
|
||||||
|
if (!shutdownTransportServer) {
|
||||||
|
transportServerTerminated = true;
|
||||||
|
checkForTermination();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shutdownTransportServer) {
|
||||||
|
transportServer.shutdown();
|
||||||
}
|
}
|
||||||
transportServer.shutdown();
|
|
||||||
SharedResourceHolder.release(TIMER_SERVICE, timeoutService);
|
SharedResourceHolder.release(TIMER_SERVICE, timeoutService);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,20 @@ public class ServerImplTest {
|
||||||
assertTrue(server.isTerminated());
|
assertTrue(server.isTerminated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stopImmediate() {
|
||||||
|
transportServer = new SimpleServer() {
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
throw new AssertionError("Should not be called, because wasn't started");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ServerImpl server = new ServerImpl(executor, registry, transportServer);
|
||||||
|
server.shutdown();
|
||||||
|
assertTrue(server.isShutdown());
|
||||||
|
assertTrue(server.isTerminated());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startStopImmediateWithChildTransport() throws IOException {
|
public void startStopImmediateWithChildTransport() throws IOException {
|
||||||
ServerImpl server = new ServerImpl(executor, registry, transportServer);
|
ServerImpl server = new ServerImpl(executor, registry, transportServer);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue