18
18
import io .dapr .testcontainers .DaprContainer ;
19
19
import org .junit .runner .Description ;
20
20
import org .junit .runners .model .Statement ;
21
+ import org .springframework .beans .factory .annotation .Qualifier ;
22
+ import org .springframework .boot .test .context .SpringBootTest ;
21
23
import org .springframework .boot .test .context .TestConfiguration ;
22
24
import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
23
25
import org .springframework .context .annotation .Bean ;
24
26
import org .springframework .core .env .Environment ;
25
27
import org .testcontainers .DockerClientFactory ;
28
+ import org .testcontainers .containers .GenericContainer ;
26
29
import org .testcontainers .containers .Network ;
30
+ import org .testcontainers .containers .wait .strategy .Wait ;
31
+ import org .testcontainers .utility .MountableFile ;
27
32
28
33
import java .util .HashMap ;
29
34
import java .util .List ;
@@ -68,6 +73,86 @@ public Statement apply(Statement base, Description description) {
68
73
}
69
74
}
70
75
76
+ private Map <String , String > getRedisProps (){
77
+ Map <String , String > redisProps = new HashMap <>();
78
+ redisProps .put ("redisHost" , "redis:6379" );
79
+ redisProps .put ("redisPassword" , "" );
80
+ redisProps .put ("actorStateStore" , String .valueOf (true ));
81
+ return redisProps ;
82
+ }
83
+
84
+ @ Bean ("workerOneDapr" )
85
+ public DaprContainer workerOneDapr (Network daprNetwork , RedisContainer redisContainer , Environment env ,
86
+ @ Qualifier ("daprContainer" ) DaprContainer orchestratorDaprContainer ) {
87
+ boolean reuse = env .getProperty ("reuse" , Boolean .class , false );
88
+
89
+ return new DaprContainer (DAPR_RUNTIME_IMAGE_TAG )
90
+ .withAppName ("worker-one" )
91
+ .withNetworkAliases ("worker-one-dapr" )
92
+ .withNetwork (daprNetwork )
93
+ .withReusablePlacement (reuse )
94
+ .withReusableScheduler (reuse )
95
+ .withComponent (new Component ("kvstore" , "state.redis" , "v1" , getRedisProps ()))
96
+ // .withDaprLogLevel(DaprLogLevel.DEBUG)
97
+ // .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
98
+ .withAppPort (8081 )
99
+ .withAppHealthCheckPath ("/actuator/health" )
100
+ .withAppChannelAddress ("host.testcontainers.internal" )
101
+ .dependsOn (orchestratorDaprContainer )
102
+ .dependsOn (redisContainer );
103
+ }
104
+ @ Bean
105
+ public GenericContainer <?> workerOneContainer (Network daprNetwork , @ Qualifier ("workerOneDapr" ) DaprContainer workerOneDapr ){
106
+ return new GenericContainer <>("openjdk:17-jdk-slim" )
107
+ .withCopyFileToContainer (MountableFile .forHostPath ("../worker-one/target" ), "/app" )
108
+ .withWorkingDirectory ("/app" )
109
+ .withCommand ("java" ,
110
+ "-Ddapr.grpc.endpoint=worker-one-dapr:50001" ,
111
+ "-Ddapr.http.endpoint=worker-one-dapr:3500" ,
112
+ "-jar" ,
113
+ "worker-one-1.17.0-SNAPSHOT.jar" )
114
+ .withNetwork (daprNetwork )
115
+ .dependsOn (workerOneDapr )
116
+ .waitingFor (Wait .forLogMessage (".*Started WorkerOneApplication.*" , 1 ))
117
+ .withLogConsumer (outputFrame -> System .out .println ("WorkerOneApplication: " + outputFrame .getUtf8String ()));
118
+ }
119
+
120
+ @ Bean ("workerTwoDapr" )
121
+ public DaprContainer workerTwoDapr (Network daprNetwork , RedisContainer redisContainer , Environment env ,
122
+ @ Qualifier ("daprContainer" ) DaprContainer orchestratorDaprContainer ) {
123
+ boolean reuse = env .getProperty ("reuse" , Boolean .class , false );
124
+
125
+ return new DaprContainer (DAPR_RUNTIME_IMAGE_TAG )
126
+ .withAppName ("worker-two" )
127
+ .withNetworkAliases ("worker-two-dapr" )
128
+ .withNetwork (daprNetwork )
129
+ .withReusablePlacement (reuse )
130
+ .withReusableScheduler (reuse )
131
+ .withComponent (new Component ("kvstore" , "state.redis" , "v1" , getRedisProps ()))
132
+ // .withDaprLogLevel(DaprLogLevel.DEBUG)
133
+ // .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
134
+ .withAppPort (8082 )
135
+ .withAppHealthCheckPath ("/actuator/health" )
136
+ .withAppChannelAddress ("host.testcontainers.internal" )
137
+ .dependsOn (orchestratorDaprContainer )
138
+ .dependsOn (redisContainer );
139
+ }
140
+ @ Bean
141
+ public GenericContainer <?> workerTwoContainer (Network daprNetwork , @ Qualifier ("workerTwoDapr" ) DaprContainer workerTwoDapr ){
142
+ return new GenericContainer <>("openjdk:17-jdk-slim" )
143
+ .withCopyFileToContainer (MountableFile .forHostPath ("../worker-two/target" ), "/app" )
144
+ .withWorkingDirectory ("/app" )
145
+ .withCommand ("java" ,
146
+ "-Ddapr.grpc.endpoint=worker-two-dapr:50001" ,
147
+ "-Ddapr.http.endpoint=worker-two-dapr:3500" ,
148
+ "-jar" ,
149
+ "worker-two-1.17.0-SNAPSHOT.jar" )
150
+ .withNetwork (daprNetwork )
151
+ .dependsOn (workerTwoDapr )
152
+ .waitingFor (Wait .forLogMessage (".*Started WorkerTwoApplication.*" , 1 ))
153
+ .withLogConsumer (outputFrame -> System .out .println ("WorkerTwoApplication: " + outputFrame .getUtf8String ()));
154
+ }
155
+
71
156
72
157
@ Bean
73
158
public RedisContainer redisContainer (Network daprNetwork , Environment env ){
@@ -82,17 +167,13 @@ public RedisContainer redisContainer(Network daprNetwork, Environment env){
82
167
@ ServiceConnection
83
168
public DaprContainer daprContainer (Network daprNetwork , RedisContainer redisContainer , Environment env ) {
84
169
boolean reuse = env .getProperty ("reuse" , Boolean .class , false );
85
- Map <String , String > redisProps = new HashMap <>();
86
- redisProps .put ("redisHost" , "redis:6379" );
87
- redisProps .put ("redisPassword" , "" );
88
- redisProps .put ("actorStateStore" , String .valueOf (true ));
89
170
90
171
return new DaprContainer (DAPR_RUNTIME_IMAGE_TAG )
91
172
.withAppName ("orchestrator" )
92
173
.withNetwork (daprNetwork )
93
- .withReusablePlacement (reuse )
94
- .withReusableScheduler (reuse )
95
- .withComponent (new Component ("kvstore" , "state.redis" , "v1" , redisProps ))
174
+ // .withReusablePlacement(reuse)
175
+ // .withReusableScheduler(reuse)
176
+ .withComponent (new Component ("kvstore" , "state.redis" , "v1" , getRedisProps () ))
96
177
// .withDaprLogLevel(DaprLogLevel.DEBUG)
97
178
// .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
98
179
.withAppPort (8080 )
0 commit comments