Skip to content

Commit

Permalink
adding @Serviceconnection to Dapr
Browse files Browse the repository at this point in the history
  • Loading branch information
salaboy committed Sep 4, 2024
1 parent 0e051a3 commit 1307148
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class DaprKeyValueRepositoryIT {
.withNetwork(DAPR_NETWORK);

@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
.withAppName("postgresql-repository-dapr-app")
.withNetwork(DAPR_NETWORK)
Expand All @@ -74,14 +76,6 @@ public class DaprKeyValueRepositoryIT {
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.dependsOn(POSTGRE_SQL_CONTAINER);

@DynamicPropertySource
static void daprProperties(DynamicPropertyRegistry registry) {
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
registry.add("dapr.grpc.port", DAPR_CONTAINER::getGrpcPort);
registry.add("dapr.http.port", DAPR_CONTAINER::getHttpPort);
}

private static Map<String, String> createStateStoreProperties() {
Map<String, String> result = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class MySQLDaprKeyValueTemplateIT {
.waitingFor(MYSQL_WAIT_STRATEGY);

@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
.withAppName("mysql-dapr-app")
.withNetwork(DAPR_NETWORK)
Expand All @@ -89,13 +91,6 @@ public class MySQLDaprKeyValueTemplateIT {
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.dependsOn(MY_SQL_CONTAINER);

@DynamicPropertySource
static void daprProperties(DynamicPropertyRegistry registry) {
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
registry.add("dapr.grpc.port", DAPR_CONTAINER::getGrpcPort);
registry.add("dapr.http.port", DAPR_CONTAINER::getHttpPort);
}

private static Map<String, String> createStateStoreProperties() {
Map<String, String> result = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
Expand Down Expand Up @@ -66,6 +67,7 @@ public class PostgreSQLDaprKeyValueTemplateIT {
.withNetwork(DAPR_NETWORK);

@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
.withAppName("postgresql-dapr-app")
.withNetwork(DAPR_NETWORK)
Expand All @@ -75,13 +77,6 @@ public class PostgreSQLDaprKeyValueTemplateIT {
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.dependsOn(POSTGRE_SQL_CONTAINER);

@DynamicPropertySource
static void daprProperties(DynamicPropertyRegistry registry) {
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
registry.add("dapr.grpc.port", DAPR_CONTAINER::getGrpcPort);
registry.add("dapr.http.port", DAPR_CONTAINER::getHttpPort);
}

private static Map<String, String> createStateStoreProperties() {
Map<String, String> result = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.Network;
Expand Down Expand Up @@ -56,6 +58,7 @@ public class DaprSpringMessagingIT {
private static final Network DAPR_NETWORK = Network.newNetwork();

@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
.withAppName("messaging-dapr-app")
.withNetwork(DAPR_NETWORK)
Expand All @@ -65,22 +68,17 @@ public class DaprSpringMessagingIT {
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withAppChannelAddress("host.testcontainers.internal");

@DynamicPropertySource
static void daprProperties(DynamicPropertyRegistry registry) {
org.testcontainers.Testcontainers.exposeHostPorts(8080);

registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
registry.add("dapr.grpc.port", DAPR_CONTAINER::getGrpcPort);
registry.add("dapr.http.port", DAPR_CONTAINER::getHttpPort);
}

@Autowired
private DaprMessagingTemplate<String> messagingTemplate;

@Autowired
private TestRestController testRestController;

@BeforeEach
public void setup(){
org.testcontainers.Testcontainers.exposeHostPorts(8080);
}

@Test
public void testDaprMessagingTemplate() throws InterruptedException {
for (int i = 0; i < 10; i++) {
Expand Down

0 comments on commit 1307148

Please sign in to comment.