-
Notifications
You must be signed in to change notification settings - Fork 4k
core,netty: Add server negotiation timeout before client preface #3670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,13 +89,13 @@ | |
| import java.util.List; | ||
| import java.util.Queue; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.Timeout; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Matchers; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.mockito.invocation.InvocationOnMock; | ||
|
|
@@ -136,7 +136,7 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand | |
| private long maxConnectionAgeGraceInNanos = MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE; | ||
| private long keepAliveTimeInNanos = DEFAULT_SERVER_KEEPALIVE_TIME_NANOS; | ||
| private long keepAliveTimeoutInNanos = DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS; | ||
| private TransportTracer transportTracer; | ||
| private TransportTracer transportTracer = new TransportTracer(); | ||
|
|
||
| private class ServerTransportListenerImpl implements ServerTransportListener { | ||
|
|
||
|
|
@@ -155,12 +155,10 @@ public void transportTerminated() { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void manualSetUp() throws Exception { | ||
| assertNull("manualSetUp should not run more than once", handler()); | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| MockitoAnnotations.initMocks(this); | ||
| transportTracer = new TransportTracer(); | ||
|
|
||
| when(streamTracerFactory.newServerStreamTracer(anyString(), any(Metadata.class))) | ||
| .thenReturn(streamTracer); | ||
|
|
||
|
|
@@ -178,7 +176,12 @@ public Void answer(InvocationOnMock invocation) throws Throwable { | |
| } | ||
| }) | ||
| .when(streamListener) | ||
| .messagesAvailable(Matchers.<StreamListener.MessageProducer>any()); | ||
| .messagesAvailable(any(StreamListener.MessageProducer.class)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void manualSetUp() throws Exception { | ||
| assertNull("manualSetUp should not run more than once", handler()); | ||
|
|
||
| initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE)); | ||
|
|
||
|
|
@@ -195,6 +198,19 @@ public Void answer(InvocationOnMock invocation) throws Throwable { | |
| channelRead(serializedSettings); | ||
| } | ||
|
|
||
| @Test | ||
| public void transportReadyDelayedUntilConnectionPreface() throws Exception { | ||
| initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE)); | ||
|
|
||
| handler().handleProtocolNegotiationCompleted(Attributes.EMPTY); | ||
| verify(transportListener, never()).transportReady(any(Attributes.class)); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/any/isA/ ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're equivalent here. But isA would actually be worse, because if I had the wrong class I could miss callbacks that I wanted to trigger failure. I'm not trying to verify it is an Attributes; I just checking the method which happens to have certain arguments.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the second verify would fall into "I'm not trying to verify it is an Attributes". |
||
| // Simulate receipt of the connection preface | ||
| channelRead(Http2CodecUtil.connectionPrefaceBuf()); | ||
| channelRead(serializeSettings(new Http2Settings())); | ||
| verify(transportListener).transportReady(any(Attributes.class)); | ||
| } | ||
|
|
||
| @Test | ||
| public void sendFrameShouldSucceed() throws Exception { | ||
| manualSetUp(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the precise point that protocol negotiation starts, and transportReady the precise point that it ends? InProcessServer also does this? Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point a TCP connection has been established, but nothing else. transportReady is called before any RPCs are triggered.