Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
"io.perfmark:perfmark-api:0.27.0",
"junit:junit:4.13.2",
"org.mockito:mockito-core:4.4.0",
"org.checkerframework:checker-qual:3.49.5",
"org.codehaus.mojo:animal-sniffer-annotations:1.26",
]
Expand Down
18 changes: 18 additions & 0 deletions api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@ java_library(
artifact("com.google.guava:guava"),
],
)

java_library(
name = "test_fixtures",
testonly = 1,
srcs = glob([
"src/testFixtures/java/io/grpc/**/*.java",
]),
visibility = ["//xds:__pkg__"],
deps = [
"//core",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.truth:truth"),
artifact("junit:junit"),
artifact("org.mockito:mockito-core"),
],
)
1 change: 1 addition & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
"io.perfmark:perfmark-api:0.27.0",
"junit:junit:4.13.2",
"org.mockito:mockito-core:4.4.0",
"org.checkerframework:checker-qual:3.49.5",
"org.codehaus.mojo:animal-sniffer-annotations:1.26",
]
Expand Down
1 change: 1 addition & 0 deletions xds/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ java_library(
":xds",
":xds_java_proto",
"//api",
"//api:test_fixtures",
"//core:internal",
"//stub",
"//testing-proto:simpleservice_java_grpc",
Expand Down
11 changes: 10 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ final class XdsNameResolver extends NameResolver {
private CallCounterProvider callCounterProvider;
private ResolveState resolveState;

/**
* Constructs a new instance.
*
* @param target the target URI to resolve
* @param targetAuthority the authority component of `target`, possibly the empty string, or null
* if 'target' has no such component
*/
XdsNameResolver(
String target, @Nullable String targetAuthority, String name,
@Nullable String overrideAuthority, ServiceConfigParser serviceConfigParser,
Expand Down Expand Up @@ -208,7 +215,9 @@ public void start(Listener2 listener) {
}
BootstrapInfo bootstrapInfo = xdsClient.getBootstrapInfo();
String listenerNameTemplate;
if (targetAuthority == null) {
if (targetAuthority == null || targetAuthority.isEmpty()) {
// Both https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md and
// A47-xds-federation.md seem to treat an empty authority the same as an undefined one.
listenerNameTemplate = bootstrapInfo.clientDefaultListenerResourceNameTemplate();
} else {
AuthorityInfo authorityInfo = bootstrapInfo.authorities().get(targetAuthority);
Expand Down
6 changes: 5 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsNameResolverProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public XdsNameResolver newNameResolver(URI targetUri, Args args) {
targetPath,
targetUri);
String name = targetPath.substring(1);
return newNameResolver(targetUri.toString(), targetUri.getAuthority(), name, args);
// TODO(jdcormie): java.net.URI#getAuthority incorrectly returns null for both xds:///service
// and xds:/service. This doesn't matter for now since XdsNameResolver treats them the same
// anyway and all this code will go away once newNameResolver(io.grpc.Uri) launches.
String targetAuthority = targetUri.getAuthority();
return newNameResolver(targetUri.toString(), targetAuthority, name, args);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.ClientStreamTracer;
import io.grpc.FlagResetRule;
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
import io.grpc.ForwardingClientCallListener;
import io.grpc.InternalFeatureFlags;
import io.grpc.LoadBalancerRegistry;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
Expand All @@ -60,10 +62,14 @@
import io.grpc.testing.protobuf.SimpleResponse;
import io.grpc.testing.protobuf.SimpleServiceGrpc;
import java.net.InetSocketAddress;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

/**
* Xds integration tests using a local control plane, implemented in {@link
Expand All @@ -85,13 +91,28 @@
* 3) Construct EDS config w/ test server address from 2). Set CDS and EDS Config at the Control
* Plane. Then start the test xDS client (requires EDS to do xDS name resolution).
*/
@RunWith(JUnit4.class)
@RunWith(Parameterized.class)
public class FakeControlPlaneXdsIntegrationTest {

@Rule(order = 0)
public ControlPlaneRule controlPlane = new ControlPlaneRule();
@Rule(order = 1)
public DataPlaneRule dataPlane = new DataPlaneRule(controlPlane);
@Rule(order = 2)
public final FlagResetRule flagResetRule = new FlagResetRule();

@Parameters(name = "enableRfc3986UrisParam={0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {{true}, {false}});
}

@Parameter public boolean enableRfc3986UrisParam;

@Before
public void setupRfc3986UrisFeatureFlag() throws Exception {
flagResetRule.setFlagForTest(
InternalFeatureFlags::setRfc3986UrisEnabled, enableRfc3986UrisParam);
}

@Test
public void pingPong() throws Exception {
Expand Down
34 changes: 34 additions & 0 deletions xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,40 @@ public void resolving_noTargetAuthority_templateWithoutXdstp() {
verify(mockListener, never()).onError(any(Status.class));
}

@Test
public void resolving_emptyTargetAuthority_templateWithXdstp() {
bootstrapInfo =
BootstrapInfo.builder()
.servers(
ImmutableList.of(
ServerInfo.create("td.googleapis.com", InsecureChannelCredentials.create())))
.node(Node.newBuilder().build())
.clientDefaultListenerResourceNameTemplate(
"xdstp://xds.authority.com/envoy.config.listener.v3.Listener/%s?id=1")
.build();
String serviceAuthority = "[::FFFF:129.144.52.38]:80";
expectedLdsResourceName =
"xdstp://xds.authority.com/envoy.config.listener.v3.Listener/"
+ "%5B::FFFF:129.144.52.38%5D:80?id=1";
resolver =
new XdsNameResolver(
"xds:///foo.googleapis.com",
"",
serviceAuthority,
null,
serviceConfigParser,
syncContext,
scheduler,
xdsClientPoolFactory,
mockRandom,
FilterRegistry.getDefaultRegistry(),
rawBootstrap,
metricRecorder,
nameResolverArgs);
resolver.start(mockListener);
verify(mockListener, never()).onError(any(Status.class));
}

@Test
public void resolving_noTargetAuthority_templateWithXdstp() {
bootstrapInfo = BootstrapInfo.builder()
Expand Down
Loading