From 4289fba7d1c81a3ea7cde428f06f2ae721e1f31c Mon Sep 17 00:00:00 2001 From: jyane Date: Mon, 11 Dec 2017 01:40:46 +0900 Subject: [PATCH] core: support user-agent in InProcess --- .../java/io/grpc/inprocess/InProcessChannelBuilder.java | 2 +- .../main/java/io/grpc/inprocess/InProcessTransport.java | 8 +++++++- .../java/io/grpc/inprocess/InProcessTransportTest.java | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java index 41bd6b8e1d7..5a86ab525c1 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java @@ -142,7 +142,7 @@ public ConnectionClientTransport newClientTransport( if (closed) { throw new IllegalStateException("The transport factory is closed."); } - return new InProcessTransport(name, authority); + return new InProcessTransport(name, authority, userAgent); } @Override diff --git a/core/src/main/java/io/grpc/inprocess/InProcessTransport.java b/core/src/main/java/io/grpc/inprocess/InProcessTransport.java index ef80a8a6a80..4c9174e0920 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessTransport.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessTransport.java @@ -34,6 +34,7 @@ import io.grpc.internal.ClientStream; import io.grpc.internal.ClientStreamListener; import io.grpc.internal.ConnectionClientTransport; +import io.grpc.internal.GrpcUtil; import io.grpc.internal.ManagedClientTransport; import io.grpc.internal.NoopClientStream; import io.grpc.internal.ObjectPool; @@ -66,6 +67,7 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans private final InternalLogId logId = InternalLogId.allocate(getClass().getName()); private final String name; private final String authority; + private final String userAgent; private ObjectPool serverSchedulerPool; private ScheduledExecutorService serverScheduler; private ServerTransportListener serverTransportListener; @@ -82,9 +84,10 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans @GuardedBy("this") private List serverStreamTracerFactories; - public InProcessTransport(String name, String authority) { + public InProcessTransport(String name, String authority, String userAgent) { this.name = name; this.authority = authority; + this.userAgent = userAgent; } @CheckReturnValue @@ -143,6 +146,9 @@ public void start(ClientStreamListener listener) { } }; } + headers.put( + GrpcUtil.USER_AGENT_KEY, + GrpcUtil.getGrpcUserAgent("inprocess", userAgent)); return new InProcessStream(method, headers, callOptions, authority).clientStream; } diff --git a/core/src/test/java/io/grpc/inprocess/InProcessTransportTest.java b/core/src/test/java/io/grpc/inprocess/InProcessTransportTest.java index 31f1ecfd14f..2c1d6715021 100644 --- a/core/src/test/java/io/grpc/inprocess/InProcessTransportTest.java +++ b/core/src/test/java/io/grpc/inprocess/InProcessTransportTest.java @@ -30,6 +30,7 @@ public class InProcessTransportTest extends AbstractTransportTest { private static final String TRANSPORT_NAME = "perfect-for-testing"; private static final String AUTHORITY = "a-testing-authority"; + private static final String USER_AGENT = "a-testing-user-agent"; @Override protected InternalServer newServer(List streamTracerFactories) { @@ -49,7 +50,7 @@ protected String testAuthority(InternalServer server) { @Override protected ManagedClientTransport newClientTransport(InternalServer server) { - return new InProcessTransport(TRANSPORT_NAME, testAuthority(server)); + return new InProcessTransport(TRANSPORT_NAME, testAuthority(server), USER_AGENT); } @Override