34
34
import org .testcontainers .junit .jupiter .Testcontainers ;
35
35
36
36
import java .util .Map ;
37
+ import java .util .Random ;
37
38
import java .util .UUID ;
38
39
39
40
import static org .junit .jupiter .api .Assertions .assertEquals ;
40
41
41
42
@ SpringBootTest (
42
- webEnvironment = WebEnvironment .DEFINED_PORT ,
43
- classes = {
44
- TestActorsApplication .class ,
45
- TestDaprActorsConfiguration .class
46
- },
47
- properties = {
48
- "server.port=64080" , // must be constant, not a static attribute from class below.
49
- }
43
+ webEnvironment = WebEnvironment .RANDOM_PORT ,
44
+ classes = {
45
+ TestActorsApplication .class ,
46
+ TestDaprActorsConfiguration .class
47
+ }
50
48
)
51
49
@ Testcontainers
52
50
@ Tag ("testcontainers" )
53
51
public class DaprActorsIT {
54
-
55
- private static final int APP_PORT = 64080 ;
56
-
57
52
private static final Network DAPR_NETWORK = Network .newNetwork ();
53
+ private static final Random RANDOM = new Random ();
54
+ private static final int PORT = RANDOM .nextInt (1000 ) + 8000 ;
58
55
59
56
private static final String ACTORS_MESSAGE_PATTERN = ".*Actor API level in the cluster has been updated to 10.*" ;
60
57
61
58
@ Container
62
59
private static final DaprContainer DAPR_CONTAINER = new DaprContainer ("daprio/daprd:1.14.4" )
63
- .withAppName ("actor-dapr-app" )
64
- .withNetwork (DAPR_NETWORK )
65
- .withComponent (new Component ("kvstore" , "state.in-memory" , "v1" ,
66
- Map .of ("actorStateStore" , "true" )))
67
- .withDaprLogLevel (DaprLogLevel .DEBUG )
68
- .withLogConsumer (outputFrame -> System .out .println (outputFrame .getUtf8String ()))
69
- .withAppChannelAddress ("host.testcontainers.internal" )
70
- .withAppPort (APP_PORT );
60
+ .withAppName ("actor-dapr-app" )
61
+ .withNetwork (DAPR_NETWORK )
62
+ .withComponent (new Component ("kvstore" , "state.in-memory" , "v1" ,
63
+ Map .of ("actorStateStore" , "true" )))
64
+ .withDaprLogLevel (DaprLogLevel .DEBUG )
65
+ .withLogConsumer (outputFrame -> System .out .println (outputFrame .getUtf8String ()))
66
+ .withAppChannelAddress ("host.testcontainers.internal" )
67
+ .withAppPort (PORT );
71
68
72
69
/**
73
70
* Expose the Dapr ports to the host.
@@ -78,6 +75,7 @@ public class DaprActorsIT {
78
75
static void daprProperties (DynamicPropertyRegistry registry ) {
79
76
registry .add ("dapr.http.endpoint" , DAPR_CONTAINER ::getHttpEndpoint );
80
77
registry .add ("dapr.grpc.endpoint" , DAPR_CONTAINER ::getGrpcEndpoint );
78
+ registry .add ("server.port" , () -> PORT );
81
79
}
82
80
83
81
@ Autowired
@@ -88,15 +86,14 @@ static void daprProperties(DynamicPropertyRegistry registry) {
88
86
89
87
@ BeforeEach
90
88
public void setUp (){
91
- org .testcontainers .Testcontainers .exposeHostPorts (APP_PORT );
89
+ org .testcontainers .Testcontainers .exposeHostPorts (PORT );
92
90
daprActorRuntime .registerActor (TestActorImpl .class );
93
91
// Ensure the subscriptions are registered
94
92
Wait .forLogMessage (ACTORS_MESSAGE_PATTERN , 1 ).waitUntilReady (DAPR_CONTAINER );
95
93
}
96
94
97
95
@ Test
98
- public void testActors () throws Exception {
99
-
96
+ public void testActors () {
100
97
ActorProxyBuilder <TestActor > builder = new ActorProxyBuilder <>(TestActor .class , daprActorClient );
101
98
ActorId actorId = ActorId .createRandom ();
102
99
TestActor actor = builder .build (actorId );
@@ -107,4 +104,4 @@ public void testActors() throws Exception {
107
104
108
105
assertEquals (echoedMessage , message );
109
106
}
110
- }
107
+ }
0 commit comments