diff --git a/spring-cloud-kubernetes-integration-tests/load-balancer/pom.xml b/spring-cloud-kubernetes-integration-tests/load-balancer/pom.xml index 4f69d13b..eb47231f 100644 --- a/spring-cloud-kubernetes-integration-tests/load-balancer/pom.xml +++ b/spring-cloud-kubernetes-integration-tests/load-balancer/pom.xml @@ -9,6 +9,7 @@ 4.0.0 + Spring Cloud Kubernetes :: Integration Tests :: Load Balancer load-balancer @@ -28,7 +29,6 @@ io.fabric8 kubernetes-server-mock - 4.10.2 test diff --git a/spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/spring/framework/kubernetes/loadbalancer/SimpleLoadBalancerApp.java b/spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/springframework/cloud/kubernetes/loadbalancer/SimpleLoadBalancerApp.java similarity index 55% rename from spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/spring/framework/kubernetes/loadbalancer/SimpleLoadBalancerApp.java rename to spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/springframework/cloud/kubernetes/loadbalancer/SimpleLoadBalancerApp.java index 84ef41c8..0f91abd6 100644 --- a/spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/spring/framework/kubernetes/loadbalancer/SimpleLoadBalancerApp.java +++ b/spring-cloud-kubernetes-integration-tests/load-balancer/src/main/java/org/springframework/cloud/kubernetes/loadbalancer/SimpleLoadBalancerApp.java @@ -1,4 +1,20 @@ -package org.spring.framework.kubernetes.loadbalancer; +/* + * Copyright 2013-2020 the original author or 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 + * + * https://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 org.springframework.cloud.kubernetes.loadbalancer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java b/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java similarity index 51% rename from spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java rename to spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java index e9533cb8..646c77c7 100644 --- a/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java +++ b/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerAllNamespacesTest.java @@ -1,8 +1,21 @@ -package org.springframework.kubernetes.loadbalancer; +/* + * Copyright 2013-2020 the original author or 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 + * + * https://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. + */ -import java.util.List; +package org.springframework.cloud.kubernetes.loadbalancer; -import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.api.model.ServicePortBuilder; import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; import io.fabric8.kubernetes.client.Config; @@ -13,20 +26,20 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; -import org.spring.framework.kubernetes.loadbalancer.SimpleLoadBalancerApp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; -@SpringBootTest(classes = {SimpleLoadBalancerApp.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, - properties = {"spring.cloud.kubernetes.discovery.all-namespaces=true"}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, + properties = { "spring.cloud.kubernetes.discovery.all-namespaces=true" }) @RunWith(SpringRunner.class) public class LoadBalancerAllNamespacesTest { @Autowired RestTemplate restTemplate; + @ClassRule public static KubernetesServer server = new KubernetesServer(true, true); @@ -36,10 +49,12 @@ public class LoadBalancerAllNamespacesTest { public static void setup() { client = server.getClient(); - System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl()); + System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, + client.getConfiguration().getMasterUrl()); System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, + "false"); System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test"); } @@ -47,25 +62,23 @@ public class LoadBalancerAllNamespacesTest { @Test public void testLoadBalancerDifferentNamespace() { createTestData("service-b", "b"); - String response = restTemplate.getForObject("http://service-b/greeting", String.class); + String response = restTemplate.getForObject("http://service-b/greeting", + String.class); Assertions.assertNotNull(response); Assertions.assertEquals("greeting", response); } private void createTestData(String name, String namespace) { - client.services().inNamespace(namespace).createNew() - .withNewMetadata().withName(name).withNamespace(namespace).endMetadata() - .withSpec(new ServiceSpecBuilder() - .withPorts(new ServicePortBuilder().withProtocol("TCP").withPort(8080).build()) - .build()) - .done(); - client.endpoints().inNamespace(namespace).createNew() - .withNewMetadata().withName("service-a").withNamespace(namespace).endMetadata() - .addNewSubset() - .addNewAddress().withIp("localhost").endAddress() - .addNewPort().withName("http").withPort(8080).endPort() - .endSubset() - .done(); + client.services().inNamespace(namespace).createNew().withNewMetadata() + .withName(name).withNamespace(namespace).endMetadata() + .withSpec(new ServiceSpecBuilder().withPorts(new ServicePortBuilder() + .withProtocol("TCP").withPort(8080).build()).build()) + .done(); + client.endpoints().inNamespace(namespace).createNew().withNewMetadata() + .withName("service-a").withNamespace(namespace).endMetadata() + .addNewSubset().addNewAddress().withIp("localhost").endAddress() + .addNewPort().withName("http").withPort(8080).endPort().endSubset() + .done(); } } diff --git a/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerTest.java b/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerTest.java similarity index 54% rename from spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerTest.java rename to spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerTest.java index 09f24730..036e69a0 100644 --- a/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/kubernetes/loadbalancer/LoadBalancerTest.java +++ b/spring-cloud-kubernetes-integration-tests/load-balancer/src/test/java/org/springframework/cloud/kubernetes/loadbalancer/LoadBalancerTest.java @@ -1,4 +1,20 @@ -package org.springframework.kubernetes.loadbalancer; +/* + * Copyright 2013-2020 the original author or 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 + * + * https://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 org.springframework.cloud.kubernetes.loadbalancer; import io.fabric8.kubernetes.api.model.ServicePortBuilder; import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; @@ -10,19 +26,19 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; -import org.spring.framework.kubernetes.loadbalancer.SimpleLoadBalancerApp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; -@SpringBootTest(classes = {SimpleLoadBalancerApp.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @RunWith(SpringRunner.class) public class LoadBalancerTest { @Autowired RestTemplate restTemplate; + @ClassRule public static KubernetesServer server = new KubernetesServer(true, true); @@ -32,10 +48,12 @@ public class LoadBalancerTest { public static void setup() { client = server.getClient(); - System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl()); + System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, + client.getConfiguration().getMasterUrl()); System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, + "false"); System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test"); } @@ -43,7 +61,8 @@ public class LoadBalancerTest { @Test public void testLoadBalancerSameNamespace() { createTestData("service-a", "test"); - String response = restTemplate.getForObject("http://service-a/greeting", String.class); + String response = restTemplate.getForObject("http://service-a/greeting", + String.class); Assertions.assertNotNull(response); Assertions.assertEquals("greeting", response); } @@ -52,23 +71,19 @@ public class LoadBalancerTest { public void testLoadBalancerDifferentNamespace() { createTestData("service-b", "b"); Assertions.assertThrows(IllegalStateException.class, () -> restTemplate - .getForObject("http://service-b/greeting", String.class)); + .getForObject("http://service-b/greeting", String.class)); } private void createTestData(String name, String namespace) { - client.services().inNamespace(namespace).createNew() - .withNewMetadata().withName(name).endMetadata() - .withSpec(new ServiceSpecBuilder() - .withPorts(new ServicePortBuilder().withProtocol("TCP").withPort(8080).build()) - .build()) - .done(); - client.endpoints().inNamespace(namespace).createNew() - .withNewMetadata().withName("service-a").endMetadata() - .addNewSubset() - .addNewAddress().withIp("localhost").endAddress() - .addNewPort().withName("http").withPort(8080).endPort() - .endSubset() - .done(); + client.services().inNamespace(namespace).createNew().withNewMetadata() + .withName(name).endMetadata() + .withSpec(new ServiceSpecBuilder().withPorts(new ServicePortBuilder() + .withProtocol("TCP").withPort(8080).build()).build()) + .done(); + client.endpoints().inNamespace(namespace).createNew().withNewMetadata() + .withName("service-a").endMetadata().addNewSubset().addNewAddress() + .withIp("localhost").endAddress().addNewPort().withName("http") + .withPort(8080).endPort().endSubset().done(); } }