Search in sources :

Example 36 with Metadata

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

the class AbstractClientStreamTest method rstStreamClosesStream.

@Test
public void rstStreamClosesStream() {
    AbstractClientStream stream = new BaseAbstractClientStream(allocator);
    stream.start(mockListener);
    // The application will call request when waiting for a message, which will in turn call this
    // on the transport thread.
    stream.requestMessagesFromDeframer(1);
    // Send first byte of 2 byte message
    stream.deframe(ReadableBuffers.wrap(new byte[] { 0, 0, 0, 0, 2, 1 }), false);
    Status status = Status.INTERNAL;
    // Simulate getting a reset
    stream.transportReportStatus(status, false, /*stop delivery*/
    new Metadata());
    assertTrue(stream.isClosed());
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 37 with Metadata

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

the class AbstractClientStreamTest method inboundHeadersReceived_acceptsIdentityEncoding.

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

Example 38 with Metadata

use of 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);
    stream.start(mockListener);
    Metadata headers = new Metadata();
    stream.inboundHeadersReceived(headers);
    verify(mockListener).headersRead(headers);
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 39 with Metadata

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

the class AbstractClientStreamTest method inboundHeadersReceived_failsOnPhaseStatus.

@Test
public void inboundHeadersReceived_failsOnPhaseStatus() {
    AbstractClientStream stream = new BaseAbstractClientStream(allocator);
    stream.start(mockListener);
    Metadata headers = new Metadata();
    stream.inboundPhase(Phase.STATUS);
    thrown.expect(IllegalStateException.class);
    stream.inboundHeadersReceived(headers);
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 40 with Metadata

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

the class AbstractClientStreamTest method cancel_notifiesOnlyOnce.

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

        @Override
        protected void sendCancel(Status errorStatus) {
            transportReportStatus(errorStatus, true, /*stop delivery*/
            new Metadata());
        }
    };
    stream.start(mockListener);
    stream.cancel(Status.DEADLINE_EXCEEDED);
    verify(mockListener).closed(isA(Status.class), isA(Metadata.class));
}
Also used : Status(io.grpc.Status) 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