Search in sources :

Example 41 with Metadata

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

the class AbstractClientStreamTest method deframeFailed_notifiesListener.

@Test
public void deframeFailed_notifiesListener() {
    AbstractClientStream stream = new BaseAbstractClientStream(allocator) {

        @Override
        protected void sendCancel(Status errorStatus) {
            transportReportStatus(errorStatus, true, /*stop delivery*/
            new Metadata());
        }
    };
    stream.start(mockListener);
    stream.deframeFailed(new RuntimeException("something bad"));
    verify(mockListener).closed(statusCaptor.capture(), isA(Metadata.class));
    assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 42 with Metadata

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

the class AbstractClientStreamTest method inboundHeadersReceived_acceptsGzipEncoding.

@Test
public void inboundHeadersReceived_acceptsGzipEncoding() {
    AbstractClientStream stream = new BaseAbstractClientStream(allocator);
    stream.start(mockListener);
    Metadata headers = new Metadata();
    headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, new Codec.Gzip().getMessageEncoding());
    stream.inboundHeadersReceived(headers);
    verify(mockListener).headersRead(headers);
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 43 with Metadata

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

the class AbstractServerStreamTest method close_failsOnNullStatus.

@Test
public void close_failsOnNullStatus() {
    thrown.expect(NullPointerException.class);
    stream.close(null, new Metadata());
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 44 with Metadata

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

the class AbstractServerStreamTest method close_sendsTrailers.

@Test
public void close_sendsTrailers() {
    Metadata trailers = new Metadata();
    stream.close(Status.INTERNAL, trailers);
    verify(sink).writeTrailers(any(Metadata.class), eq(false));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 45 with Metadata

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

the class AbstractServerStreamTest method close_sendTrailersClearsReservedFields.

@Test
public void close_sendTrailersClearsReservedFields() {
    // stream actually mutates trailers, so we can't check that the fields here are the same as
    // the captured ones.
    Metadata trailers = new Metadata();
    trailers.put(Status.CODE_KEY, Status.OK);
    trailers.put(Status.MESSAGE_KEY, "Everything's super.");
    stream.close(Status.INTERNAL.withDescription("bad"), trailers);
    verify(sink).writeTrailers(metadataCaptor.capture(), eq(false));
    assertEquals(Status.Code.INTERNAL, metadataCaptor.getValue().get(Status.CODE_KEY).getCode());
    assertEquals("bad", metadataCaptor.getValue().get(Status.MESSAGE_KEY));
}
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