31
31
import org .testcontainers .utility .MountableFile ;
32
32
33
33
import java .io .ByteArrayInputStream ;
34
- import java .util .concurrent .TimeoutException ;
35
34
import java .util .stream .Collectors ;
36
35
37
36
import static java .util .concurrent .TimeUnit .SECONDS ;
@@ -51,7 +50,18 @@ class AzureDiscoveryExtensionIT {
51
50
new GenericContainer <>(OciImages .getImageName ("azure-storage/azurite" )) //
52
51
.withExposedPorts (AZURITE_PORT ) //
53
52
.withNetwork (network ) //
54
- .withNetworkAliases (AZURITE_NETWORK_ALIAS );
53
+ .withNetworkAliases (AZURITE_NETWORK_ALIAS ) //
54
+ .withLogConsumer (outputFrame -> System .out .printf ("[AZURITE] %s" , outputFrame .getUtf8String ())) //
55
+ .withCommand ("azurite" ,
56
+ // listen on all network interfaces within the container
57
+ "--blobHost" ,
58
+ "0.0.0.0" ,
59
+ "--queueHost" ,
60
+ "0.0.0.0" ,
61
+ "--tableHost" ,
62
+ "0.0.0.0" ,
63
+ // prevent test failure when azure-storage-blob is updated before azurite supports its new API version
64
+ "--skipApiVersionCheck" );
55
65
56
66
@ BeforeEach
57
67
void setUp () {
@@ -65,7 +75,7 @@ void tearDown() {
65
75
}
66
76
67
77
@ Test
68
- void threeNodesFormCluster () throws TimeoutException {
78
+ void threeNodesFormCluster () throws Exception {
69
79
final var consumer1 = new WaitingConsumer ();
70
80
final var consumer2 = new WaitingConsumer ();
71
81
final var consumer3 = new WaitingConsumer ();
@@ -86,7 +96,7 @@ void threeNodesFormCluster() throws TimeoutException {
86
96
}
87
97
88
98
@ Test
89
- void twoNodesInCluster_oneNodeStarted_threeNodesInCluster () throws TimeoutException {
99
+ void twoNodesInCluster_oneNodeStarted_threeNodesInCluster () throws Exception {
90
100
final var consumer1 = new WaitingConsumer ();
91
101
final var consumer2 = new WaitingConsumer ();
92
102
final var consumer3 = new WaitingConsumer ();
@@ -106,7 +116,7 @@ void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws TimeoutExcept
106
116
}
107
117
108
118
@ Test
109
- void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted () throws TimeoutException {
119
+ void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted () throws Exception {
110
120
final var toxiproxy = new ToxiproxyContainer (OciImages .getImageName ("shopify/toxiproxy" )) //
111
121
.withNetwork (network ).withNetworkAliases (TOXIPROXY_NETWORK_ALIAS );
112
122
try (toxiproxy ) {
@@ -142,7 +152,7 @@ void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws TimeoutE
142
152
}
143
153
144
154
@ Test
145
- void threeNodesInCluster_oneNodeStopped_twoNodesInCluster () throws TimeoutException {
155
+ void threeNodesInCluster_oneNodeStopped_twoNodesInCluster () throws Exception {
146
156
final var consumer1 = new WaitingConsumer ();
147
157
final var consumer2 = new WaitingConsumer ();
148
158
final var consumer3 = new WaitingConsumer ();
@@ -174,15 +184,11 @@ void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws TimeoutExcept
174
184
175
185
@ Test
176
186
@ SuppressWarnings ("HttpUrlsUsage" )
177
- void wrongConnectionString_reloadRightConnectionString_clusterCreated () throws TimeoutException {
178
- final var wrongConnectionString = "DefaultEndpointsProtocol=http;" +
187
+ void wrongConnectionString_reloadRightConnectionString_clusterCreated () throws Exception {
188
+ final var wrongConnectionString = String . format ( "DefaultEndpointsProtocol=http;" +
179
189
"AccountName=devstoreaccount1;" +
180
190
"AccountKey=XXX8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
181
- "BlobEndpoint=http://" +
182
- AZURITE_NETWORK_ALIAS +
183
- ":" +
184
- AZURITE_PORT +
185
- "/devstoreaccount1" ;
191
+ "BlobEndpoint=http://%s:%d/devstoreaccount1" , AZURITE_NETWORK_ALIAS , AZURITE_PORT );
186
192
187
193
final var consumer = new WaitingConsumer ();
188
194
@@ -235,33 +241,24 @@ void containerExisting_nodeStarted_containerUsed() {
235
241
}
236
242
}
237
243
238
- @ SuppressWarnings ("HttpUrlsUsage" )
239
- private @ NotNull String createAzuriteConnectionString (final @ NotNull String host , final int port ) {
240
- return "DefaultEndpointsProtocol=http;" +
241
- //
242
- "AccountName=devstoreaccount1;" +
243
- "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
244
- "BlobEndpoint=http://" +
245
- host +
246
- ":" +
247
- port +
248
- "/devstoreaccount1" ;
244
+ private @ NotNull String createHostAzuriteConnectionString () {
245
+ return createAzuriteConnectionString ("127.0.0.1" , azuriteContainer .getMappedPort (AZURITE_PORT ));
249
246
}
250
247
251
248
private @ NotNull String createDockerAzuriteConnectionString () {
252
249
return createAzuriteConnectionString (AZURITE_NETWORK_ALIAS , AZURITE_PORT );
253
250
}
254
251
255
- private @ NotNull String createConfig ( final @ NotNull String connectionString ) {
256
- return "connection-string=" + connectionString + '\n' + //
257
- "container-name= " + BLOB_CONTAINER_NAME + '\n' + //
258
- "file-prefix=hivemq-node- \n " + //
259
- "file-expiration=15 \n " + //
260
- "update-interval=5" ;
252
+ @ SuppressWarnings ( "HttpUrlsUsage" )
253
+ private @ NotNull String createAzuriteConnectionString ( final @ NotNull String host , final int port ) {
254
+ return String . format ( "DefaultEndpointsProtocol=http; " +
255
+ "AccountName=devstoreaccount1; " +
256
+ "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==; " +
257
+ "BlobEndpoint=http://%s:%s/devstoreaccount1" , host , port ) ;
261
258
}
262
259
263
- private @ NotNull String createHostAzuriteConnectionString () {
264
- return createAzuriteConnectionString ( "127.0.0.1" , azuriteContainer . getMappedPort ( AZURITE_PORT ));
260
+ private @ NotNull HiveMQContainer createHiveMQNode () {
261
+ return createHiveMQNode ( createDockerAzuriteConnectionString ( ));
265
262
}
266
263
267
264
private @ NotNull HiveMQContainer createHiveMQNode (final @ NotNull String connectionString ) {
@@ -273,7 +270,10 @@ void containerExisting_nodeStarted_containerUsed() {
273
270
.withNetwork (network );
274
271
}
275
272
276
- private @ NotNull HiveMQContainer createHiveMQNode () {
277
- return createHiveMQNode (createDockerAzuriteConnectionString ());
273
+ private @ NotNull String createConfig (final @ NotNull String connectionString ) {
274
+ return String .format (
275
+ "connection-string=%s\n container-name=%s\n file-prefix=hivemq-node-\n file-expiration=15\n update-interval=5" ,
276
+ connectionString ,
277
+ BLOB_CONTAINER_NAME );
278
278
}
279
279
}
0 commit comments