37
37
import java .util .concurrent .atomic .AtomicBoolean ;
38
38
import java .util .concurrent .atomic .AtomicInteger ;
39
39
import java .util .concurrent .atomic .AtomicReference ;
40
- import java .util .function .Consumer ;
40
+ import java .util .function .BiConsumer ;
41
41
import java .util .function .Function ;
42
42
import java .util .function .UnaryOperator ;
43
43
import java .util .stream .IntStream ;
44
44
import java .util .stream .Stream ;
45
+ import org .jetbrains .annotations .NotNull ;
45
46
import org .junit .jupiter .api .*;
46
47
import org .slf4j .Logger ;
47
48
import org .slf4j .LoggerFactory ;
@@ -108,26 +109,7 @@ void clusterRestart() {
108
109
Management .QueueType .QUORUM ,
109
110
Management .QueueType .CLASSIC ,
110
111
Management .QueueType .CLASSIC );
111
- AtomicInteger classicQueueCount = new AtomicInteger (0 );
112
- List <QueueConfiguration > queueConfigurations =
113
- queueTypes .stream ()
114
- .flatMap (
115
- (Function <Management .QueueType , Stream <QueueConfiguration >>)
116
- type ->
117
- IntStream .range (0 , queueCount )
118
- .mapToObj (
119
- ignored -> {
120
- boolean exclusive =
121
- type == Management .QueueType .CLASSIC
122
- && classicQueueCount .incrementAndGet () > queueCount ;
123
- String prefix =
124
- type .name ().toLowerCase () + (exclusive ? "-ex-" : "-" );
125
- String n = name (prefix );
126
- UnaryOperator <Management .QueueSpecification > c =
127
- s -> s .type (type ).exclusive (exclusive );
128
- return new QueueConfiguration (n , type , exclusive , c );
129
- }))
130
- .collect (toList ());
112
+ List <QueueConfiguration > queueConfigurations = queueConfigurations (queueTypes , queueCount );
131
113
List <String > queueNames = queueConfigurations .stream ().map (c -> c .name ).collect (toList ());
132
114
List <PublisherState > publisherStates = Collections .emptyList ();
133
115
List <ConsumerState > consumerStates = Collections .emptyList ();
@@ -152,10 +134,12 @@ void clusterRestart() {
152
134
.destinationQueue (conf .name )
153
135
.bind ();
154
136
} else {
137
+ boolean isolate = conf .type == Management .QueueType .STREAM ;
155
138
c =
156
139
connection (
157
140
b ->
158
141
b .name (cName )
142
+ .isolateResources (isolate )
159
143
.affinity ()
160
144
.queue (conf .name )
161
145
.operation (CONSUME )
@@ -210,6 +194,7 @@ void clusterRestart() {
210
194
waitAtMostNoException (TIMEOUT , () -> management .queueInfo (n ));
211
195
});
212
196
LOGGER .info ("Retrieved info for each queue." );
197
+
213
198
queueConfigurations .forEach (
214
199
c -> {
215
200
if (c .type == Management .QueueType .QUORUM || c .type == Management .QueueType .STREAM ) {
@@ -258,10 +243,16 @@ void clusterRestart() {
258
243
p -> System .out .printf (" queue %s, is on member? %s%n" , p .queue , p .isOnMember ()));
259
244
} catch (Throwable e ) {
260
245
LOGGER .info ("Test failed with {}" , e .getMessage (), e );
261
- Consumer <AmqpConnection > log = c -> LOGGER .info ("Connection {}: {}" , c .name (), c .state ());
262
- log .accept (this .connection );
263
- publisherStates .forEach (s -> log .accept (s .connection ));
264
- consumerStates .forEach (s -> log .accept (s .connection ));
246
+ BiConsumer <AmqpConnection , ResourceBase > log =
247
+ (c , r ) -> {
248
+ LOGGER .info ("Connection {}: {}" , c .name (), c .state ());
249
+ if (r != null ) {
250
+ LOGGER .info ("Resource: {}" , r .state ());
251
+ }
252
+ };
253
+ log .accept (this .connection , null );
254
+ publisherStates .forEach (s -> log .accept (s .connection , s .publisher ));
255
+ consumerStates .forEach (s -> log .accept (s .connection , s .consumer ));
265
256
throw e ;
266
257
} finally {
267
258
publisherStates .forEach (PublisherState ::close );
@@ -272,6 +263,30 @@ void clusterRestart() {
272
263
}
273
264
}
274
265
266
+ @ NotNull
267
+ private List <QueueConfiguration > queueConfigurations (
268
+ List <Management .QueueType > queueTypes , int queueCount ) {
269
+ AtomicInteger classicQueueCount = new AtomicInteger (0 );
270
+ return queueTypes .stream ()
271
+ .flatMap (
272
+ (Function <Management .QueueType , Stream <QueueConfiguration >>)
273
+ type ->
274
+ IntStream .range (0 , queueCount )
275
+ .mapToObj (
276
+ ignored -> {
277
+ boolean exclusive =
278
+ type == Management .QueueType .CLASSIC
279
+ && classicQueueCount .incrementAndGet () > queueCount ;
280
+ String prefix =
281
+ type .name ().toLowerCase () + (exclusive ? "-ex-" : "-" );
282
+ String n = name (prefix );
283
+ UnaryOperator <Management .QueueSpecification > c =
284
+ s -> s .type (type ).exclusive (exclusive );
285
+ return new QueueConfiguration (n , type , exclusive , c );
286
+ }))
287
+ .collect (toList ());
288
+ }
289
+
275
290
String name (String prefix ) {
276
291
return prefix + TestUtils .name (this .testInfo );
277
292
}
@@ -328,7 +343,9 @@ void start() {
328
343
}
329
344
330
345
Sync waitForNewMessages (int messageCount ) {
331
- TestUtils .Sync sync = TestUtils .sync (messageCount , () -> this .postAccepted .set (() -> {}));
346
+ TestUtils .Sync sync =
347
+ TestUtils .sync (
348
+ messageCount , () -> this .postAccepted .set (() -> {}), "Publisher to '%s'" , this .queue );
332
349
this .postAccepted .set (sync ::down );
333
350
return sync ;
334
351
}
@@ -383,7 +400,9 @@ private ConsumerState(String queue, AmqpConnection connection) {
383
400
}
384
401
385
402
TestUtils .Sync waitForNewMessages (int messageCount ) {
386
- TestUtils .Sync sync = TestUtils .sync (messageCount , () -> this .postHandle .set (() -> {}));
403
+ TestUtils .Sync sync =
404
+ TestUtils .sync (
405
+ messageCount , () -> this .postHandle .set (() -> {}), "Consumer from '%s'" , this .queue );
387
406
this .postHandle .set (sync ::down );
388
407
return sync ;
389
408
}
0 commit comments