use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method inboundHeadersReceived_acceptsIdentityMessageEncoding.
@Test
public void inboundHeadersReceived_acceptsIdentityMessageEncoding() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, Codec.Identity.NONE.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 inboundHeadersReceived_disallowsContentAndMessageEncoding.
@Test
public void inboundHeadersReceived_disallowsContentAndMessageEncoding() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.CONTENT_ENCODING_KEY, "gzip");
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, new Codec.Gzip().getMessageEncoding());
stream.setFullStreamDecompression(true);
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().equals("Full stream and gRPC message encoding cannot both be set"));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method trailerNotOkWithTruncatedMessage.
@Test
public void trailerNotOkWithTruncatedMessage() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
stream.request(1);
stream.transportState().deframe(ReadableBuffers.wrap(new byte[] { 0, 0, 0, 0, 2, 1 }));
stream.transportState().inboundTrailersReceived(new Metadata(), Status.DATA_LOSS.withDescription("data___loss"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(mockListener).closed(statusCaptor.capture(), any(RpcProgress.class), any(Metadata.class));
assertSame(Status.Code.DATA_LOSS, statusCaptor.getValue().getCode());
assertEquals("data___loss", 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_notifiesListener.
@Test
public void inboundHeadersReceived_notifiesListener() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator, statsTraceCtx, transportTracer);
stream.start(mockListener);
Metadata headers = new Metadata();
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 deadlineTimeoutPopulatedToHeaders.
@Test
public void deadlineTimeoutPopulatedToHeaders() {
AbstractClientStream.Sink sink = mock(AbstractClientStream.Sink.class);
ClientStream stream = new BaseAbstractClientStream(allocator, new BaseTransportState(statsTraceCtx, transportTracer), sink, statsTraceCtx, transportTracer);
stream.setDeadline(Deadline.after(1, TimeUnit.SECONDS));
stream.start(mockListener);
ArgumentCaptor<Metadata> headersCaptor = ArgumentCaptor.forClass(Metadata.class);
verify(sink).writeHeaders(headersCaptor.capture(), ArgumentMatchers.<byte[]>any());
Metadata headers = headersCaptor.getValue();
assertTrue(headers.containsKey(GrpcUtil.TIMEOUT_KEY));
assertThat(headers.get(GrpcUtil.TIMEOUT_KEY).longValue()).isLessThan(TimeUnit.SECONDS.toNanos(1));
assertThat(headers.get(GrpcUtil.TIMEOUT_KEY).longValue()).isGreaterThan(TimeUnit.MILLISECONDS.toNanos(600));
}
Aggregations