Skip to content

Commit 7ff7890

Browse files
committed
Allow unit test to pass CacheChannelManager for in-process channel.
1 parent f1ea3ec commit 7ff7890

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

xds/src/main/java/io/grpc/xds/ExternalProcessorFilter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.grpc.ClientInterceptor;
2121
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
2222
import io.grpc.ForwardingClientCallListener;
23+
import io.grpc.ManagedChannel;
2324
import io.grpc.Metadata;
2425
import io.grpc.MethodDescriptor;
2526
import io.grpc.Status;
@@ -124,7 +125,7 @@ public String typeUrl() {
124125
}
125126

126127
static final class ExternalProcessorInterceptor implements ClientInterceptor {
127-
private final CachedChannelManager cachedChannelManager = new CachedChannelManager();
128+
private final CachedChannelManager cachedChannelManager;
128129
private final ExternalProcessorFilterConfig filterConfig;
129130

130131
private static final MethodDescriptor.Marshaller<InputStream> RAW_MARSHALLER =
@@ -136,7 +137,13 @@ static final class ExternalProcessorInterceptor implements ClientInterceptor {
136137
};
137138

138139
ExternalProcessorInterceptor(ExternalProcessorFilterConfig filterConfig) {
140+
this(filterConfig, new CachedChannelManager());
141+
}
142+
143+
ExternalProcessorInterceptor(ExternalProcessorFilterConfig filterConfig,
144+
CachedChannelManager cachedChannelManager) {
139145
this.filterConfig = filterConfig;
146+
this.cachedChannelManager = checkNotNull(cachedChannelManager, "cachedChannelManager");
140147
}
141148

142149
@Override

xds/src/test/java/io/grpc/xds/ExternalProcessorFilterTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232
import io.grpc.stub.StreamObserver;
3333
import io.grpc.testing.GrpcCleanupRule;
3434
import io.grpc.util.MutableHandlerRegistry;
35-
import io.grpc.xds.internal.grpcservice.ChannelCredsConfig;
35+
import io.grpc.xds.ExternalProcessorFilter.ExternalProcessorFilterConfig;
36+
import io.grpc.xds.ExternalProcessorFilter.ExternalProcessorInterceptor;
37+
import io.grpc.xds.internal.grpcservice.CachedChannelManager;
3638
import io.grpc.xds.internal.grpcservice.ConfiguredChannelCredentials;
3739
import io.grpc.xds.internal.grpcservice.GrpcServiceXdsContext;
3840
import io.grpc.xds.internal.grpcservice.GrpcServiceXdsContextProvider;
41+
import io.grpc.xds.internal.grpcservice.ChannelCredsConfig;
3942
import java.io.ByteArrayInputStream;
4043
import java.io.InputStream;
4144
import java.util.ArrayList;
@@ -116,11 +119,10 @@ public void setUp() throws Exception {
116119
InProcessChannelBuilder.forName(dataPlaneServerName).directExecutor().build());
117120
}
118121

119-
private ExternalProcessorFilter.ExternalProcessorFilterConfig createFilterConfig() {
122+
private ExternalProcessorFilterConfig createFilterConfig() {
120123
GrpcService grpcService = GrpcService.newBuilder()
121124
.setGoogleGrpc(GrpcService.GoogleGrpc.newBuilder()
122-
// Important: Use "in-process:" scheme so Grpc.newChannelBuilder resolves it correctly
123-
.setTargetUri("in-process:" + extProcServerName)
125+
.setTargetUri(extProcServerName)
124126
.setStatPrefix("ext_proc")
125127
.build())
126128
.build();
@@ -152,7 +154,7 @@ private ExternalProcessorFilter.ExternalProcessorFilterConfig createFilterConfig
152154
this.filter = provider.newInstance("ext-proc", contextProvider);
153155

154156
// 2. Parse the config using the provider
155-
ConfigOrError<ExternalProcessorFilter.ExternalProcessorFilterConfig> configOrError =
157+
ConfigOrError<ExternalProcessorFilterConfig> configOrError =
156158
provider.parseFilterConfig(Any.pack(externalProcessor));
157159

158160
assertThat(configOrError.errorDetail).isNull();
@@ -161,10 +163,14 @@ private ExternalProcessorFilter.ExternalProcessorFilterConfig createFilterConfig
161163

162164
@Test
163165
public void requestHeadersMutated() throws Exception {
164-
ExternalProcessorFilter.ExternalProcessorFilterConfig filterConfig = createFilterConfig();
166+
ExternalProcessorFilterConfig filterConfig = createFilterConfig();
165167

166-
// Use the filter instance created in createFilterConfig()
167-
ClientInterceptor interceptor = filter.buildClientInterceptor(filterConfig, null, null);
168+
// Manually create the interceptor using the test-friendly constructor
169+
CachedChannelManager testChannelManager = new CachedChannelManager(config ->
170+
grpcCleanup.register(InProcessChannelBuilder.forName(extProcServerName).directExecutor().build())
171+
);
172+
ClientInterceptor interceptor = new ExternalProcessorInterceptor(filterConfig, testChannelManager);
173+
168174
Channel interceptedChannel = ClientInterceptors.intercept(dataPlaneChannel, interceptor);
169175

170176
// Data Plane Server

0 commit comments

Comments
 (0)