use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method serverChecksInboundMetadataSize.
/**
* This assumes the server limits metadata size to GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE.
*/
@Test
public void serverChecksInboundMetadataSize() throws Exception {
server.start(serverListener);
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverTransport = serverTransportListener.transport;
Metadata tooLargeMetadata = new Metadata();
tooLargeMetadata.put(Metadata.Key.of("foo-bin", Metadata.BINARY_BYTE_MARSHALLER), new byte[GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE]);
ClientStream clientStream = client.newStream(methodDescriptor, tooLargeMetadata, callOptions, tracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
clientStream.start(clientStreamListener);
clientStream.writeMessage(methodDescriptor.streamRequest("foo"));
clientStream.halfClose();
clientStream.request(1);
// Server shouldn't have created a stream, so nothing to clean up on server-side
// If this times out, the server probably isn't noticing the metadata size
Status status = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
List<Status.Code> codeOptions = Arrays.asList(Status.Code.UNKNOWN, Status.Code.RESOURCE_EXHAUSTED, Status.Code.INTERNAL);
if (!codeOptions.contains(status.getCode())) {
fail("Status code was not expected: " + status);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method inboundHeadersReceived_acceptsGzipMessageEncoding.
@Test
public void inboundHeadersReceived_acceptsGzipMessageEncoding() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, new Codec.Gzip().getMessageEncoding());
stream.transportState().inboundHeadersReceived(headers);
verify(mockListener).headersRead(headers);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method rstStreamClosesStream.
@Test
public void rstStreamClosesStream() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
// The application will call request when waiting for a message
stream.request(1);
// Send first byte of 2 byte message
stream.transportState().deframe(ReadableBuffers.wrap(new byte[] { 0, 0, 0, 0, 2, 1 }));
Status status = Status.INTERNAL.withDescription("rst___stream");
// Simulate getting a reset
stream.transportState().transportReportStatus(status, false, /*stop delivery*/
new Metadata());
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(mockListener).closed(statusCaptor.capture(), any(RpcProgress.class), any(Metadata.class));
assertSame(Status.Code.INTERNAL, statusCaptor.getValue().getCode());
assertEquals("rst___stream", statusCaptor.getValue().getDescription());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method inboundHeadersReceived_failsIfStatusReported.
@Test
public void inboundHeadersReceived_failsIfStatusReported() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
stream.transportState().transportReportStatus(Status.CANCELLED, false, new Metadata());
TransportState state = stream.transportState();
thrown.expect(IllegalStateException.class);
state.inboundHeadersReceived(new Metadata());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method inboundHeadersReceived_failsOnUnrecognizedMessageEncoding.
@Test
public void inboundHeadersReceived_failsOnUnrecognizedMessageEncoding() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, "not-a-real-compression-method");
stream.transportState().inboundHeadersReceived(headers);
verifyNoMoreInteractions(mockListener);
Throwable t = ((BaseTransportState) stream.transportState()).getDeframeFailedCause();
assertEquals(Status.INTERNAL.getCode(), Status.fromThrowable(t).getCode());
assertTrue("unexpected deframe failed description", Status.fromThrowable(t).getDescription().startsWith("Can't find decompressor for"));
}
Aggregations