netty: Status should be based on GOAWAY code

goingAway() is called before onGoAwayRead() in Netty:
b7f57223c1/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java (L521)

The test before checked that the stream went away, but not that the
GOAWAY code influenced our Status, as UNAVAILABLE is the default
internally.

The UNAVAILABLE default has also been changed to include a message so
that we can determine where the Status came from in case it is triggered
again in the future.
This commit is contained in:
Eric Anderson 2015-03-25 09:36:45 -07:00
parent 6407c18578
commit e515c772cd
2 changed files with 7 additions and 8 deletions

View File

@ -112,11 +112,6 @@ class NettyClientHandler extends Http2ConnectionHandler {
// Whenever a stream has been closed, try to create a pending stream to fill its place.
createPendingStreams();
}
@Override
public void goingAway() {
NettyClientHandler.this.goingAway();
}
});
}
@ -215,6 +210,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
status = status.augmentDescription(msg);
}
goAwayStatus(status);
goingAway();
}
@Override
@ -404,7 +400,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
if (goAwayStatus != null) {
return goAwayStatus;
}
return Status.UNAVAILABLE;
return Status.UNAVAILABLE.withDescription("Connection going away, but for unknown reason");
}
private void goAwayStatus(Status status) {

View File

@ -289,12 +289,15 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
promise);
// Read a GOAWAY that indicates our stream was never processed by the server.
handler.channelRead(ctx, goAwayFrame(0));
handler.channelRead(ctx,
goAwayFrame(0, 8 /* Cancel */, Unpooled.copiedBuffer("this is a test", UTF_8)));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
InOrder inOrder = inOrder(stream);
inOrder.verify(stream, calls(1)).transportReportStatus(captor.capture(), eq(false),
notNull(Metadata.Trailers.class));
assertEquals(Status.UNAVAILABLE.getCode(), captor.getValue().getCode());
assertEquals(Status.CANCELLED.getCode(), captor.getValue().getCode());
assertEquals("HTTP/2 error code: CANCEL\nthis is a test",
captor.getValue().getDescription());
}
@Test