use of io.grpc.Metadata in project grpc-java by grpc.
the class NettyServerStreamTest method closeBeforeClientHalfCloseShouldSucceed.
@Test
public void closeBeforeClientHalfCloseShouldSucceed() throws Exception {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("0")));
stream().close(Status.OK, new Metadata());
ArgumentCaptor<SendResponseHeadersCommand> sendHeadersCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
verify(writeQueue).enqueue(sendHeadersCap.capture(), eq(true));
SendResponseHeadersCommand sendHeaders = sendHeadersCap.getValue();
assertThat(sendHeaders.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(sendHeaders.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(sendHeaders.endOfStream()).isTrue();
verifyZeroInteractions(serverListener);
// Sending complete. Listener gets closed()
stream().transportState().complete();
verify(serverListener).closed(Status.OK);
verifyZeroInteractions(serverListener);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method cancelStreamForDeadlineExceeded.
@Test
public void cancelStreamForDeadlineExceeded() throws Exception {
initTransport();
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
getStream(3).cancel(Status.DEADLINE_EXCEEDED);
verify(frameWriter, timeout(TIME_OUT_MS)).rstStream(eq(3), eq(ErrorCode.CANCEL));
listener.waitUntilStreamClosed();
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method pendingStreamFailedByGoAway.
@Test
public void pendingStreamFailedByGoAway() throws Exception {
initTransport();
setMaxConcurrentStreams(1);
final MockStreamListener listener1 = new MockStreamListener();
final MockStreamListener listener2 = new MockStreamListener();
OkHttpClientStream stream1 = clientTransport.newStream(method, new Metadata());
stream1.start(listener1);
// The second stream should be pending.
OkHttpClientStream stream2 = clientTransport.newStream(method, new Metadata());
stream2.start(listener2);
waitForStreamPending(1);
assertEquals(1, activeStreamCount());
// Receives GO_AWAY.
frameHandler().goAway(99, ErrorCode.CANCEL, null);
listener2.waitUntilStreamClosed();
assertEquals(Status.CANCELLED.getCode(), listener2.status.getCode());
assertEquals(0, clientTransport.getPendingStreamSize());
// active stream should not be affected.
assertEquals(1, activeStreamCount());
getStream(3).sendCancel(Status.CANCELLED);
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method shutdownDuringConnecting.
@Test
public void shutdownDuringConnecting() throws Exception {
initTransportAndDelayConnected();
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
clientTransport.shutdown();
allowTransportConnected();
// The new stream should be failed, but not the pending stream.
assertNewStreamFail();
verify(frameWriter, timeout(TIME_OUT_MS)).synStream(anyBoolean(), anyBoolean(), eq(3), anyInt(), anyListHeader());
assertEquals(1, activeStreamCount());
stream.cancel(Status.CANCELLED);
listener.waitUntilStreamClosed();
assertEquals(Status.CANCELLED.getCode(), listener.status.getCode());
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method maxMessageSizeShouldBeEnforced.
@Test
public void maxMessageSizeShouldBeEnforced() throws Exception {
// Allow the response payloads of up to 1 byte.
startTransport(3, null, true, 1, null);
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
stream.request(1);
assertContainStream(3);
frameHandler().headers(false, false, 3, 0, grpcResponseHeaders(), HeadersMode.HTTP_20_HEADERS);
assertNotNull(listener.headers);
// Receive the message.
final String message = "Hello Client";
Buffer buffer = createMessageFrame(message);
frameHandler().data(false, 3, buffer, (int) buffer.size());
listener.waitUntilStreamClosed();
assertEquals(INTERNAL, listener.status.getCode());
shutdownAndVerify();
}
Aggregations