Skip to content

Commit d3674f5

Browse files
authored
Adding app health check parameters (#1465)
* adding app health check parameters Signed-off-by: salaboy <[email protected]> * fixing style Signed-off-by: salaboy <[email protected]> * testing with configure for coverage Signed-off-by: salaboy <[email protected]> * updating sched api on DaprContainer (#1462) Signed-off-by: salaboy <[email protected]> * fix Artur comments Signed-off-by: salaboy <[email protected]> --------- Signed-off-by: salaboy <[email protected]>
1 parent 1e62c73 commit d3674f5

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,38 @@ 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+
.withAppHealthCheckPath("/test")
54+
.withAppHealthCheckProbeInterval(10)
55+
.withAppHealthCheckProbeTimeout(600)
56+
.withAppHealthCheckThreshold(7);
57+
58+
dapr.configure();
59+
60+
assertEquals(10, dapr.getAppHealthCheckProbeInterval());
61+
assertEquals(600, dapr.getAppHealthCheckProbeTimeout());
62+
assertEquals(7, dapr.getAppHealthCheckThreshold());
63+
assertEquals("/test", dapr.getAppHealthCheckPath());
64+
65+
}
66+
67+
@Test
68+
public void appHealthParametersDefaultsTest(){
69+
//Check that the defaults are set by default
70+
DaprContainer dapr2 = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
71+
.withAppName("dapr2-app")
72+
.withAppPort(8082);
73+
74+
dapr2.configure();
75+
76+
assertEquals(5, dapr2.getAppHealthCheckProbeInterval());
77+
assertEquals(500, dapr2.getAppHealthCheckProbeTimeout());
78+
assertEquals(3, dapr2.getAppHealthCheckThreshold());
79+
80+
}
4781
}

0 commit comments

Comments
 (0)