Skip to content

Commit da74502

Browse files
committed
adding app health check parameters
Signed-off-by: salaboy <[email protected]>
1 parent a822f8b commit da74502

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
7777
private String appName;
7878
private Integer appPort;
7979
private String appHealthCheckPath;
80+
private Integer appHealthCheckProbeInterval = 5; //default from docs
81+
private Integer appHealthCheckProbeTimeout = 500; //default from docs
82+
private Integer appHealthCheckThreshold = 3; //default from docs
8083
private boolean shouldReusePlacement;
8184
private boolean shouldReuseScheduler;
8285

@@ -133,6 +136,21 @@ public DaprContainer withAppHealthCheckPath(String appHealthCheckPath) {
133136
return this;
134137
}
135138

139+
public DaprContainer withAppHealthCheckProbeInterval(Integer appHealthCheckProbeInterval) {
140+
this.appHealthCheckProbeInterval = appHealthCheckProbeInterval;
141+
return this;
142+
}
143+
144+
public DaprContainer withAppHealthCheckProbeTimeout(Integer appHealthCheckProbeTimeout){
145+
this.appHealthCheckProbeTimeout = appHealthCheckProbeTimeout;
146+
return this;
147+
}
148+
149+
public DaprContainer withAppHealthCheckThreshold(Integer appHealthCheckThreshold ){
150+
this.appHealthCheckThreshold = appHealthCheckThreshold;
151+
return this;
152+
}
153+
136154
public DaprContainer withConfiguration(Configuration configuration) {
137155
this.configuration = configuration;
138156
return this;
@@ -311,6 +329,16 @@ protected void configure() {
311329
cmds.add("--enable-app-health-check");
312330
cmds.add("--app-health-check-path");
313331
cmds.add(appHealthCheckPath);
332+
333+
cmds.add("--app-health-probe-interval");
334+
cmds.add(Integer.toString(appHealthCheckProbeInterval));
335+
336+
cmds.add("--app-health-probe-timeout");
337+
cmds.add(Integer.toString(appHealthCheckProbeTimeout));
338+
339+
cmds.add("--app-health-threshold");
340+
cmds.add(Integer.toString(appHealthCheckThreshold));
341+
314342
}
315343

316344
if (configuration != null) {
@@ -385,6 +413,22 @@ public Integer getAppPort() {
385413
return appPort;
386414
}
387415

416+
public String getAppHealthCheckPath() {
417+
return appHealthCheckPath;
418+
}
419+
420+
public Integer getAppHealthCheckProbeInterval() {
421+
return appHealthCheckProbeInterval;
422+
}
423+
424+
public Integer getAppHealthCheckProbeTimeout() {
425+
return appHealthCheckProbeTimeout;
426+
}
427+
428+
public Integer getAppHealthCheckThreshold() {
429+
return appHealthCheckThreshold;
430+
}
431+
388432
public String getAppChannelAddress() {
389433
return appChannelAddress;
390434
}

testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprContainerTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
77
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_VERSION;
8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.*;
99

1010
public class DaprContainerTest {
1111

@@ -44,4 +44,30 @@ public void schedulerAndPlacementCustomImagesStringTest() {
4444
assertEquals("daprio/scheduler:" + DAPR_VERSION, dapr.getSchedulerDockerImageName().asCanonicalNameString());
4545

4646
}
47+
48+
@Test
49+
public void appHealthParametersTest(){
50+
DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
51+
.withAppName("dapr-app")
52+
.withAppPort(8081)
53+
.withAppHealthCheckProbeInterval(10)
54+
.withAppHealthCheckProbeTimeout(600)
55+
.withAppHealthCheckThreshold(7);
56+
57+
assertEquals(10, dapr.getAppHealthCheckProbeInterval());
58+
assertEquals(600, dapr.getAppHealthCheckProbeTimeout());
59+
assertEquals(7, dapr.getAppHealthCheckThreshold());
60+
61+
62+
//Check that the defaults are set by default
63+
DaprContainer dapr2 = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
64+
.withAppName("dapr2-app")
65+
.withAppPort(8082);
66+
67+
assertEquals(5, dapr2.getAppHealthCheckProbeInterval());
68+
assertEquals(500, dapr2.getAppHealthCheckProbeTimeout());
69+
assertEquals(3, dapr2.getAppHealthCheckThreshold());
70+
71+
72+
}
4773
}

0 commit comments

Comments
 (0)