Skip to content

Commit

Permalink
fixing actors IT test and messaging IT with app-health-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
salaboy committed Feb 7, 2025
1 parent cae1e9e commit fe76f18
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import io.dapr.testcontainers.Subscription;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
Expand All @@ -45,7 +46,7 @@
webEnvironment = WebEnvironment.DEFINED_PORT,
classes = {
DaprClientAutoConfiguration.class,
TestApplication.class
TestApplication.class, TestRestController.class
},
properties = {"dapr.pubsub.name=pubsub"}
)
Expand All @@ -61,10 +62,11 @@ public class DaprSpringMessagingIT {

@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.14.4")
.withAppName("messaging-dapr-app")
.withNetwork(DAPR_NETWORK)
.withComponent(new Component("pubsub", "pubsub.in-memory", "v1", Collections.emptyMap()))
.withSubscription(new Subscription("my-app-subscription", "pubsub", "mockTopic", "subscribe"))
.withAppPort(8080)
.withDaprLogLevel(DaprLogLevel.DEBUG)
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
Expand All @@ -81,14 +83,10 @@ public static void beforeAll(){
org.testcontainers.Testcontainers.exposeHostPorts(8080);
}

@BeforeEach
public void beforeEach() throws InterruptedException {
Thread.sleep(1000);
}

@Test
@Disabled("Test is flaky due to global state in the spring test application.")
public void testDaprMessagingTemplate() throws InterruptedException {
Thread.sleep(10000);
for (int i = 0; i < 10; i++) {
var msg = "ProduceAndReadWithPrimitiveMessageType:" + i;

Expand All @@ -98,7 +96,7 @@ public void testDaprMessagingTemplate() throws InterruptedException {
}

// Wait for the messages to arrive
Thread.sleep(1000);
Thread.sleep(10000);

List<CloudEvent<String>> events = testRestController.getEvents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ public class TestRestController {
private static final Logger LOG = LoggerFactory.getLogger(TestRestController.class);
private final List<CloudEvent<String>> events = new ArrayList<>();

@GetMapping("/")
public TestRestController() {
System.out.println("TestRestController started...");
}

@GetMapping("/actuator/health")
public String ok() {
return "OK";
}

@Topic(name = topicName, pubsubName = pubSubName)
@PostMapping("/subscribe")
@PostMapping("subscribe")
public void handleMessages(@RequestBody CloudEvent<String> event) {
LOG.info("++++++CONSUME {}------", event);
events.add(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
webEnvironment = WebEnvironment.DEFINED_PORT,
classes = {
TestActorsApplication.class,
TestDaprActorsConfiguration.class
Expand All @@ -44,7 +44,8 @@ public class DaprActorsIT {
Map.of("actorStateStore", "true")))
.withDaprLogLevel(DaprLogLevel.DEBUG)
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withAppChannelAddress("host.testcontainers.internal");
.withAppChannelAddress("host.testcontainers.internal")
.withAppPort(8080);

/**
* Expose the Dapr ports to the host.
Expand All @@ -65,11 +66,14 @@ static void daprProperties(DynamicPropertyRegistry registry) {

@BeforeEach
public void setUp(){
org.testcontainers.Testcontainers.exposeHostPorts(8080);
daprActorRuntime.registerActor(TestActorImpl.class);
}

@Test
public void testActors() throws Exception {
Thread.sleep(10000);

ActorProxyBuilder<TestActor> builder = new ActorProxyBuilder<>(TestActor.class, daprActorClient);
ActorId actorId = ActorId.createRandom();
TestActor actor = builder.build(actorId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class TestActorsApplication {

public static void main(String[] args) {
SpringApplication.run(TestActorsApplication.class, args);
}

//Mocking the actuator health endpoint for the sidecar health check
@GetMapping("/actuator/health")
public String health(){
return "OK";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,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 fe76f18

Please sign in to comment.