Skip to content

Commit 89fdb6a

Browse files
authored
Fix 1561 (#1563)
Fixes #1561
1 parent 50927e4 commit 89fdb6a

File tree

4 files changed

+103
-23
lines changed

4 files changed

+103
-23
lines changed

spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,23 @@ void kubernetesDiscoveryEnabled() {
6767
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
6868
}
6969

70-
// disabling discovery has no impact on the catalog watch.
70+
// disabling discovery, disables catalog watcher.
7171
@Test
7272
void kubernetesDiscoveryDisabled() {
7373
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
7474
"spring.cloud.kubernetes.discovery.enabled=false");
75-
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
75+
applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class));
7676
}
7777

7878
/**
79-
* both blocking and reactive configs are disabled, should not influence catalog
80-
* watcher in any way.
79+
* both blocking and reactive configs are disabled, catalog watcher is disabled also.
8180
*/
8281
@Test
8382
void disableBlockingAndReactive() {
8483
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
8584
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false");
8685
applicationContextRunner.run(context -> {
87-
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
86+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
8887
assertThat(context).doesNotHaveBean(KubernetesInformerReactiveDiscoveryClient.class);
8988
assertThat(context).doesNotHaveBean(KubernetesInformerDiscoveryClient.class);
9089
assertThat(context).doesNotHaveBean(SharedInformerFactory.class);
@@ -94,15 +93,38 @@ void disableBlockingAndReactive() {
9493
}
9594

9695
/**
97-
* spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog
98-
* watcher.
96+
* blocking is disabled, reactive is enabled, catalog watcher is enabled.
97+
*/
98+
@Test
99+
void disableBlockingEnableReactive() {
100+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
101+
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=true");
102+
applicationContextRunner.run(context -> {
103+
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
104+
});
105+
}
106+
107+
/**
108+
* blocking is enabled, reactive is disabled, catalog watcher is enabled.
109+
*/
110+
@Test
111+
void enableBlockingDisableReactive() {
112+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
113+
"spring.cloud.discovery.blocking.enabled=true", "spring.cloud.discovery.reactive.enabled=false");
114+
applicationContextRunner.run(context -> {
115+
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
116+
});
117+
}
118+
119+
/**
120+
* spring.cloud.kubernetes.discovery.enabled is false, catalog watcher is disabled also.
99121
*/
100122
@Test
101123
void disableKubernetesDiscovery() {
102124
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
103125
"spring.cloud.kubernetes.discovery.enabled=false");
104126
applicationContextRunner.run(context -> {
105-
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
127+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
106128
assertThat(context).doesNotHaveBean(KubernetesInformerReactiveDiscoveryClient.class);
107129
assertThat(context).doesNotHaveBean(KubernetesInformerDiscoveryClient.class);
108130
});

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnKubernetesCatalogWatcherEnabled.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
@Documented
3838
@Inherited
3939
@ConditionalOnDiscoveryEnabled
40+
@ConditionalOnKubernetesDiscoveryEnabled
41+
@ConditionalOnBlockingOrReactiveDiscoveryEnabled
4042
@ConditionalOnKubernetesCatalogEnabled
4143
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
4244
public @interface ConditionalOnKubernetesCatalogWatcherEnabled {

spring-cloud-kubernetes-discovery/src/test/java/org/springframework/cloud/kubernetes/discovery/KubernetesCatalogWatchAutoConfigurationTests.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,71 @@ void kubernetesDiscoveryEnabled() {
6464
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
6565
}
6666

67-
// disabling discovery has no impact on the catalog watch.
67+
// disabling discovery, disabled catalog watcher.
6868
@Test
6969
void kubernetesDiscoveryDisabled() {
7070
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
7171
"spring.cloud.kubernetes.discovery.enabled=false",
7272
"spring.cloud.kubernetes.discovery.discovery-server-url=example.com",
73+
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true",
74+
"spring.cloud.kubernetes.discovery.discovery-server-url=example.com",
7375
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true");
74-
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
76+
applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class));
7577
}
7678

7779
/**
78-
* both blocking and reactive configs are disabled, should not influence catalog
79-
* watcher in any way.
80+
* both blocking and reactive configs are disabled, catalog watcher is disabled.
8081
*/
8182
@Test
8283
void disableBlockingAndReactive() {
8384
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
8485
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false",
8586
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true");
8687
applicationContextRunner.run(context -> {
87-
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
88+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
8889
assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
8990
assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class);
9091
});
9192
}
9293

