Search in sources :

Example 51 with Metadata

use of io.grpc.Metadata in project grpc-java by grpc.

the class Http2ClientStreamTransportStateTest method transportTrailersReceived_missingStatusUsesHttpStatus.

@Test
public void transportTrailersReceived_missingStatusUsesHttpStatus() {
    BaseTransportState state = new BaseTransportState();
    state.setListener(mockListener);
    Metadata trailers = new Metadata();
    trailers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "401");
    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.UNAUTHENTICATED, statusCaptor.getValue().getCode());
    assertTrue(statusCaptor.getValue().getDescription().contains("401"));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 52 with Metadata

use of io.grpc.Metadata in project grpc-java by grpc.

the class Http2ClientStreamTransportStateTest method transportHeadersReceived_doesntRequire200.

@Test
public void transportHeadersReceived_doesntRequire200() {
    BaseTransportState state = new BaseTransportState();
    state.setListener(mockListener);
    Metadata headers = new Metadata();
    headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "500");
    headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
    state.transportHeadersReceived(headers);
    verify(mockListener, never()).closed(any(Status.class), any(Metadata.class));
    verify(mockListener).headersRead(headers);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 53 with Metadata

use of io.grpc.Metadata in project grpc-java by grpc.

the class Http2ClientStreamTransportStateTest method transportHeadersReceived_handles_1xx.

@Test
public void transportHeadersReceived_handles_1xx() {
    BaseTransportState state = new BaseTransportState();
    state.setListener(mockListener);
    Metadata infoHeaders = new Metadata();
    infoHeaders.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "100");
    state.transportHeadersReceived(infoHeaders);
    Metadata infoHeaders2 = new Metadata();
    infoHeaders2.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "101");
    state.transportHeadersReceived(infoHeaders2);
    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);
    verify(mockListener, never()).closed(any(Status.class), any(Metadata.class));
    verify(mockListener).headersRead(headers);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 54 with Metadata

use of io.grpc.Metadata in project grpc-java by grpc.

the class Http2ClientStreamTransportStateTest method transportHeadersReceived_noHttpStatus.

@Test
public void transportHeadersReceived_noHttpStatus() {
    BaseTransportState state = new BaseTransportState();
    state.setListener(mockListener);
    Metadata headers = new Metadata();
    headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
    state.transportHeadersReceived(headers);
    state.transportDataReceived(ReadableBuffers.empty(), true);
    verify(mockListener, never()).headersRead(any(Metadata.class));
    verify(mockListener).closed(statusCaptor.capture(), same(headers));
    assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 55 with Metadata

use of io.grpc.Metadata in project grpc-java by grpc.

the class Http2ClientStreamTransportStateTest method transportDataReceived_debugData.

@Test
public void transportDataReceived_debugData() {
    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);
    String testString = "This is a test";
    state.transportDataReceived(ReadableBuffers.wrap(testString.getBytes(US_ASCII)), true);
    verify(mockListener).closed(statusCaptor.capture(), same(headers));
    assertTrue(statusCaptor.getValue().getDescription().contains(testString));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)283 Test (org.junit.Test)229 Status (io.grpc.Status)78 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ClientStream (io.grpc.internal.ClientStream)20 InputStream (java.io.InputStream)19 Buffer (okio.Buffer)16 ClientCall (io.grpc.ClientCall)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 ServerStreamListener (io.grpc.internal.ServerStreamListener)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 ServerCall (io.grpc.ServerCall)12 StatsContext (com.google.instrumentation.stats.StatsContext)11 CallOptions (io.grpc.CallOptions)11 IOException (java.io.IOException)11 Context (io.grpc.Context)10 StatusRuntimeException (io.grpc.StatusRuntimeException)10 Matchers.anyString (org.mockito.Matchers.anyString)10 ServerStream (io.grpc.internal.ServerStream)9 ServiceDescriptor (io.grpc.ServiceDescriptor)8