Support early-OK from Server.

The semantics in gRPC changed where server sending OK before client
half-closes is now permitted.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=78404390
This commit is contained in:
ejona 2014-10-23 19:49:26 -07:00 committed by Eric Anderson
parent 0a585333ce
commit df9867def9
2 changed files with 9 additions and 9 deletions

View File

@ -75,8 +75,6 @@ public abstract class AbstractServerStream extends AbstractStream implements Ser
Preconditions.checkNotNull(trailers, "trailers");
outboundPhase(Phase.STATUS);
synchronized (stateLock) {
Preconditions.checkState(!status.isOk() || state == WRITE_ONLY,
"Cannot close with OK before client half-closes");
state = CLOSED;
}
gracefulClose = true;

View File

@ -67,13 +67,15 @@ public class NettyServerStreamTest extends NettyStreamTestBase {
}
@Test
public void closeBeforeClientHalfCloseShouldFail() {
try {
stream().close(Status.OK, new Metadata.Trailers());
fail("Should throw exception");
} catch (IllegalStateException expected) {
}
assertEquals(StreamState.OPEN, stream.state());
public void closeBeforeClientHalfCloseShouldSucceed() throws Exception {
stream().close(Status.OK, new Metadata.Trailers());
verify(channel).writeAndFlush(
new SendGrpcFrameCommand(STREAM_ID, statusFrame(Status.OK), true));
verifyZeroInteractions(serverListener);
// Sending complete. Listener gets closed()
stream().complete();
verify(serverListener).closed(Status.OK);
assertEquals(StreamState.CLOSED, stream.state());
verifyZeroInteractions(serverListener);
}