@@ -125,6 +125,10 @@ public void tearDown() {
125
125
}
126
126
127
127
private void createResolver () {
128
+ createResolver ("1:1:1" );
129
+ }
130
+
131
+ private void createResolver (String responseToIpV6 ) {
128
132
HttpConnectionProvider httpConnections = new HttpConnectionProvider () {
129
133
@ Override
130
134
public HttpURLConnection createConnection (String url ) throws IOException {
@@ -135,6 +139,10 @@ public HttpURLConnection createConnection(String url) throws IOException {
135
139
new ByteArrayInputStream (("/" + ZONE ).getBytes (StandardCharsets .UTF_8 )));
136
140
return con ;
137
141
} else if (url .equals (GoogleCloudToProdNameResolver .METADATA_URL_SUPPORT_IPV6 )) {
142
+ if (responseToIpV6 != null ) {
143
+ when (con .getInputStream ()).thenReturn (
144
+ new ByteArrayInputStream (responseToIpV6 .getBytes (StandardCharsets .UTF_8 )));
145
+ }
138
146
return con ;
139
147
}
140
148
throw new AssertionError ("Unknown http query" );
@@ -147,7 +155,7 @@ public HttpURLConnection createConnection(String url) throws IOException {
147
155
}
148
156
149
157
@ Test
150
- public void notOnGcpDelegateToDns () {
158
+ public void notOnGcp_DelegateToDns () {
151
159
GoogleCloudToProdNameResolver .isOnGcp = false ;
152
160
createResolver ();
153
161
resolver .start (mockListener );
@@ -156,7 +164,7 @@ public void notOnGcpDelegateToDns() {
156
164
}
157
165
158
166
@ Test
159
- public void hasProvidedBootstrapDelegateToDns () {
167
+ public void hasProvidedBootstrap_DelegateToDns () {
160
168
GoogleCloudToProdNameResolver .isOnGcp = true ;
161
169
GoogleCloudToProdNameResolver .xdsBootstrapProvided = true ;
162
170
GoogleCloudToProdNameResolver .enableFederation = false ;
@@ -168,7 +176,7 @@ public void hasProvidedBootstrapDelegateToDns() {
168
176
169
177
@ SuppressWarnings ("unchecked" )
170
178
@ Test
171
- public void onGcpAndNoProvidedBootstrapDelegateToXds () {
179
+ public void onGcpAndNoProvidedBootstrap_DelegateToXds () {
172
180
GoogleCloudToProdNameResolver .isOnGcp = true ;
173
181
GoogleCloudToProdNameResolver .xdsBootstrapProvided = false ;
174
182
createResolver ();
@@ -196,7 +204,51 @@ public void onGcpAndNoProvidedBootstrapDelegateToXds() {
196
204
197
205
@ SuppressWarnings ("unchecked" )
198
206
@ Test
199
- public void onGcpAndNoProvidedBootstrapAndFederationEnabledDelegateToXds () {
207
+ public void onGcpAndNoProvidedBootstrap_DelegateToXds_noIpV6 () {
208
+ GoogleCloudToProdNameResolver .isOnGcp = true ;
209
+ GoogleCloudToProdNameResolver .xdsBootstrapProvided = false ;
210
+ createResolver (null );
211
+ resolver .start (mockListener );
212
+ fakeExecutor .runDueTasks ();
213
+ assertThat (delegatedResolver .keySet ()).containsExactly ("xds" );
214
+ verify (Iterables .getOnlyElement (delegatedResolver .values ())).start (mockListener );
215
+ Map <String , ?> bootstrap = fakeBootstrapSetter .bootstrapRef .get ();
216
+ Map <String , ?> node = (Map <String , ?>) bootstrap .get ("node" );
217
+ assertThat (node ).containsExactly (
218
+ "id" , "C2P-991614323" ,
219
+ "locality" , ImmutableMap .of ("zone" , ZONE ));
220
+ Map <String , ?> server = Iterables .getOnlyElement (
221
+ (List <Map <String , ?>>) bootstrap .get ("xds_servers" ));
222
+ assertThat (server ).containsExactly (
223
+ "server_uri" , "directpath-pa.googleapis.com" ,
224
+ "channel_creds" , ImmutableList .of (ImmutableMap .of ("type" , "google_default" )),
225
+ "server_features" , ImmutableList .of ("xds_v3" , "ignore_resource_deletion" ));
226
+ Map <String , ?> authorities = (Map <String , ?>) bootstrap .get ("authorities" );
227
+ assertThat (authorities ).containsExactly (
228
+ "traffic-director-c2p.xds.googleapis.com" ,
229
+ ImmutableMap .of ("xds_servers" , ImmutableList .of (server )));
230
+ }
231
+
232
+ @ SuppressWarnings ("unchecked" )
233
+ @ Test
234
+ public void emptyResolverMeetadataValue () {
235
+ GoogleCloudToProdNameResolver .isOnGcp = true ;
236
+ GoogleCloudToProdNameResolver .xdsBootstrapProvided = false ;
237
+ createResolver ("" );
238
+ resolver .start (mockListener );
239
+ fakeExecutor .runDueTasks ();
240
+ assertThat (delegatedResolver .keySet ()).containsExactly ("xds" );
241
+ verify (Iterables .getOnlyElement (delegatedResolver .values ())).start (mockListener );
242
+ Map <String , ?> bootstrap = fakeBootstrapSetter .bootstrapRef .get ();
243
+ Map <String , ?> node = (Map <String , ?>) bootstrap .get ("node" );
244
+ assertThat (node ).containsExactly (
245
+ "id" , "C2P-991614323" ,
246
+ "locality" , ImmutableMap .of ("zone" , ZONE ));
247
+ }
248
+
249
+ @ SuppressWarnings ("unchecked" )
250
+ @ Test
251
+ public void onGcpAndNoProvidedBootstrapAndFederationEnabled_DelegateToXds () {
200
252
GoogleCloudToProdNameResolver .isOnGcp = true ;
201
253
GoogleCloudToProdNameResolver .xdsBootstrapProvided = false ;
202
254
GoogleCloudToProdNameResolver .enableFederation = true ;
@@ -226,7 +278,7 @@ public void onGcpAndNoProvidedBootstrapAndFederationEnabledDelegateToXds() {
226
278
227
279
@ SuppressWarnings ("unchecked" )
228
280
@ Test
229
- public void onGcpAndProvidedBootstrapAndFederationEnabledDontDelegateToXds () {
281
+ public void onGcpAndProvidedBootstrapAndFederationEnabled_DontDelegateToXds () {
230
282
GoogleCloudToProdNameResolver .isOnGcp = true ;
231
283
GoogleCloudToProdNameResolver .xdsBootstrapProvided = true ;
232
284
GoogleCloudToProdNameResolver .enableFederation = true ;
0 commit comments