Skip to content

Commit

Permalink
adding health check from the sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
salaboy committed Feb 7, 2025
1 parent abbdf7c commit 220b71e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.dapr.springboot.examples.consumer;

import io.dapr.client.DaprClient;
import io.dapr.spring.messaging.DaprMessagingTemplate;
import io.dapr.springboot.DaprAutoConfiguration;
import io.restassured.RestAssured;
Expand Down Expand Up @@ -29,6 +30,9 @@ class ConsumerAppTests {
@Autowired
private SubscriberRestController subscriberRestController;

@Autowired
private DaprClient daprClient;

@BeforeAll
public static void setup() {
org.testcontainers.Testcontainers.exposeHostPorts(8081);
Expand All @@ -37,14 +41,18 @@ public static void setup() {
@BeforeEach
void setUp() {
RestAssured.baseURI = "http://localhost:" + 8081;

}


@Test
void testMessageConsumer() throws InterruptedException, IOException {

messagingTemplate.send("topic", new Order("abc-123", "the mars volta LP", 1));
Thread.sleep(10000);

daprClient.waitForSidecar(10000).block();

messagingTemplate.send("topic", new Order("abc-123", "the mars volta LP", 1));

given()
.contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import io.dapr.testcontainers.Subscription;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.boot.test.context.TestConfiguration;
Expand Down Expand Up @@ -96,6 +97,7 @@ public DaprContainer daprContainer(Network daprNetwork, PostgreSQLContainer<?> p
.withComponent(new Component("kvstore", "state.postgresql", "v1", STATE_STORE_PROPERTIES))
.withComponent(new Component("kvbinding", "bindings.postgresql", "v1", BINDING_PROPERTIES))
.withComponent(new Component("pubsub", "pubsub.rabbitmq", "v1", rabbitMqProperties))
.withSubscription(new Subscription("app", "pubsub", "topic", "/subscribe"))
.withDaprLogLevel(DaprLogLevel.DEBUG)
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withAppPort(8080)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.dapr.springboot.examples.producer;

import io.dapr.client.DaprClient;
import io.dapr.springboot.DaprAutoConfiguration;
import io.dapr.springboot.examples.producer.workflow.CustomerFollowupActivity;
import io.dapr.springboot.examples.producer.workflow.CustomerWorkflow;
Expand Down Expand Up @@ -33,6 +34,9 @@ class ProducerAppTests {
@Autowired
private CustomerStore customerStore;

@Autowired
private DaprClient daprClient;

@BeforeAll
public static void setup(){
org.testcontainers.Testcontainers.exposeHostPorts(8080);
Expand All @@ -41,11 +45,14 @@ public static void setup(){
@BeforeEach
void setUp() {
RestAssured.baseURI = "http://localhost:" + 8080;

}


@Test
void testOrdersEndpointAndMessaging() throws InterruptedException, IOException {
Thread.sleep(10000);

given()
.contentType(ContentType.JSON)
.body("{ \"id\": \"abc-123\",\"item\": \"the mars volta LP\",\"amount\": 1}")
Expand Down Expand Up @@ -101,6 +108,9 @@ void testOrdersEndpointAndMessaging() throws InterruptedException, IOException {

@Test
void testCustomersWorkflows() throws InterruptedException, IOException {

Thread.sleep(10000);

given()
.contentType(ContentType.JSON)
.body("{\"customerName\": \"salaboy\"}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ protected void configure() {
cmds.add(Integer.toString(appPort));
}

cmds.add("--enable-app-health-check");
cmds.add("--app-health-check-path");
cmds.add("/actuator/health");

if (configuration != null) {
cmds.add("--config");
cmds.add("/dapr-resources/" + configuration.getName() + ".yaml");
Expand Down

0 comments on commit 220b71e

Please sign in to comment.