9394
/**
94-
* spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog
95-
* watcher.
95+
* blocking is disabled, reactive is enabled, catalog watcher is enabled.
96+
*/
97+
@Test
98+
void disableBlockingEnableReactive() {
99+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
100+
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=true",
101+
"spring.cloud.kubernetes.discovery.discovery-server-url=example.com",
102+
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true");
103+
applicationContextRunner.run(context -> {
104+
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
105+
});
106+
}
107+
108+
/**
109+
* blocking is enabled, reactive is disabled, catalog watcher is enabled.
110+
*/
111+
@Test
112+
void enableBlockingDisableReactive() {
113+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
114+
"spring.cloud.discovery.blocking.enabled=true", "spring.cloud.discovery.reactive.enabled=false",
115+
"spring.cloud.kubernetes.discovery.discovery-server-url=example.com",
116+
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true");
117+
applicationContextRunner.run(context -> {
118+
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
119+
});
120+
}
121+
122+
/**
123+
* spring.cloud.kubernetes.discovery.enabled is false, catalog watcher is disabled.
96124
*/
97125
@Test
98126
void disableKubernetesDiscovery() {
99127
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
100128
"spring.cloud.kubernetes.discovery.enabled=false",
101129
"spring.cloud.kubernetes.http.discovery.catalog.watcher.enabled=true");
102130
applicationContextRunner.run(context -> {
103-
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
131+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
104132
assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
105133
assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class);
106134
});

spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,36 @@ void kubernetesDiscoveryEnabled() {
6161
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
6262
}
6363

64-
// disabling discovery has no impact on the catalog watch.
64+
// disabling discovery should disable catalog watcher.
6565
@Test
6666
void kubernetesDiscoveryDisabled() {
6767
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
6868
"spring.cloud.kubernetes.discovery.enabled=false");
69-
applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class));
69+
applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class));
7070
}
7171

7272
/**
73-
* both blocking and reactive configs are disabled, should not influence catalog
74-
* watcher in any way.
73+
* both blocking and reactive configs are disabled, catalog watcher is disabled too.
7574
*/
7675
@Test
7776
void disableBlockingAndReactive() {
7877
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
7978
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false");
79+
applicationContextRunner.run(context -> {
80+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
81+
assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
82+
assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
83+
assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class);
84+
});
85+
}
86+
87+
/**
88+
* blocking is disabled, reactive is enabled, catalog watcher is enabled.
89+
*/
90+
@Test
91+
void disableBlockingEnableReactive() {
92+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
93+
"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=true");
8094
applicationContextRunner.run(context -> {
8195
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
8296
assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
@@ -86,15 +100,29 @@ void disableBlockingAndReactive() {
86100
}
87101

88102
/**
89-
* spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog
90-
* watcher.
103+
* blocking is enabled, reactive is disabled, catalog watcher is enabled.
104+
*/
105+
@Test
106+
void enableBlockingDisableReactive() {
107+
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
108+
"spring.cloud.discovery.blocking.enabled=true", "spring.cloud.discovery.reactive.enabled=false");
109+
applicationContextRunner.run(context -> {
110+
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
111+
assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
112+
assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
113+
assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class);
114+
});
115+
}
116+
117+
/**
118+
* spring.cloud.kubernetes.discovery.enabled is false, catalog watcher is disabled also.
91119
*/
92120
@Test
93121
void disableKubernetesDiscovery() {
94122
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
95123
"spring.cloud.kubernetes.discovery.enabled=false");
96124
applicationContextRunner.run(context -> {
97-
assertThat(context).hasSingleBean(KubernetesCatalogWatch.class);
125+
assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class);
98126
assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
99127
assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
100128
assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class);

0 commit comments

Comments
 (0)