diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthStatus.java b/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthStatus.java
index 9c67e5d88..2288e9f9d 100644
--- a/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthStatus.java
+++ b/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthStatus.java
@@ -76,14 +76,14 @@ public long getLastUnreachableTs() {
return lastUnreachableTs;
}
- void reportAsUnreachable(final long timestamp, final String cause) {
+ public void reportAsUnreachable(final long timestamp, final String cause) {
LOG.info("{}: reportAsUnreachable {} cause {}", hostPort, new Timestamp(timestamp), cause);
this.lastUnreachableTs = timestamp;
this.status = Status.DOWN;
this.connections.set(0);
}
- void reportAsReachable(final long timestamp) {
+ public void reportAsReachable(final long timestamp) {
this.lastReachableTs = timestamp;
if (this.lastReachableTs - this.lastUnreachableTs >= WARMUP_MILLIS) {
this.status = Status.STABLE;
diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java
index fb7641349..7ebf5042c 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java
@@ -67,7 +67,7 @@
public class BasicStandardEndpointMapperTest {
@Rule
- public WireMockRule backend1 = new WireMockRule(0);
+ public WireMockRule backend = new WireMockRule(0);
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();
@@ -92,7 +92,7 @@ public void test() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- int backendPort = backend1.port();
+ int backendPort = backend.port();
StandardEndpointMapper mapper = new StandardEndpointMapper();
mapper.addBackend(new BackendConfiguration("backend-a", "localhost", backendPort, "/"));
@@ -182,7 +182,7 @@ public void testRouteErrors() throws Exception {
configuration.put("backend.1.id", "backend");
configuration.put("backend.1.host", "localhost");
- configuration.put("backend.1.port", String.valueOf(backend1.port()));
+ configuration.put("backend.1.port", String.valueOf(backend.port()));
configuration.put("backend.1.enabled", "true");
configuration.put("director.1.id", "director");
@@ -192,7 +192,7 @@ public void testRouteErrors() throws Exception {
// unreachable backend -> expected service unavailable
configuration.put("backend.2.id", "backend-down");
configuration.put("backend.2.host", "localhost-down");
- configuration.put("backend.2.port", String.valueOf(backend1.port()));
+ configuration.put("backend.2.port", String.valueOf(backend.port()));
configuration.put("backend.2.enabled", "true");
configuration.put("director.2.id", "director-down");
@@ -256,12 +256,14 @@ public void testRouteErrors() throws Exception {
PropertiesConfigurationStore config = new PropertiesConfigurationStore(configuration);
BackendHealthManager bhMan = mock(BackendHealthManager.class);
- final EndpointKey alive = EndpointKey.make("localhost:" + backend1.port());
- final EndpointKey hostPort1 = eq(alive);
- when(bhMan.getBackendStatus(hostPort1).getStatus()).thenReturn(BackendHealthStatus.Status.STABLE);
- final EndpointKey down = EndpointKey.make("localhost-down:" + backend1.port());
- final EndpointKey hostPort = eq(down);
- when(bhMan.getBackendStatus(hostPort).getStatus()).thenReturn(BackendHealthStatus.Status.DOWN); // simulate unreachable backend -> expected 500 error
+ final EndpointKey alive = EndpointKey.make("localhost:" + backend.port());
+ final BackendHealthStatus mockAliveStatus = mock(BackendHealthStatus.class);
+ when(mockAliveStatus.getStatus()).thenReturn(BackendHealthStatus.Status.STABLE);
+ when(bhMan.getBackendStatus(eq(alive))).thenReturn(mockAliveStatus);
+ final EndpointKey down = EndpointKey.make("localhost-down:" + backend.port());
+ final BackendHealthStatus mockDownStatus = mock(BackendHealthStatus.class);
+ when(mockDownStatus.getStatus()).thenReturn(BackendHealthStatus.Status.DOWN);
+ when(bhMan.getBackendStatus(eq(down))).thenReturn(mockDownStatus); // simulate unreachable backend -> expected 500 error
server.setBackendHealthManager(bhMan);
server.configureAtBoot(config);
server.start();
@@ -312,7 +314,7 @@ public void testDefaultRoute() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- int backendPort = backend1.port();
+ int backendPort = backend.port();
StandardEndpointMapper mapper = new StandardEndpointMapper();
mapper.addBackend(new BackendConfiguration("backend", "localhost", backendPort, "/"));
@@ -327,11 +329,13 @@ public void testDefaultRoute() throws Exception {
BackendHealthManager bhMan = mock(BackendHealthManager.class);
final EndpointKey alive = EndpointKey.make("localhost:" + backendPort);
- final EndpointKey hostPort1 = eq(alive);
- when(bhMan.getBackendStatus(hostPort1).getStatus()).thenReturn(BackendHealthStatus.Status.STABLE);
+ final BackendHealthStatus mockAliveStatus = mock(BackendHealthStatus.class);
+ when(mockAliveStatus.getStatus()).thenReturn(BackendHealthStatus.Status.STABLE);
+ when(bhMan.getBackendStatus(eq(alive))).thenReturn(mockAliveStatus);
final EndpointKey down = EndpointKey.make("localhost-down:" + backendPort);
- final EndpointKey hostPort = eq(down);
- when(bhMan.getBackendStatus(hostPort).getStatus()).thenReturn(BackendHealthStatus.Status.DOWN); // simulate unreachable backend -> expected 500 error
+ final BackendHealthStatus mockDownStatus = mock(BackendHealthStatus.class);
+ when(mockDownStatus.getStatus()).thenReturn(BackendHealthStatus.Status.DOWN);
+ when(bhMan.getBackendStatus(eq(down))).thenReturn(mockDownStatus); // simulate unreachable backend -> expected 500 error
try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
server.setBackendHealthManager(bhMan);
@@ -371,7 +375,7 @@ public void testAlwaysServeStaticContent() throws Exception {
Properties configuration = new Properties();
configuration.put("backend.1.id", "foo");
configuration.put("backend.1.host", "localhost");
- configuration.put("backend.1.port", String.valueOf(backend1.port()));
+ configuration.put("backend.1.port", String.valueOf(backend.port()));
configuration.put("backend.1.enabled", "true");
configuration.put("director.1.id", "*");
@@ -448,7 +452,7 @@ public void testServeACMEChallengeToken() throws Exception {
Properties configuration = new Properties();
configuration.put("backend.1.id", "foo");
configuration.put("backend.1.host", "localhost");
- configuration.put("backend.1.port", String.valueOf(backend1.port()));
+ configuration.put("backend.1.port", String.valueOf(backend.port()));
configuration.put("backend.1.enabled", "true");
configuration.put("director.1.id", "*");
@@ -522,11 +526,11 @@ public void testCustomAndDebuggingHeaders() throws Exception {
Properties configuration = new Properties();
configuration.put("backend.1.id", "b1");
configuration.put("backend.1.host", "localhost");
- configuration.put("backend.1.port", String.valueOf(backend1.port()));
+ configuration.put("backend.1.port", String.valueOf(backend.port()));
configuration.put("backend.1.enabled", "true");
configuration.put("backend.2.id", "b2");
configuration.put("backend.2.host", "localhost");
- configuration.put("backend.2.port", String.valueOf(backend1.port()));
+ configuration.put("backend.2.port", String.valueOf(backend.port()));
configuration.put("backend.2.enabled", "true");
configuration.put("director.1.id", "d1");