Merge pull request #9952 from alimate/BAEL-4579-2

BAEL-4579: Fix the integrations tests in ribbon-client-service
This commit is contained in:
Eric Martin 2020-08-30 22:37:01 -05:00 committed by GitHub
commit e60f79377b
5 changed files with 18 additions and 29 deletions

View File

@ -33,8 +33,20 @@
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>0</forkCount>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
</project>

View File

@ -9,6 +9,7 @@ weather-service:
ribbon:
eureka:
enabled: false
listOfServers: http://localhost:8021, http://localhost:8022
ServerListRefreshInterval: 5000
MaxAutoRetries: 3
MaxAutoRetriesNextServer: 1

View File

@ -10,7 +10,6 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.ResponseEntity;
import static com.baeldung.spring.cloud.ribbon.retry.TestUtils.setUpServices;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RibbonClientApp.class)
@ -25,10 +24,8 @@ public class RibbonRetryFailureIntegrationTest {
@BeforeAll
public static void setup() {
weatherServiceInstance1 = startApp(0);
weatherServiceInstance2 = startApp(0);
setUpServices(weatherServiceInstance1, weatherServiceInstance2);
weatherServiceInstance1 = startApp(8021);
weatherServiceInstance2 = startApp(8022);
}
@AfterAll

View File

@ -10,7 +10,6 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.ResponseEntity;
import static com.baeldung.spring.cloud.ribbon.retry.TestUtils.setUpServices;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -26,10 +25,8 @@ public class RibbonRetrySuccessIntegrationTest {
@BeforeAll
public static void setup() {
weatherServiceInstance1 = startApp(0);
weatherServiceInstance2 = startApp(0);
setUpServices(weatherServiceInstance1, weatherServiceInstance2);
weatherServiceInstance1 = startApp(8021);
weatherServiceInstance2 = startApp(8022);
}
private static ConfigurableApplicationContext startApp(int port) {

View File

@ -1,18 +0,0 @@
package com.baeldung.spring.cloud.ribbon.retry;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
class TestUtils {
static int getWebAppPort(ConfigurableApplicationContext ctx) {
return ((AnnotationConfigServletWebServerApplicationContext) ctx).getWebServer().getPort();
}
static void setUpServices(ConfigurableApplicationContext service1, ConfigurableApplicationContext service2) {
int port1 = getWebAppPort(service1);
int port2 = getWebAppPort(service2);
String serversList = String.format("http://localhost:%d, http://localhost:%d", port1, port2);
System.setProperty("weather-service.ribbon.listOfServers", serversList);
}
}