Skip to content

Commit

Permalink
remove internalClosed, update test. will enforce close() behavior in #…
Browse files Browse the repository at this point in the history
  • Loading branch information
zpencer committed Jun 10, 2017
1 parent 96f2635 commit c2f88b5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 25 deletions.
23 changes: 0 additions & 23 deletions core/src/main/java/io/grpc/internal/ServerCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ final class ServerCallImpl<ReqT, RespT> extends ServerCall<ReqT, RespT> {
private boolean closeCalled;
private Compressor compressor;
private boolean messageSent;
private boolean internalClosed;

ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT, RespT> method,
Metadata inboundHeaders, Context.CancellableContext context,
Expand All @@ -87,21 +86,13 @@ final class ServerCallImpl<ReqT, RespT> extends ServerCall<ReqT, RespT> {

@Override
public void request(int numMessages) {
if (internalClosed) {
return;
}
stream.request(numMessages);
}

@Override
public void sendHeaders(Metadata headers) {
checkState(!sendHeadersCalled, "sendHeaders has already been called");
checkState(!closeCalled, "call is closed");
// Check internalClosed for completeness, though today there's no way to trigger an internal
// close without already having sent headers.
if (internalClosed) {
return;
}

headers.discardAll(MESSAGE_ENCODING_KEY);
if (compressor == null) {
Expand Down Expand Up @@ -142,9 +133,6 @@ public void sendHeaders(Metadata headers) {
public void sendMessage(RespT message) {
checkState(sendHeadersCalled, "sendHeaders has not been called");
checkState(!closeCalled, "call is closed");
if (internalClosed) {
return;
}

if (method.getType().serverSendsOneMessage() && messageSent) {
internalClose(Status.INTERNAL.withDescription(TOO_MANY_RESPONSES));
Expand All @@ -167,10 +155,6 @@ public void sendMessage(RespT message) {

@Override
public void setMessageCompression(boolean enable) {
if (internalClosed) {
return;
}

stream.setMessageCompression(enable);
}

Expand All @@ -185,19 +169,13 @@ public void setCompression(String compressorName) {

@Override
public boolean isReady() {
if (internalClosed) {
return false;
}
return stream.isReady();
}

@Override
public void close(Status status, Metadata trailers) {
checkState(!closeCalled, "call already closed");
closeCalled = true;
if (internalClosed) {
return;
}

if (status.isOk() && method.getType().serverSendsOneMessage() && !messageSent) {
internalClose(Status.INTERNAL.withDescription(MISSING_RESPONSE));
Expand Down Expand Up @@ -237,7 +215,6 @@ public MethodDescriptor<ReqT, RespT> getMethodDescriptor() {
* on.
*/
private void internalClose(Status internalError) {
internalClosed = true;
stream.close(internalError, new Metadata());
}

Expand Down
2 changes: 0 additions & 2 deletions core/src/test/java/io/grpc/internal/ServerCallImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ private void sendMessage_serverSendsOne_closeOnSecondCall_appRunToCompletion(

// App runs to completion but everything is ignored
serverCall.sendMessage(1L);
verify(stream, times(1)).writeMessage(any(InputStream.class));
serverCall.close(Status.OK, new Metadata());
verify(stream, times(1)).close(any(Status.class), any(Metadata.class));
try {
serverCall.close(Status.OK, new Metadata());
fail("calling a second time should still cause an error");
Expand Down

0 comments on commit c2f88b5

Please sign in to comment.