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"));
}
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));
}
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));
}
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));
}
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));
}
Aggregations