core: add server transports to channelz (#4149)

A previous PR added client transports, this PR adds server
transports.
This commit is contained in:
zpencer 2018-02-27 10:02:44 -08:00 committed by GitHub
parent 4dc1b50e1a
commit 09d305c3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 8 deletions

View File

@ -380,6 +380,7 @@ public final class ServerImpl extends io.grpc.Server implements Instrumented<Ser
@Override public void run() {}
}, null);
}
channelz.addTransport(transport);
}
@Override
@ -397,14 +398,18 @@ public final class ServerImpl extends io.grpc.Server implements Instrumented<Ser
@Override
public void transportTerminated() {
if (handshakeTimeoutFuture != null) {
handshakeTimeoutFuture.cancel(false);
handshakeTimeoutFuture = null;
try {
if (handshakeTimeoutFuture != null) {
handshakeTimeoutFuture.cancel(false);
handshakeTimeoutFuture = null;
}
for (ServerTransportFilter filter : transportFilters) {
filter.transportTerminated(attributes);
}
transportClosed(transport);
} finally {
channelz.removeTransport(transport);
}
for (ServerTransportFilter filter : transportFilters) {
filter.transportTerminated(attributes);
}
transportClosed(transport);
}
@Override

View File

@ -1380,6 +1380,19 @@ public class ServerImplTest {
assertEquals(1, server.getStats().get().callsSucceeded);
}
@Test
public void channelz_transport_membershp() throws Exception {
createAndStartServer();
SimpleServerTransport transport = new SimpleServerTransport();
assertFalse(builder.channelz.containsTransport(transport.getLogId()));
ServerTransportListener listener
= transportServer.registerNewServerTransport(transport);
assertTrue(builder.channelz.containsTransport(transport.getLogId()));
listener.transportTerminated();
assertFalse(builder.channelz.containsTransport(transport.getLogId()));
}
private void createAndStartServer() throws IOException {
createServer();
server.start();
@ -1445,6 +1458,7 @@ public class ServerImplTest {
private class SimpleServerTransport implements ServerTransport {
ServerTransportListener listener;
LogId id = LogId.allocate(getClass().getName());
@Override
public void shutdown() {
@ -1458,7 +1472,7 @@ public class ServerImplTest {
@Override
public LogId getLogId() {
throw new UnsupportedOperationException();
return id;
}
@Override