forked from grpc/grpc-java
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XdsClientImplTest.java
3754 lines (3299 loc) · 171 KB
/
XdsClientImplTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.xds;
import static com.google.common.truth.Truth.assertThat;
import static io.grpc.xds.XdsClientTestHelper.buildCluster;
import static io.grpc.xds.XdsClientTestHelper.buildClusterLoadAssignment;
import static io.grpc.xds.XdsClientTestHelper.buildDiscoveryRequest;
import static io.grpc.xds.XdsClientTestHelper.buildDiscoveryResponse;
import static io.grpc.xds.XdsClientTestHelper.buildDropOverload;
import static io.grpc.xds.XdsClientTestHelper.buildLbEndpoint;
import static io.grpc.xds.XdsClientTestHelper.buildListener;
import static io.grpc.xds.XdsClientTestHelper.buildLocalityLbEndpoints;
import static io.grpc.xds.XdsClientTestHelper.buildRouteConfiguration;
import static io.grpc.xds.XdsClientTestHelper.buildSecureCluster;
import static io.grpc.xds.XdsClientTestHelper.buildUpstreamTlsContext;
import static io.grpc.xds.XdsClientTestHelper.buildVirtualHost;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Any;
import com.google.protobuf.UInt32Value;
import com.google.protobuf.util.Durations;
import io.envoyproxy.envoy.api.v2.ClusterLoadAssignment;
import io.envoyproxy.envoy.api.v2.ClusterLoadAssignment.Policy;
import io.envoyproxy.envoy.api.v2.DiscoveryRequest;
import io.envoyproxy.envoy.api.v2.DiscoveryResponse;
import io.envoyproxy.envoy.api.v2.RouteConfiguration;
import io.envoyproxy.envoy.api.v2.auth.UpstreamTlsContext;
import io.envoyproxy.envoy.api.v2.core.AggregatedConfigSource;
import io.envoyproxy.envoy.api.v2.core.ConfigSource;
import io.envoyproxy.envoy.api.v2.core.HealthStatus;
import io.envoyproxy.envoy.api.v2.core.Node;
import io.envoyproxy.envoy.api.v2.endpoint.ClusterStats;
import io.envoyproxy.envoy.api.v2.route.RedirectAction;
import io.envoyproxy.envoy.api.v2.route.Route;
import io.envoyproxy.envoy.api.v2.route.RouteAction;
import io.envoyproxy.envoy.api.v2.route.RouteMatch;
import io.envoyproxy.envoy.api.v2.route.VirtualHost;
import io.envoyproxy.envoy.api.v2.route.WeightedCluster;
import io.envoyproxy.envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager;
import io.envoyproxy.envoy.config.filter.network.http_connection_manager.v2.Rds;
import io.envoyproxy.envoy.service.discovery.v2.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase;
import io.envoyproxy.envoy.service.load_stats.v2.LoadReportingServiceGrpc.LoadReportingServiceImplBase;
import io.envoyproxy.envoy.service.load_stats.v2.LoadStatsRequest;
import io.envoyproxy.envoy.service.load_stats.v2.LoadStatsResponse;
import io.grpc.Context;
import io.grpc.Context.CancellationListener;
import io.grpc.ManagedChannel;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.SynchronizationContext;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.internal.BackoffPolicy;
import io.grpc.internal.FakeClock;
import io.grpc.internal.FakeClock.ScheduledTask;
import io.grpc.internal.FakeClock.TaskFilter;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.Bootstrapper.ChannelCreds;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.DropOverload;
import io.grpc.xds.EnvoyProtoData.LbEndpoint;
import io.grpc.xds.EnvoyProtoData.Locality;
import io.grpc.xds.EnvoyProtoData.LocalityLbEndpoints;
import io.grpc.xds.XdsClient.ClusterUpdate;
import io.grpc.xds.XdsClient.ClusterWatcher;
import io.grpc.xds.XdsClient.ConfigUpdate;
import io.grpc.xds.XdsClient.ConfigWatcher;
import io.grpc.xds.XdsClient.EndpointUpdate;
import io.grpc.xds.XdsClient.EndpointWatcher;
import io.grpc.xds.XdsClient.XdsChannelFactory;
import io.grpc.xds.XdsClientImpl.MessagePrinter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
/**
* Tests for {@link XdsClientImpl}.
*/
@RunWith(JUnit4.class)
public class XdsClientImplTest {
private static final String TARGET_AUTHORITY = "foo.googleapis.com:8080";
private static final Node NODE = Node.getDefaultInstance();
private static final FakeClock.TaskFilter RPC_RETRY_TASK_FILTER =
new FakeClock.TaskFilter() {
@Override
public boolean shouldAccept(Runnable command) {
return command.toString().contains(XdsClientImpl.RpcRetryTask.class.getSimpleName());
}
};
private static final FakeClock.TaskFilter LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER =
new TaskFilter() {
@Override
public boolean shouldAccept(Runnable command) {
return command.toString()
.contains(XdsClientImpl.LdsResourceFetchTimeoutTask.class.getSimpleName());
}
};
private static final FakeClock.TaskFilter RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER =
new TaskFilter() {
@Override
public boolean shouldAccept(Runnable command) {
return command.toString()
.contains(XdsClientImpl.RdsResourceFetchTimeoutTask.class.getSimpleName());
}
};
private static final FakeClock.TaskFilter CDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER =
new TaskFilter() {
@Override
public boolean shouldAccept(Runnable command) {
return command.toString()
.contains(XdsClientImpl.CdsResourceFetchTimeoutTask.class.getSimpleName());
}
};
private static final FakeClock.TaskFilter EDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER =
new FakeClock.TaskFilter() {
@Override
public boolean shouldAccept(Runnable command) {
return command.toString()
.contains(XdsClientImpl.EdsResourceFetchTimeoutTask.class.getSimpleName());
}
};
@Rule
public final GrpcCleanupRule cleanupRule = new GrpcCleanupRule();
private final SynchronizationContext syncContext = new SynchronizationContext(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new AssertionError(e);
}
});
private final FakeClock fakeClock = new FakeClock();
private final Queue<StreamObserver<DiscoveryResponse>> responseObservers = new ArrayDeque<>();
private final Queue<StreamObserver<DiscoveryRequest>> requestObservers = new ArrayDeque<>();
private final AtomicBoolean adsEnded = new AtomicBoolean(true);
private final Queue<LoadReportCall> loadReportCalls = new ArrayDeque<>();
private final AtomicBoolean lrsEnded = new AtomicBoolean(true);
@Mock
private AggregatedDiscoveryServiceImplBase mockedDiscoveryService;
@Mock
private BackoffPolicy.Provider backoffPolicyProvider;
@Mock
private BackoffPolicy backoffPolicy1;
@Mock
private BackoffPolicy backoffPolicy2;
@Mock
private ConfigWatcher configWatcher;
@Mock
private ClusterWatcher clusterWatcher;
@Mock
private EndpointWatcher endpointWatcher;
private ManagedChannel channel;
private XdsClientImpl xdsClient;
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
when(backoffPolicy1.nextBackoffNanos()).thenReturn(10L, 100L);
when(backoffPolicy2.nextBackoffNanos()).thenReturn(20L, 200L);
final String serverName = InProcessServerBuilder.generateName();
AggregatedDiscoveryServiceImplBase adsServiceImpl = new AggregatedDiscoveryServiceImplBase() {
@Override
public StreamObserver<DiscoveryRequest> streamAggregatedResources(
final StreamObserver<DiscoveryResponse> responseObserver) {
assertThat(adsEnded.get()).isTrue(); // ensure previous call was ended
adsEnded.set(false);
Context.current().addListener(
new CancellationListener() {
@Override
public void cancelled(Context context) {
adsEnded.set(true);
}
}, MoreExecutors.directExecutor());
responseObservers.offer(responseObserver);
@SuppressWarnings("unchecked")
StreamObserver<DiscoveryRequest> requestObserver = mock(StreamObserver.class);
requestObservers.offer(requestObserver);
return requestObserver;
}
};
mockedDiscoveryService =
mock(AggregatedDiscoveryServiceImplBase.class, delegatesTo(adsServiceImpl));
LoadReportingServiceImplBase lrsServiceImpl = new LoadReportingServiceImplBase() {
@Override
public StreamObserver<LoadStatsRequest> streamLoadStats(
StreamObserver<LoadStatsResponse> responseObserver) {
assertThat(lrsEnded.get()).isTrue();
lrsEnded.set(false);
@SuppressWarnings("unchecked")
StreamObserver<LoadStatsRequest> requestObserver = mock(StreamObserver.class);
final LoadReportCall call = new LoadReportCall(requestObserver, responseObserver);
Context.current().addListener(
new CancellationListener() {
@Override
public void cancelled(Context context) {
lrsEnded.set(true);
}
}, MoreExecutors.directExecutor());
loadReportCalls.offer(call);
return requestObserver;
}
};
cleanupRule.register(
InProcessServerBuilder
.forName(serverName)
.addService(mockedDiscoveryService)
.addService(lrsServiceImpl)
.directExecutor()
.build()
.start());
channel =
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
List<ServerInfo> servers =
ImmutableList.of(new ServerInfo(serverName, ImmutableList.<ChannelCreds>of()));
XdsChannelFactory channelFactory = new XdsChannelFactory() {
@Override
ManagedChannel createChannel(List<ServerInfo> servers) {
assertThat(Iterables.getOnlyElement(servers).getServerUri()).isEqualTo(serverName);
assertThat(Iterables.getOnlyElement(servers).getChannelCredentials()).isEmpty();
return channel;
}
};
xdsClient =
new XdsClientImpl(
TARGET_AUTHORITY,
servers,
channelFactory,
NODE,
syncContext,
fakeClock.getScheduledExecutorService(),
backoffPolicyProvider,
fakeClock.getStopwatchSupplier());
// Only the connection to management server is established, no RPC request is sent until at
// least one watcher is registered.
assertThat(responseObservers).isEmpty();
assertThat(requestObservers).isEmpty();
}
@After
public void tearDown() {
xdsClient.shutdown();
assertThat(adsEnded.get()).isTrue();
assertThat(lrsEnded.get()).isTrue();
assertThat(channel.isShutdown()).isTrue();
assertThat(fakeClock.getPendingTasks()).isEmpty();
}
// Always test the real workflow and integrity of XdsClient: RDS protocol should always followed
// after at least one LDS request-response, from which the RDS resource name comes. CDS and EDS
// can be tested separately as they are used in a standalone way.
// Discovery responses should follow management server spec and xDS protocol. See
// https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol.
/**
* Client receives an LDS response that does not contain a Listener for the requested resource.
* The LDS response is ACKed.
* The config watcher is notified with an error after its response timer expires.
*/
@Test
public void ldsResponseWithoutMatchingResource() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
// Client sends an LDS request for the host name (with port) to management server.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "")));
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener("bar.googleapis.com",
Any.pack(HttpConnectionManager.newBuilder()
.setRouteConfig(
buildRouteConfiguration("route-bar.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of("bar.googleapis.com"),
"cluster-bar.googleapis.com"))))
.build()))),
Any.pack(buildListener("baz.googleapis.com",
Any.pack(HttpConnectionManager.newBuilder()
.setRouteConfig(
buildRouteConfiguration("route-baz.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of("baz.googleapis.com"),
"cluster-baz.googleapis.com"))))
.build()))));
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0000")));
verify(configWatcher, never()).onConfigChanged(any(ConfigUpdate.class));
verify(configWatcher, never()).onError(any(Status.class));
fakeClock.forwardTime(XdsClientImpl.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
ArgumentCaptor<Status> errorStatusCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onError(errorStatusCaptor.capture());
Status error = errorStatusCaptor.getValue();
assertThat(error.getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
/**
* An LDS response contains the requested listener and an in-lined RouteConfiguration message for
* that listener. But the RouteConfiguration message is invalid as it does not contain any
* VirtualHost with domains matching the requested hostname.
* The LDS response is NACKed, as if the XdsClient has not received this response.
* The config watcher is notified with an error after its response timer expires..
*/
@Test
public void failToFindVirtualHostInLdsResponseInLineRouteConfig() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
// Client sends an LDS request for the host name (with port) to management server.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "")));
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
RouteConfiguration routeConfig =
buildRouteConfiguration(
"route.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster"),
buildVirtualHost(ImmutableList.of("something else does not match"),
"some other cluster")));
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRouteConfig(routeConfig).build()))));
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an NACK LDS request.
verify(requestObserver)
.onNext(
argThat(new DiscoveryRequestMatcher("", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0000")));
verify(configWatcher, never()).onConfigChanged(any(ConfigUpdate.class));
verify(configWatcher, never()).onError(any(Status.class));
fakeClock.forwardTime(XdsClientImpl.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
ArgumentCaptor<Status> errorStatusCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onError(errorStatusCaptor.capture());
Status error = errorStatusCaptor.getValue();
assertThat(error.getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
/**
* Client resolves the virtual host config from an LDS response that contains a
* RouteConfiguration message directly in-line for the requested resource. No RDS is needed.
* The LDS response is ACKed.
* The config watcher is notified with an update.
*/
@Test
public void resolveVirtualHostInLdsResponse() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
// Client sends an LDS request for the host name (with port) to management server.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "")));
ScheduledTask ldsRespTimer =
Iterables.getOnlyElement(
fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER));
assertThat(ldsRespTimer.isCancelled()).isFalse();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener("bar.googleapis.com",
Any.pack(HttpConnectionManager.newBuilder()
.setRouteConfig(
buildRouteConfiguration("route-bar.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of("bar.googleapis.com"),
"cluster-bar.googleapis.com"))))
.build()))),
Any.pack(buildListener("baz.googleapis.com",
Any.pack(HttpConnectionManager.newBuilder()
.setRouteConfig(
buildRouteConfiguration("route-baz.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of("baz.googleapis.com"),
"cluster-baz.googleapis.com"))))
.build()))),
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(
HttpConnectionManager.newBuilder()
.setRouteConfig( // target route configuration
buildRouteConfiguration("route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost( // matching virtual host
ImmutableList.of(TARGET_AUTHORITY, "bar.googleapis.com"),
"cluster.googleapis.com"),
buildVirtualHost(
ImmutableList.of("something does not match"),
"some cluster"))))
.build()))));
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
assertThat(ldsRespTimer.isCancelled()).isTrue();
// Client sends an ACK request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0000")));
ArgumentCaptor<ConfigUpdate> configUpdateCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onConfigChanged(configUpdateCaptor.capture());
assertThat(configUpdateCaptor.getValue().getClusterName()).isEqualTo("cluster.googleapis.com");
verifyNoMoreInteractions(requestObserver);
}
/**
* Client receives an RDS response (after a previous LDS request-response) that does not contain a
* RouteConfiguration for the requested resource while each received RouteConfiguration is valid.
* The RDS response is ACKed.
* After the resource fetch timeout expires, watcher waiting for the resource is notified
* with a resource not found error.
*/
@Test
public void rdsResponseWithoutMatchingResource() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
// Client sends an LDS request for the host name (with port) to management server.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "")));
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("route-foo.googleapis.com")
.build();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0000")));
// Client sends an (first) RDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "")));
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
// Management server should only sends RouteConfiguration messages with at least one
// VirtualHost with domains matching requested hostname. Otherwise, it is invalid data.
List<Any> routeConfigs = ImmutableList.of(
Any.pack(
buildRouteConfiguration(
"some resource name does not match route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of(TARGET_AUTHORITY),
"whatever cluster")))),
Any.pack(
buildRouteConfiguration(
"some other resource name does not match route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(
ImmutableList.of(TARGET_AUTHORITY),
"some more whatever cluster")))));
response = buildDiscoveryResponse("0", routeConfigs, XdsClientImpl.ADS_TYPE_URL_RDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK RDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "0000")));
verify(configWatcher, never()).onConfigChanged(any(ConfigUpdate.class));
verify(configWatcher, never()).onError(any(Status.class));
fakeClock.forwardTime(XdsClientImpl.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onError(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
/**
* Client resolves the virtual host config from an RDS response for the requested resource. The
* RDS response is ACKed.
* The config watcher is notified with an update.
*/
@Test
public void resolveVirtualHostInRdsResponse() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("route-foo.googleapis.com")
.build();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request and an RDS request for "route-foo.googleapis.com". (Omitted)
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
// Management server should only sends RouteConfiguration messages with at least one
// VirtualHost with domains matching requested hostname. Otherwise, it is invalid data.
List<Any> routeConfigs = ImmutableList.of(
Any.pack(
buildRouteConfiguration(
"route-foo.googleapis.com", // target route configuration
ImmutableList.of(
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster"),
buildVirtualHost(ImmutableList.of(TARGET_AUTHORITY, "bar.googleapis.com:443"),
"cluster.googleapis.com")))), // matching virtual host
Any.pack(
buildRouteConfiguration(
"some resource name does not match route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("foo.googleapis.com"),
"some more cluster")))));
response = buildDiscoveryResponse("0", routeConfigs, XdsClientImpl.ADS_TYPE_URL_RDS, "0000");
responseObserver.onNext(response);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
// Client sent an ACK RDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "0000")));
ArgumentCaptor<ConfigUpdate> configUpdateCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onConfigChanged(configUpdateCaptor.capture());
assertThat(configUpdateCaptor.getValue().getClusterName()).isEqualTo("cluster.googleapis.com");
}
/**
* Client resolves the virtual host config with path matching from an RDS response for the
* requested resource. The RDS response is ACKed.
* The config watcher is notified with an update.
*/
@Test
public void resolveVirtualHostWithPathMatchingInRdsResponse() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("route-foo.googleapis.com")
.build();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request and an RDS request for "route-foo.googleapis.com". (Omitted)
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
// Management server should only sends RouteConfiguration messages with at least one
// VirtualHost with domains matching requested hostname. Otherwise, it is invalid data.
List<Any> routeConfigs = ImmutableList.of(
Any.pack(
buildRouteConfiguration(
"route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster"),
VirtualHost.newBuilder()
.setName("virtualhost00.googleapis.com") // don't care
// domains wit a match.
.addAllDomains(ImmutableList.of(TARGET_AUTHORITY, "bar.googleapis.com"))
.addRoutes(Route.newBuilder()
// path match with cluster route
.setRoute(RouteAction.newBuilder().setCluster("cl1.googleapis.com"))
.setMatch(RouteMatch.newBuilder().setPath("/service1/method1/")))
.addRoutes(Route.newBuilder()
// path match with weighted cluster route
.setRoute(RouteAction.newBuilder().setWeightedClusters(
WeightedCluster.newBuilder()
.addClusters(WeightedCluster.ClusterWeight.newBuilder()
.setWeight(UInt32Value.newBuilder().setValue(30))
.setName("cl21.googleapis.com"))
.addClusters(WeightedCluster.ClusterWeight.newBuilder()
.setWeight(UInt32Value.newBuilder().setValue(70))
.setName("cl22.googleapis.com"))))
.setMatch(RouteMatch.newBuilder().setPath("/service2/method2/")))
.addRoutes(Route.newBuilder()
// prefix match with cluster route
.setRoute(RouteAction.newBuilder()
.setCluster("cl1.googleapis.com"))
.setMatch(RouteMatch.newBuilder().setPrefix("/service1/")))
.addRoutes(Route.newBuilder()
// default match with cluster route
.setRoute(RouteAction.newBuilder().setCluster("cluster.googleapis.com"))
.setMatch(RouteMatch.newBuilder().setPrefix("")))
.build(),
buildVirtualHost(ImmutableList.of("something does not match"),
"some more cluster")))),
Any.pack(
buildRouteConfiguration(
"some resource name does not match route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("foo.googleapis.com"),
"some more cluster")))));
response = buildDiscoveryResponse("0", routeConfigs, XdsClientImpl.ADS_TYPE_URL_RDS, "0000");
responseObserver.onNext(response);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
// Client sent an ACK RDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "0000")));
ArgumentCaptor<ConfigUpdate> configUpdateCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onConfigChanged(configUpdateCaptor.capture());
assertThat(configUpdateCaptor.getValue().getClusterName()).isEqualTo("cluster.googleapis.com");
List<EnvoyProtoData.Route> routes = configUpdateCaptor.getValue().getRoutes();
assertThat(routes).hasSize(4);
assertThat(routes.get(0)).isEqualTo(
new EnvoyProtoData.Route(
// path match with cluster route
new EnvoyProtoData.RouteMatch("", "/service1/method1/", false),
new EnvoyProtoData.RouteAction(
"cl1.googleapis.com",
"",
ImmutableList.<EnvoyProtoData.ClusterWeight>of())));
assertThat(routes.get(1)).isEqualTo(
new EnvoyProtoData.Route(
// path match with weighted cluster route
new EnvoyProtoData.RouteMatch("", "/service2/method2/", false),
new EnvoyProtoData.RouteAction(
"",
"",
ImmutableList.of(
new EnvoyProtoData.ClusterWeight("cl21.googleapis.com", 30),
new EnvoyProtoData.ClusterWeight("cl22.googleapis.com", 70)
))));
assertThat(routes.get(2)).isEqualTo(
new EnvoyProtoData.Route(
// prefix match with cluster route
new EnvoyProtoData.RouteMatch("/service1/", "", false),
new EnvoyProtoData.RouteAction(
"cl1.googleapis.com",
"",
ImmutableList.<EnvoyProtoData.ClusterWeight>of())));
assertThat(routes.get(3)).isEqualTo(
new EnvoyProtoData.Route(
// default match with cluster route
new EnvoyProtoData.RouteMatch("", "", false),
new EnvoyProtoData.RouteAction(
"cluster.googleapis.com",
"",
ImmutableList.<EnvoyProtoData.ClusterWeight>of())));
}
/**
* Client receives an RDS response (after a previous LDS request-response) containing a
* RouteConfiguration message for the requested resource. But the RouteConfiguration message
* is invalid as it does not contain any VirtualHost with domains matching the requested
* hostname.
* The RDS response is NACKed, as if the XdsClient has not received this response.
* The config watcher is NOT notified with an error.
*/
@Test
public void failToFindVirtualHostInRdsResponse() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("route-foo.googleapis.com")
.build();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request and an RDS request for "route-foo.googleapis.com". (Omitted)
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
List<Any> routeConfigs = ImmutableList.of(
Any.pack(
buildRouteConfiguration(
"route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster"),
buildVirtualHost(
ImmutableList.of("something else does not match", "also does not match"),
"cluster.googleapis.com")))),
Any.pack(
buildRouteConfiguration(
"some resource name does not match route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of("one more does not match"),
"some more cluster")))));
response = buildDiscoveryResponse("0", routeConfigs, XdsClientImpl.ADS_TYPE_URL_RDS, "0000");
responseObserver.onNext(response);
// Client sent an NACK RDS request.
verify(requestObserver)
.onNext(
argThat(new DiscoveryRequestMatcher("", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "0000")));
verify(configWatcher, never()).onConfigChanged(any(ConfigUpdate.class));
verify(configWatcher, never()).onError(any(Status.class));
fakeClock.forwardTime(XdsClientImpl.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onError(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
/**
* Client receives an RDS response (after a previous LDS request-response) containing a
* RouteConfiguration message for the requested resource. But the RouteConfiguration message
* is invalid as the VirtualHost with domains matching the requested hostname contains invalid
* data, its RouteAction message is absent.
* The RDS response is NACKed, as if the XdsClient has not received this response.
* The config watcher is NOT notified with an error.
*/
@Test
public void matchingVirtualHostDoesNotContainRouteAction() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("route-foo.googleapis.com")
.build();
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request and an RDS request for "route-foo.googleapis.com". (Omitted)
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
// A VirtualHost with a Route that contains only redirect configuration.
VirtualHost virtualHost =
VirtualHost.newBuilder()
.setName("virtualhost00.googleapis.com") // don't care
.addDomains("foo.googleapis.com")
.addRoutes(
Route.newBuilder()
.setRedirect(
RedirectAction.newBuilder()
.setHostRedirect("bar.googleapis.com")
.setPortRedirect(443)))
.build();
List<Any> routeConfigs = ImmutableList.of(
Any.pack(
buildRouteConfiguration("route-foo.googleapis.com",
ImmutableList.of(virtualHost))));
response = buildDiscoveryResponse("0", routeConfigs, XdsClientImpl.ADS_TYPE_URL_RDS, "0000");
responseObserver.onNext(response);
// Client sent an NACK RDS request.
verify(requestObserver)
.onNext(
argThat(new DiscoveryRequestMatcher("", "route-foo.googleapis.com",
XdsClientImpl.ADS_TYPE_URL_RDS, "0000")));
verify(configWatcher, never()).onConfigChanged(any(ConfigUpdate.class));
verify(configWatcher, never()).onError(any(Status.class));
fakeClock.forwardTime(XdsClientImpl.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onError(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
/**
* Client receives LDS/RDS responses for updating resources previously received.
*
* <p>Tests for streaming behavior.
*/
@Test
public void notifyUpdatedResources() {
xdsClient.watchConfigData(TARGET_AUTHORITY, configWatcher);
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
// Client sends an LDS request for the host name (with port) to management server.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "")));
// Management server sends back an LDS response containing a RouteConfiguration for the
// requested Listener directly in-line.
RouteConfiguration routeConfig =
buildRouteConfiguration(
"route-foo.googleapis.com", // target route configuration
ImmutableList.of(
buildVirtualHost( // matching virtual host
ImmutableList.of(TARGET_AUTHORITY, "bar.googleapis.com:443"),
"cluster.googleapis.com"),
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster")));
List<Any> listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRouteConfig(routeConfig).build())))
);
DiscoveryResponse response =
buildDiscoveryResponse("0", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0000");
responseObserver.onNext(response);
// Client sends an ACK LDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "0", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0000")));
// Cluster name is resolved and notified to config watcher.
ArgumentCaptor<ConfigUpdate> configUpdateCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher).onConfigChanged(configUpdateCaptor.capture());
assertThat(configUpdateCaptor.getValue().getClusterName()).isEqualTo("cluster.googleapis.com");
// Management sends back another LDS response containing updates for the requested Listener.
routeConfig =
buildRouteConfiguration(
"another-route-foo.googleapis.com",
ImmutableList.of(
buildVirtualHost(ImmutableList.of(TARGET_AUTHORITY, "bar.googleapis.com:443"),
"another-cluster.googleapis.com"),
buildVirtualHost(ImmutableList.of("something does not match"),
"some cluster")));
listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRouteConfig(routeConfig).build())))
);
response =
buildDiscoveryResponse("1", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0001");
responseObserver.onNext(response);
// Client sends an ACK LDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "1", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0001")));
// Updated cluster name is notified to config watcher.
configUpdateCaptor = ArgumentCaptor.forClass(null);
verify(configWatcher, times(2)).onConfigChanged(configUpdateCaptor.capture());
assertThat(configUpdateCaptor.getValue().getClusterName())
.isEqualTo("another-cluster.googleapis.com");
// Management server sends back another LDS response containing updates for the requested
// Listener and telling client to do RDS.
Rds rdsConfig =
Rds.newBuilder()
// Must set to use ADS.
.setConfigSource(
ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))
.setRouteConfigName("some-route-to-foo.googleapis.com")
.build();
listeners = ImmutableList.of(
Any.pack(buildListener(TARGET_AUTHORITY, /* matching resource */
Any.pack(HttpConnectionManager.newBuilder().setRds(rdsConfig).build())))
);
response =
buildDiscoveryResponse("2", listeners, XdsClientImpl.ADS_TYPE_URL_LDS, "0002");
responseObserver.onNext(response);
// Client sends an ACK LDS request.
verify(requestObserver)
.onNext(eq(buildDiscoveryRequest(NODE, "2", TARGET_AUTHORITY,
XdsClientImpl.ADS_TYPE_URL_LDS, "0002")));