20
20
import io .dapr .testcontainers .DaprContainer ;
21
21
import io .dapr .testcontainers .DaprLogLevel ;
22
22
import org .junit .jupiter .api .BeforeAll ;
23
- import org .junit .jupiter .api .BeforeEach ;
24
23
import org .junit .jupiter .api .Tag ;
25
24
import org .junit .jupiter .api .Test ;
26
- import org .junit .jupiter .api .Disabled ;
27
25
import org .slf4j .Logger ;
28
26
import org .slf4j .LoggerFactory ;
29
27
import org .springframework .beans .factory .annotation .Autowired ;
30
28
import org .springframework .boot .test .context .SpringBootTest ;
31
29
import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
32
30
import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
33
- import org .springframework .test .context .DynamicPropertyRegistry ;
34
- import org .springframework .test .context .DynamicPropertySource ;
35
31
import org .testcontainers .containers .Network ;
32
+ import org .testcontainers .containers .wait .strategy .Wait ;
36
33
import org .testcontainers .junit .jupiter .Container ;
37
34
import org .testcontainers .junit .jupiter .Testcontainers ;
38
35
@@ -56,16 +53,18 @@ public class DaprSpringMessagingIT {
56
53
private static final Logger logger = LoggerFactory .getLogger (DaprSpringMessagingIT .class );
57
54
58
55
private static final String TOPIC = "mockTopic" ;
59
-
60
56
private static final Network DAPR_NETWORK = Network .newNetwork ();
57
+ private static final int APP_PORT = 8080 ;
58
+ private static final String SUBSCRIPTION_MESSAGE_PATTERN = ".*app is subscribed to the following topics.*" ;
61
59
62
60
@ Container
63
61
@ ServiceConnection
64
62
private static final DaprContainer DAPR_CONTAINER = new DaprContainer ("daprio/daprd:1.13.2" )
65
63
.withAppName ("messaging-dapr-app" )
66
64
.withNetwork (DAPR_NETWORK )
67
65
.withComponent (new Component ("pubsub" , "pubsub.in-memory" , "v1" , Collections .emptyMap ()))
68
- .withAppPort (8080 )
66
+ .withAppPort (APP_PORT )
67
+ .withAppHealthCheckPath ("/ready" )
69
68
.withDaprLogLevel (DaprLogLevel .DEBUG )
70
69
.withLogConsumer (outputFrame -> System .out .println (outputFrame .getUtf8String ()))
71
70
.withAppChannelAddress ("host.testcontainers.internal" );
@@ -78,17 +77,13 @@ public class DaprSpringMessagingIT {
78
77
79
78
@ BeforeAll
80
79
public static void beforeAll (){
81
- org .testcontainers .Testcontainers .exposeHostPorts (8080 );
82
- }
83
-
84
- @ BeforeEach
85
- public void beforeEach () throws InterruptedException {
86
- Thread .sleep (1000 );
80
+ org .testcontainers .Testcontainers .exposeHostPorts (APP_PORT );
87
81
}
88
82
89
83
@ Test
90
- @ Disabled ("Test is flaky due to global state in the spring test application." )
91
84
public void testDaprMessagingTemplate () throws InterruptedException {
85
+ Wait .forLogMessage (SUBSCRIPTION_MESSAGE_PATTERN , 1 ).waitUntilReady (DAPR_CONTAINER );
86
+
92
87
for (int i = 0 ; i < 10 ; i ++) {
93
88
var msg = "ProduceAndReadWithPrimitiveMessageType:" + i ;
94
89
0 commit comments