use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method readStatus.
@Test
public void readStatus() throws Exception {
initTransport();
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
assertContainStream(3);
frameHandler().headers(true, true, 3, 0, grpcResponseTrailers(), HeadersMode.HTTP_20_HEADERS);
listener.waitUntilStreamClosed();
assertEquals(Status.Code.OK, listener.status.getCode());
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method stopNormally.
@Test
public void stopNormally() throws Exception {
initTransport();
MockStreamListener listener1 = new MockStreamListener();
MockStreamListener listener2 = new MockStreamListener();
OkHttpClientStream stream1 = clientTransport.newStream(method, new Metadata());
stream1.start(listener1);
OkHttpClientStream stream2 = clientTransport.newStream(method, new Metadata());
stream2.start(listener2);
assertEquals(2, activeStreamCount());
clientTransport.shutdown();
assertEquals(2, activeStreamCount());
verify(transportListener).transportShutdown(isA(Status.class));
stream1.cancel(Status.CANCELLED);
stream2.cancel(Status.CANCELLED);
listener1.waitUntilStreamClosed();
listener2.waitUntilStreamClosed();
assertEquals(0, activeStreamCount());
assertEquals(Status.CANCELLED.getCode(), listener1.status.getCode());
assertEquals(Status.CANCELLED.getCode(), listener2.status.getCode());
verify(frameWriter, timeout(TIME_OUT_MS)).goAway(eq(0), eq(ErrorCode.NO_ERROR), (byte[]) any());
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method streamIdExhausted.
@Test
public void streamIdExhausted() throws Exception {
int startId = Integer.MAX_VALUE - 2;
initTransport(startId);
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
stream.request(1);
// New stream should be failed.
assertNewStreamFail();
// The alive stream should be functional, receives a message.
frameHandler().headers(false, false, startId, 0, grpcResponseHeaders(), HeadersMode.HTTP_20_HEADERS);
assertNotNull(listener.headers);
String message = "hello";
Buffer buffer = createMessageFrame(message);
frameHandler().data(false, startId, buffer, (int) buffer.size());
getStream(startId).cancel(Status.CANCELLED);
// Receives the second message after be cancelled.
buffer = createMessageFrame(message);
frameHandler().data(false, startId, buffer, (int) buffer.size());
listener.waitUntilStreamClosed();
// Should only have the first message delivered.
assertEquals(message, listener.messages.get(0));
verify(frameWriter, timeout(TIME_OUT_MS)).rstStream(eq(startId), eq(ErrorCode.CANCEL));
verify(transportListener).transportShutdown(isA(Status.class));
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method pendingStreamCancelled.
@Test
public void pendingStreamCancelled() throws Exception {
initTransport();
setMaxConcurrentStreams(0);
MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
waitForStreamPending(1);
stream.sendCancel(Status.CANCELLED);
// The second cancel should be an no-op.
stream.sendCancel(Status.UNKNOWN);
listener.waitUntilStreamClosed();
assertEquals(0, clientTransport.getPendingStreamSize());
assertEquals(Status.CANCELLED.getCode(), listener.status.getCode());
shutdownAndVerify();
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class OkHttpClientTransportTest method pendingStreamSucceedAfterShutdown.
@Test
public void pendingStreamSucceedAfterShutdown() throws Exception {
initTransport();
setMaxConcurrentStreams(0);
final MockStreamListener listener = new MockStreamListener();
// The second stream should be pending.
OkHttpClientStream stream = clientTransport.newStream(method, new Metadata());
stream.start(listener);
waitForStreamPending(1);
clientTransport.shutdown();
setMaxConcurrentStreams(1);
verify(frameWriter, timeout(TIME_OUT_MS)).synStream(anyBoolean(), anyBoolean(), eq(3), anyInt(), anyListHeader());
assertEquals(1, activeStreamCount());
stream.sendCancel(Status.CANCELLED);
shutdownAndVerify();
}
Aggregations