|
41 | 41 |
|
42 | 42 | import com.google.common.collect.ImmutableMap;
|
43 | 43 | import com.google.common.collect.ImmutableSet;
|
| 44 | +import com.google.common.util.concurrent.MoreExecutors; |
44 | 45 | import com.google.protobuf.Message;
|
45 | 46 | import io.envoyproxy.envoy.config.cluster.v3.Cluster;
|
46 | 47 | import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
|
|
65 | 66 | import io.grpc.xds.XdsConfig.XdsClusterConfig;
|
66 | 67 | import io.grpc.xds.XdsEndpointResource.EdsUpdate;
|
67 | 68 | import io.grpc.xds.client.CommonBootstrapperTestUtils;
|
68 |
| -import io.grpc.xds.client.XdsClientImpl; |
| 69 | +import io.grpc.xds.client.XdsClient; |
69 | 70 | import io.grpc.xds.client.XdsClientMetricReporter;
|
70 | 71 | import io.grpc.xds.client.XdsTransportFactory;
|
71 | 72 | import java.io.Closeable;
|
@@ -115,7 +116,7 @@ public class XdsDependencyManagerTest {
|
115 | 116 | });
|
116 | 117 |
|
117 | 118 | private ManagedChannel channel;
|
118 |
| - private XdsClientImpl xdsClient; |
| 119 | + private XdsClient xdsClient; |
119 | 120 | private XdsDependencyManager xdsDependencyManager;
|
120 | 121 | private TestWatcher xdsConfigWatcher;
|
121 | 122 | private Server xdsServer;
|
@@ -715,6 +716,138 @@ public void testCdsError() throws IOException {
|
715 | 716 | assertThat(status.getDescription()).contains(XdsTestUtils.CLUSTER_NAME);
|
716 | 717 | }
|
717 | 718 |
|
| 719 | + @Test |
| 720 | + public void ldsUpdateAfterShutdown() { |
| 721 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS", |
| 722 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 723 | + |
| 724 | + xdsDependencyManager = new XdsDependencyManager(xdsClient, xdsConfigWatcher, syncContext, |
| 725 | + serverName, serverName, nameResolverArgs, scheduler); |
| 726 | + |
| 727 | + verify(xdsConfigWatcher, timeout(1000)).onUpdate(any()); |
| 728 | + |
| 729 | + @SuppressWarnings("unchecked") |
| 730 | + XdsClient.ResourceWatcher<XdsListenerResource.LdsUpdate> resourceWatcher = |
| 731 | + mock(XdsClient.ResourceWatcher.class); |
| 732 | + xdsClient.watchXdsResource( |
| 733 | + XdsListenerResource.getInstance(), |
| 734 | + serverName, |
| 735 | + resourceWatcher, |
| 736 | + MoreExecutors.directExecutor()); |
| 737 | + verify(resourceWatcher, timeout(5000)).onChanged(any()); |
| 738 | + |
| 739 | + syncContext.execute(() -> { |
| 740 | + // Shutdown before any updates. This will unsubscribe from XdsClient, but only after this |
| 741 | + // Runnable returns |
| 742 | + xdsDependencyManager.shutdown(); |
| 743 | + |
| 744 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS2", "CDS", "EDS", |
| 745 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 746 | + verify(resourceWatcher, timeout(5000).times(2)).onChanged(any()); |
| 747 | + xdsClient.cancelXdsResourceWatch( |
| 748 | + XdsListenerResource.getInstance(), serverName, resourceWatcher); |
| 749 | + }); |
| 750 | + } |
| 751 | + |
| 752 | + @Test |
| 753 | + public void rdsUpdateAfterShutdown() { |
| 754 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS", |
| 755 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 756 | + |
| 757 | + xdsDependencyManager = new XdsDependencyManager(xdsClient, xdsConfigWatcher, syncContext, |
| 758 | + serverName, serverName, nameResolverArgs, scheduler); |
| 759 | + |
| 760 | + verify(xdsConfigWatcher, timeout(1000)).onUpdate(any()); |
| 761 | + |
| 762 | + @SuppressWarnings("unchecked") |
| 763 | + XdsClient.ResourceWatcher<XdsRouteConfigureResource.RdsUpdate> resourceWatcher = |
| 764 | + mock(XdsClient.ResourceWatcher.class); |
| 765 | + xdsClient.watchXdsResource( |
| 766 | + XdsRouteConfigureResource.getInstance(), |
| 767 | + "RDS", |
| 768 | + resourceWatcher, |
| 769 | + MoreExecutors.directExecutor()); |
| 770 | + verify(resourceWatcher, timeout(5000)).onChanged(any()); |
| 771 | + |
| 772 | + syncContext.execute(() -> { |
| 773 | + // Shutdown before any updates. This will unsubscribe from XdsClient, but only after this |
| 774 | + // Runnable returns |
| 775 | + xdsDependencyManager.shutdown(); |
| 776 | + |
| 777 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS2", "EDS", |
| 778 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 779 | + verify(resourceWatcher, timeout(5000).times(2)).onChanged(any()); |
| 780 | + xdsClient.cancelXdsResourceWatch( |
| 781 | + XdsRouteConfigureResource.getInstance(), serverName, resourceWatcher); |
| 782 | + }); |
| 783 | + } |
| 784 | + |
| 785 | + @Test |
| 786 | + public void cdsUpdateAfterShutdown() { |
| 787 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS", |
| 788 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 789 | + |
| 790 | + xdsDependencyManager = new XdsDependencyManager(xdsClient, xdsConfigWatcher, syncContext, |
| 791 | + serverName, serverName, nameResolverArgs, scheduler); |
| 792 | + |
| 793 | + verify(xdsConfigWatcher, timeout(1000)).onUpdate(any()); |
| 794 | + |
| 795 | + @SuppressWarnings("unchecked") |
| 796 | + XdsClient.ResourceWatcher<XdsClusterResource.CdsUpdate> resourceWatcher = |
| 797 | + mock(XdsClient.ResourceWatcher.class); |
| 798 | + xdsClient.watchXdsResource( |
| 799 | + XdsClusterResource.getInstance(), |
| 800 | + "CDS", |
| 801 | + resourceWatcher, |
| 802 | + MoreExecutors.directExecutor()); |
| 803 | + verify(resourceWatcher, timeout(5000)).onChanged(any()); |
| 804 | + |
| 805 | + syncContext.execute(() -> { |
| 806 | + // Shutdown before any updates. This will unsubscribe from XdsClient, but only after this |
| 807 | + // Runnable returns |
| 808 | + xdsDependencyManager.shutdown(); |
| 809 | + |
| 810 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS2", |
| 811 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 812 | + verify(resourceWatcher, timeout(5000).times(2)).onChanged(any()); |
| 813 | + xdsClient.cancelXdsResourceWatch( |
| 814 | + XdsClusterResource.getInstance(), serverName, resourceWatcher); |
| 815 | + }); |
| 816 | + } |
| 817 | + |
| 818 | + @Test |
| 819 | + public void edsUpdateAfterShutdown() { |
| 820 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS", |
| 821 | + ENDPOINT_HOSTNAME, ENDPOINT_PORT); |
| 822 | + |
| 823 | + xdsDependencyManager = new XdsDependencyManager(xdsClient, xdsConfigWatcher, syncContext, |
| 824 | + serverName, serverName, nameResolverArgs, scheduler); |
| 825 | + |
| 826 | + verify(xdsConfigWatcher, timeout(1000)).onUpdate(any()); |
| 827 | + |
| 828 | + @SuppressWarnings("unchecked") |
| 829 | + XdsClient.ResourceWatcher<XdsEndpointResource.EdsUpdate> resourceWatcher = |
| 830 | + mock(XdsClient.ResourceWatcher.class); |
| 831 | + xdsClient.watchXdsResource( |
| 832 | + XdsEndpointResource.getInstance(), |
| 833 | + "EDS", |
| 834 | + resourceWatcher, |
| 835 | + MoreExecutors.directExecutor()); |
| 836 | + verify(resourceWatcher, timeout(5000)).onChanged(any()); |
| 837 | + |
| 838 | + syncContext.execute(() -> { |
| 839 | + // Shutdown before any updates. This will unsubscribe from XdsClient, but only after this |
| 840 | + // Runnable returns |
| 841 | + xdsDependencyManager.shutdown(); |
| 842 | + |
| 843 | + XdsTestUtils.setAdsConfig(controlPlaneService, serverName, "RDS", "CDS", "EDS", |
| 844 | + ENDPOINT_HOSTNAME + "2", ENDPOINT_PORT); |
| 845 | + verify(resourceWatcher, timeout(5000).times(2)).onChanged(any()); |
| 846 | + xdsClient.cancelXdsResourceWatch( |
| 847 | + XdsEndpointResource.getInstance(), serverName, resourceWatcher); |
| 848 | + }); |
| 849 | + } |
| 850 | + |
718 | 851 | private Listener buildInlineClientListener(String rdsName, String clusterName) {
|
719 | 852 | return XdsTestUtils.buildInlineClientListener(rdsName, clusterName, serverName);
|
720 | 853 | }
|
|
0 commit comments