Skip to content

Commit

Permalink
core: support user-agent in InProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
jyane committed Dec 11, 2017
1 parent 8bcb5cf commit 4289fba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/io/grpc/inprocess/InProcessTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ScheduledExecutorService> serverSchedulerPool;
private ScheduledExecutorService serverScheduler;
private ServerTransportListener serverTransportListener;
Expand All @@ -82,9 +84,10 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
@GuardedBy("this")
private List<ServerStreamTracer.Factory> 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
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerStreamTracer.Factory> streamTracerFactories) {
Expand All @@ -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
Expand Down

0 comments on commit 4289fba

Please sign in to comment.