Skip to content

Commit 4388aeb

Browse files
committed
network is needed
1 parent 9c48b68 commit 4388aeb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

spring-boot-examples/workflows/src/test/java/io/dapr/springboot/examples/wfp/DaprTestContainersConfig.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import org.springframework.context.annotation.Bean;
2424
import org.springframework.core.env.Environment;
2525
import org.springframework.test.context.DynamicPropertyRegistrar;
26+
import org.testcontainers.DockerClientFactory;
2627
import org.testcontainers.containers.Network;
2728

2829
import java.util.Collections;
30+
import java.util.List;
2931

3032
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
3133

@@ -64,7 +66,9 @@ public DynamicPropertyRegistrar endpointsProperties(MicrocksContainersEnsemble e
6466

6567
@Bean
6668
public Network getDaprNetwork(Environment env) {
67-
return new Network() {
69+
boolean reuse = env.getProperty("reuse", Boolean.class, false);
70+
if (reuse) {
71+
Network defaultDaprNetwork = new Network() {
6872
@Override
6973
public String getId() {
7074
return "dapr-network";
@@ -80,6 +84,18 @@ public Statement apply(Statement base, Description description) {
8084
return null;
8185
}
8286
};
87+
88+
List<com.github.dockerjava.api.model.Network> networks = DockerClientFactory.instance().client().listNetworksCmd()
89+
.withNameFilter("dapr-network").exec();
90+
if (networks.isEmpty()) {
91+
Network.builder().createNetworkCmdModifier(cmd -> cmd.withName("dapr-network")).build().getId();
92+
return defaultDaprNetwork;
93+
} else {
94+
return defaultDaprNetwork;
95+
}
96+
} else {
97+
return Network.newNetwork();
98+
}
8399
}
84100

85101
}

0 commit comments

Comments
 (0)