Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: override bootstrap for xds server #8575

Merged
merged 5 commits into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsServerBuilder.java
Expand Up @@ -37,6 +37,7 @@
import io.grpc.netty.NettyServerBuilder;
import io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingNegotiatorServerFactory;
import io.grpc.xds.XdsNameResolverProvider.XdsClientPoolFactory;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
Expand Down Expand Up @@ -136,6 +137,18 @@ XdsServerBuilder xdsClientPoolFactory(XdsClientPoolFactory xdsClientPoolFactory)
return this;
}

/**
* Allows providing bootstrap override, useful for testing.
*/
public XdsServerBuilder overrideBootstrapForTest(Map<String, ?> bootstrapOverride) {
checkNotNull(bootstrapOverride, "bootstrapOverride");
if (this.xdsClientPoolFactory == SharedXdsClientPoolProvider.getDefaultProvider()) {
this.xdsClientPoolFactory = new SharedXdsClientPoolProvider();
}
this.xdsClientPoolFactory.setBootstrapOverride(bootstrapOverride);
return this;
}

/**
* Returns the delegate {@link NettyServerBuilder} to allow experimental level
* transport-specific configuration. Note this API will always be experimental.
Expand Down
13 changes: 12 additions & 1 deletion xds/src/test/java/io/grpc/xds/XdsServerBuilderTest.java
Expand Up @@ -40,7 +40,9 @@
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.SocketAddress;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand All @@ -65,6 +67,7 @@ public class XdsServerBuilderTest {
private int port;
private TlsContextManager tlsContextManager;
private FakeXdsClient xdsClient = new FakeXdsClient();
private FakeXdsClientPoolFactory xdsClientPoolFactory = new FakeXdsClientPoolFactory(xdsClient);

private void buildServer(XdsServerBuilder.XdsServingStatusListener xdsServingStatusListener)
throws IOException {
Expand All @@ -77,7 +80,7 @@ private void buildBuilder(XdsServerBuilder.XdsServingStatusListener xdsServingSt
builder =
XdsServerBuilder.forPort(
port, XdsServerCredentials.create(InsecureServerCredentials.create()));
builder.xdsClientPoolFactory(new FakeXdsClientPoolFactory(xdsClient));
builder.xdsClientPoolFactory(xdsClientPoolFactory);
if (xdsServingStatusListener != null) {
builder.xdsServingStatusListener(xdsServingStatusListener);
}
Expand Down Expand Up @@ -292,4 +295,12 @@ public void drainGraceTime_negativeThrows() throws IOException {
assertThat(expected).hasMessageThat().contains("drain grace time");
}
}

@Test
public void testOverrideBootstrap() throws Exception {
Map<String, Object> b = new HashMap<>();
buildBuilder(null);
builder.overrideBootstrapForTest(b);
assertThat(xdsClientPoolFactory.savedBootstrap).isEqualTo(b);
}
}
3 changes: 2 additions & 1 deletion xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java
Expand Up @@ -113,14 +113,15 @@ static final class FakeXdsClientPoolFactory
implements XdsNameResolverProvider.XdsClientPoolFactory {

private XdsClient xdsClient;
Map<String, ?> savedBootstrap;

FakeXdsClientPoolFactory(XdsClient xdsClient) {
this.xdsClient = xdsClient;
}

@Override
public void setBootstrapOverride(Map<String, ?> bootstrap) {
throw new UnsupportedOperationException("Should not be called");
this.savedBootstrap = bootstrap;
}

@Override
Expand Down