|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -package org.springframework.cloud.kubernetes.fabric8.loadbalancer.it; |
| 17 | +package org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.mode.pod; |
18 | 18 |
|
19 | 19 | import com.github.tomakehurst.wiremock.WireMockServer; |
20 | 20 | import com.github.tomakehurst.wiremock.client.WireMock; |
21 | | -import io.fabric8.kubernetes.api.model.EndpointAddressBuilder; |
22 | | -import io.fabric8.kubernetes.api.model.EndpointPortBuilder; |
23 | | -import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder; |
24 | 21 | import io.fabric8.kubernetes.api.model.Endpoints; |
25 | | -import io.fabric8.kubernetes.api.model.EndpointsBuilder; |
26 | 22 | import io.fabric8.kubernetes.api.model.EndpointsListBuilder; |
27 | | -import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
28 | 23 | import io.fabric8.kubernetes.api.model.Service; |
29 | 24 | import io.fabric8.kubernetes.client.Config; |
30 | 25 | import io.fabric8.kubernetes.client.utils.Serialization; |
|
37 | 32 |
|
38 | 33 | import org.springframework.beans.factory.ObjectProvider; |
39 | 34 | import org.springframework.beans.factory.annotation.Autowired; |
40 | | -import org.springframework.boot.SpringApplication; |
41 | | -import org.springframework.boot.autoconfigure.SpringBootApplication; |
42 | 35 | import org.springframework.boot.test.context.SpringBootTest; |
43 | | -import org.springframework.boot.test.context.TestConfiguration; |
44 | | -import org.springframework.cloud.client.loadbalancer.LoadBalanced; |
45 | 36 | import org.springframework.cloud.kubernetes.commons.loadbalancer.KubernetesServiceInstanceMapper; |
| 37 | +import org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.Util; |
46 | 38 | import org.springframework.cloud.loadbalancer.core.CachingServiceInstanceListSupplier; |
47 | 39 | import org.springframework.cloud.loadbalancer.core.DiscoveryClientServiceInstanceListSupplier; |
48 | 40 | import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; |
49 | 41 | import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; |
50 | | -import org.springframework.context.annotation.Bean; |
51 | 42 | import org.springframework.http.HttpMethod; |
52 | 43 | import org.springframework.web.reactive.function.client.WebClient; |
53 | 44 |
|
54 | 45 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; |
55 | | -import static org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.PodModeAllNamespacesTest.Configuration; |
56 | | -import static org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.PodModeAllNamespacesTest.LoadBalancerConfiguration; |
| 46 | +import static org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.Util.Configuration; |
| 47 | +import static org.springframework.cloud.kubernetes.fabric8.loadbalancer.it.Util.LoadBalancerConfiguration; |
57 | 48 |
|
58 | 49 | /** |
59 | 50 | * @author wind57 |
|
62 | 53 | properties = { "spring.cloud.kubernetes.loadbalancer.mode=POD", "spring.main.cloud-platform=KUBERNETES", |
63 | 54 | "spring.cloud.kubernetes.discovery.all-namespaces=true" }, |
64 | 55 | classes = { LoadBalancerConfiguration.class, Configuration.class }) |
65 | | -class PodModeAllNamespacesTest { |
| 56 | +class AllNamespacesTest { |
66 | 57 |
|
67 | 58 | private static final String SERVICE_A_URL = "http://service-a"; |
68 | 59 |
|
@@ -137,22 +128,11 @@ static void afterAll() { |
137 | 128 | @Test |
138 | 129 | void test() { |
139 | 130 |
|
140 | | - Service serviceA = Util.createService("a", "service-a", SERVICE_A_PORT); |
141 | | - Service serviceB = Util.createService("b", "service-b", SERVICE_B_PORT); |
| 131 | + Service serviceA = Util.service("a", "service-a", SERVICE_A_PORT); |
| 132 | + Service serviceB = Util.service("b", "service-b", SERVICE_B_PORT); |
142 | 133 |
|
143 | | - Endpoints endpointsA = new EndpointsBuilder() |
144 | | - .withSubsets(new EndpointSubsetBuilder() |
145 | | - .withPorts(new EndpointPortBuilder().withPort(SERVICE_A_PORT).build()) |
146 | | - .withAddresses(new EndpointAddressBuilder().withIp("127.0.0.1").build()).build()) |
147 | | - .withMetadata(new ObjectMetaBuilder().withName("no-port-name-service").withNamespace("a").build()) |
148 | | - .build(); |
149 | | - |
150 | | - Endpoints endpointsB = new EndpointsBuilder() |
151 | | - .withSubsets(new EndpointSubsetBuilder() |
152 | | - .withPorts(new EndpointPortBuilder().withPort(SERVICE_B_PORT).build()) |
153 | | - .withAddresses(new EndpointAddressBuilder().withIp("127.0.0.1").build()).build()) |
154 | | - .withMetadata(new ObjectMetaBuilder().withName("no-port-name-service").withNamespace("b").build()) |
155 | | - .build(); |
| 134 | + Endpoints endpointsA = Util.endpoints(SERVICE_A_PORT, "127.0.0.1", "a"); |
| 135 | + Endpoints endpointsB = Util.endpoints(SERVICE_B_PORT, "127.0.0.1", "b"); |
156 | 136 |
|
157 | 137 | String endpointsAListAsString = Serialization.asJson(new EndpointsListBuilder().withItems(endpointsA).build()); |
158 | 138 | String endpointsBListAsString = Serialization.asJson(new EndpointsListBuilder().withItems(endpointsB).build()); |
@@ -192,26 +172,18 @@ void test() { |
192 | 172 | .getIfAvailable().getProvider("service-a", ServiceInstanceListSupplier.class).getIfAvailable(); |
193 | 173 | Assertions.assertThat(supplier.getDelegate().getClass()) |
194 | 174 | .isSameAs(DiscoveryClientServiceInstanceListSupplier.class); |
195 | | - } |
196 | | - |
197 | | - @TestConfiguration |
198 | | - static class LoadBalancerConfiguration { |
199 | 175 |
|
200 | | - @Bean |
201 | | - @LoadBalanced |
202 | | - WebClient.Builder client() { |
203 | | - return WebClient.builder(); |
204 | | - } |
205 | | - |
206 | | - } |
| 176 | + wireMockServer.verify(WireMock.exactly(1), WireMock |
| 177 | + .getRequestedFor(WireMock.urlEqualTo("/api/v1/endpoints?fieldSelector=metadata.name%3Dservice-a"))); |
207 | 178 |
|
208 | | - @SpringBootApplication |
209 | | - static class Configuration { |
| 179 | + wireMockServer.verify(WireMock.exactly(1), WireMock |
| 180 | + .getRequestedFor(WireMock.urlEqualTo("/api/v1/endpoints?fieldSelector=metadata.name%3Dservice-b"))); |
210 | 181 |
|
211 | | - public static void main(String[] args) { |
212 | | - SpringApplication.run(ServiceModeAllNamespacesTest.Configuration.class); |
213 | | - } |
| 182 | + wireMockServer.verify(WireMock.exactly(1), |
| 183 | + WireMock.getRequestedFor(WireMock.urlEqualTo("/api/v1/namespaces/a/services/service-a"))); |
214 | 184 |
|
| 185 | + wireMockServer.verify(WireMock.exactly(1), |
| 186 | + WireMock.getRequestedFor(WireMock.urlEqualTo("/api/v1/namespaces/b/services/service-b"))); |
215 | 187 | } |
216 | 188 |
|
217 | 189 | } |
0 commit comments