Search in sources :

Example 81 with Metadata

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

the class NettyClientStreamTest method removeUserAgentFromApplicationHeaders.

@Test
public void removeUserAgentFromApplicationHeaders() {
    Metadata metadata = new Metadata();
    metadata.put(GrpcUtil.USER_AGENT_KEY, "bad agent");
    listener = mock(ClientStreamListener.class);
    Mockito.reset(writeQueue);
    when(writeQueue.enqueue(any(QueuedCommand.class), any(boolean.class))).thenReturn(future);
    stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), methodDescriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("good agent"), StatsTraceContext.NOOP);
    stream.start(listener);
    ArgumentCaptor<CreateStreamCommand> cmdCap = ArgumentCaptor.forClass(CreateStreamCommand.class);
    verify(writeQueue).enqueue(cmdCap.capture(), eq(false));
    assertThat(ImmutableListMultimap.copyOf(cmdCap.getValue().headers())).containsEntry(Utils.USER_AGENT, AsciiString.of("good agent"));
}
Also used : ClientStreamListener(io.grpc.internal.ClientStreamListener) Metadata(io.grpc.Metadata) QueuedCommand(io.grpc.netty.WriteQueue.QueuedCommand) Test(org.junit.Test)

Example 82 with Metadata

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

the class NettyClientStreamTest method setStatusWithErrorShouldNotOverridePreviousError.

@Test
public void setStatusWithErrorShouldNotOverridePreviousError() {
    Status errorStatus = Status.INTERNAL;
    stream().transportState().transportReportStatus(errorStatus, true, new Metadata());
    stream().transportState().transportReportStatus(Status.fromThrowable(new RuntimeException("fake")), true, new Metadata());
    verify(listener).closed(any(Status.class), any(Metadata.class));
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 83 with Metadata

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

the class NettyClientStreamTest method setStatusWithOkShouldNotOverrideError.

@Test
public void setStatusWithOkShouldNotOverrideError() {
    Status errorStatus = Status.INTERNAL;
    stream().transportState().transportReportStatus(errorStatus, true, new Metadata());
    stream().transportState().transportReportStatus(Status.OK, true, new Metadata());
    verify(listener).closed(any(Status.class), any(Metadata.class));
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 84 with Metadata

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

the class NettyClientTransportTest method overrideDefaultUserAgent.

@Test
public void overrideDefaultUserAgent() throws Exception {
    startServer();
    NettyClientTransport transport = newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, "testUserAgent", true);
    callMeMaybe(transport.start(clientTransportListener));
    new Rpc(transport, new Metadata()).halfClose().waitForResponse();
    // Verify that the received headers contained the User-Agent.
    assertEquals(1, serverListener.streamListeners.size());
    Metadata receivedHeaders = serverListener.streamListeners.get(0).headers;
    assertEquals(GrpcUtil.getGrpcUserAgent("netty", "testUserAgent"), receivedHeaders.get(USER_AGENT_KEY));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 85 with Metadata

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

the class NettyClientTransportTest method addDefaultUserAgent.

@Test
public void addDefaultUserAgent() throws Exception {
    startServer();
    NettyClientTransport transport = newTransport(newNegotiator());
    callMeMaybe(transport.start(clientTransportListener));
    // Send a single RPC and wait for the response.
    new Rpc(transport).halfClose().waitForResponse();
    // Verify that the received headers contained the User-Agent.
    assertEquals(1, serverListener.streamListeners.size());
    Metadata headers = serverListener.streamListeners.get(0).headers;
    assertEquals(GrpcUtil.getGrpcUserAgent("netty", null), headers.get(USER_AGENT_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