use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportTrailersReceived_missingStatusAndMissingHttpStatus.
@Test
public void transportTrailersReceived_missingStatusAndMissingHttpStatus() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata trailers = new Metadata();
trailers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportTrailersReceived(trailers);
verify(mockListener, never()).headersRead(any(Metadata.class));
verify(mockListener).closed(statusCaptor.capture(), same(trailers));
assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportHeadersReceived_twice.
@Test
public void transportHeadersReceived_twice() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "200");
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportHeadersReceived(headers);
Metadata headersAgain = new Metadata();
state.transportHeadersReceived(headersAgain);
state.transportDataReceived(ReadableBuffers.empty(), true);
verify(mockListener).headersRead(headers);
verify(mockListener).closed(statusCaptor.capture(), same(headersAgain));
assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
assertTrue(statusCaptor.getValue().getDescription().contains("twice"));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportHeadersReceived_wrongContentType_200.
@Test
public void transportHeadersReceived_wrongContentType_200() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "200");
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "text/html");
state.transportHeadersReceived(headers);
state.transportDataReceived(ReadableBuffers.empty(), true);
verify(mockListener, never()).headersRead(any(Metadata.class));
verify(mockListener).closed(statusCaptor.capture(), same(headers));
assertEquals(Code.UNKNOWN, statusCaptor.getValue().getCode());
assertTrue(statusCaptor.getValue().getDescription().contains("200"));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class AbstractInteropTest method exchangeMetadataUnaryCall.
@Test(timeout = 10000)
public void exchangeMetadataUnaryCall() throws Exception {
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel);
// Capture the metadata exchange
Metadata fixedHeaders = new Metadata();
// Send a context proto (as it's in the default extension registry)
Messages.SimpleContext contextValue = Messages.SimpleContext.newBuilder().setValue("dog").build();
fixedHeaders.put(METADATA_KEY, contextValue);
stub = MetadataUtils.attachHeaders(stub, fixedHeaders);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata> trailersCapture = new AtomicReference<Metadata>();
AtomicReference<Metadata> headersCapture = new AtomicReference<Metadata>();
stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture);
assertNotNull(stub.emptyCall(EMPTY));
// Assert that our side channel object is echoed back in both headers and trailers
Assert.assertEquals(contextValue, headersCapture.get().get(METADATA_KEY));
Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class AbstractInteropTest method exchangeMetadataStreamingCall.
@Test(timeout = 10000)
public void exchangeMetadataStreamingCall() throws Exception {
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
// Capture the metadata exchange
Metadata fixedHeaders = new Metadata();
// Send a context proto (as it's in the default extension registry)
Messages.SimpleContext contextValue = Messages.SimpleContext.newBuilder().setValue("dog").build();
fixedHeaders.put(METADATA_KEY, contextValue);
stub = MetadataUtils.attachHeaders(stub, fixedHeaders);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata> trailersCapture = new AtomicReference<Metadata>();
AtomicReference<Metadata> headersCapture = new AtomicReference<Metadata>();
stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture);
List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200);
Messages.StreamingOutputCallRequest.Builder streamingOutputBuilder = Messages.StreamingOutputCallRequest.newBuilder();
streamingOutputBuilder.setResponseType(COMPRESSABLE);
for (Integer size : responseSizes) {
streamingOutputBuilder.addResponseParametersBuilder().setSize(size).setIntervalUs(0);
}
final Messages.StreamingOutputCallRequest request = streamingOutputBuilder.build();
StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<Messages.StreamingOutputCallRequest> requestStream = stub.fullDuplexCall(recorder);
final int numRequests = 10;
List<StreamingOutputCallRequest> requests = new ArrayList<StreamingOutputCallRequest>(numRequests);
for (int ix = numRequests; ix > 0; --ix) {
requests.add(request);
requestStream.onNext(request);
}
requestStream.onCompleted();
recorder.awaitCompletion();
assertSuccess(recorder);
org.junit.Assert.assertEquals(responseSizes.size() * numRequests, recorder.getValues().size());
// Assert that our side channel object is echoed back in both headers and trailers
Assert.assertEquals(contextValue, headersCapture.get().get(METADATA_KEY));
Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY));
}
Aggregations