Merge pull request #9944 from alimate/BAEL-4579
BAEL-4579: Fix the integrations tests in ribbon-client-service
This commit is contained in:
commit
5145ca0f5a
|
@ -9,7 +9,6 @@ weather-service:
|
|||
ribbon:
|
||||
eureka:
|
||||
enabled: false
|
||||
listOfServers: http://localhost:8021, http://localhost:8022
|
||||
ServerListRefreshInterval: 5000
|
||||
MaxAutoRetries: 3
|
||||
MaxAutoRetriesNextServer: 1
|
||||
|
|
|
@ -10,6 +10,7 @@ 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)
|
||||
|
@ -24,8 +25,10 @@ public class RibbonRetryFailureIntegrationTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
weatherServiceInstance1 = startApp(8021);
|
||||
weatherServiceInstance2 = startApp(8022);
|
||||
weatherServiceInstance1 = startApp(0);
|
||||
weatherServiceInstance2 = startApp(0);
|
||||
|
||||
setUpServices(weatherServiceInstance1, weatherServiceInstance2);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
|
@ -10,6 +10,7 @@ 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;
|
||||
|
||||
|
@ -25,8 +26,10 @@ public class RibbonRetrySuccessIntegrationTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
weatherServiceInstance1 = startApp(8021);
|
||||
weatherServiceInstance2 = startApp(8022);
|
||||
weatherServiceInstance1 = startApp(0);
|
||||
weatherServiceInstance2 = startApp(0);
|
||||
|
||||
setUpServices(weatherServiceInstance1, weatherServiceInstance2);
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext startApp(int port) {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue