21
21
import java .util .UUID ;
22
22
23
23
import javax .jms .ConnectionFactory ;
24
- import javax .jms .Destination ;
25
- import javax .jms .JMSException ;
26
24
import javax .jms .Message ;
27
25
import javax .jms .TextMessage ;
28
26
27
+ import org .apache .activemq .artemis .api .core .RoutingType ;
28
+ import org .apache .activemq .artemis .api .core .SimpleString ;
29
29
import org .apache .activemq .artemis .api .core .TransportConfiguration ;
30
30
import org .apache .activemq .artemis .core .remoting .impl .invm .InVMConnectorFactory ;
31
31
import org .apache .activemq .artemis .core .remoting .impl .netty .NettyConnectorFactory ;
32
+ import org .apache .activemq .artemis .core .server .BindingQueryResult ;
32
33
import org .apache .activemq .artemis .jms .client .ActiveMQConnectionFactory ;
33
34
import org .apache .activemq .artemis .jms .server .config .JMSConfiguration ;
34
35
import org .apache .activemq .artemis .jms .server .config .JMSQueueConfiguration ;
50
51
import org .springframework .context .annotation .Configuration ;
51
52
import org .springframework .jms .connection .CachingConnectionFactory ;
52
53
import org .springframework .jms .core .JmsTemplate ;
53
- import org .springframework .jms .core .SessionCallback ;
54
- import org .springframework .jms .support .destination .DestinationResolver ;
55
- import org .springframework .jms .support .destination .DynamicDestinationResolver ;
56
54
57
55
import static org .assertj .core .api .Assertions .assertThat ;
58
56
@@ -208,9 +206,9 @@ public void embeddedServerWithDestinations() {
208
206
DestinationChecker checker = new DestinationChecker (context );
209
207
checker .checkQueue ("Queue1" , true );
210
208
checker .checkQueue ("Queue2" , true );
211
- checker .checkQueue ("QueueWillNotBeAutoCreated " , true );
209
+ checker .checkQueue ("NonExistentQueue " , false );
212
210
checker .checkTopic ("Topic1" , true );
213
- checker .checkTopic ("TopicWillBeAutoCreated " , true );
211
+ checker .checkTopic ("NonExistentTopic " , false );
214
212
});
215
213
}
216
214
@@ -230,8 +228,8 @@ public void embeddedServiceWithCustomJmsConfiguration() {
230
228
.withPropertyValues ("spring.artemis.embedded.queues=Queue1,Queue2" ).run ((context ) -> {
231
229
DestinationChecker checker = new DestinationChecker (context );
232
230
checker .checkQueue ("custom" , true ); // See CustomJmsConfiguration
233
- checker .checkQueue ("Queue1" , true );
234
- checker .checkQueue ("Queue2" , true );
231
+ checker .checkQueue ("Queue1" , false );
232
+ checker .checkQueue ("Queue2" , false );
235
233
});
236
234
}
237
235
@@ -275,10 +273,10 @@ public void severalEmbeddedBrokers() {
275
273
.isLessThan (secondProperties .getEmbedded ().getServerId ());
276
274
DestinationChecker firstChecker = new DestinationChecker (first );
277
275
firstChecker .checkQueue ("Queue1" , true );
278
- firstChecker .checkQueue ("Queue2" , true );
276
+ firstChecker .checkQueue ("Queue2" , false );
279
277
DestinationChecker secondChecker = new DestinationChecker (second );
278
+ secondChecker .checkQueue ("Queue1" , false );
280
279
secondChecker .checkQueue ("Queue2" , true );
281
- secondChecker .checkQueue ("Queue1" , true );
282
280
});
283
281
});
284
282
}
@@ -295,10 +293,9 @@ public void connectToASpecificEmbeddedBroker() {
295
293
// Do not start a specific one
296
294
"spring.artemis.embedded.enabled=false" )
297
295
.run ((secondContext ) -> {
298
- DestinationChecker firstChecker = new DestinationChecker (first );
299
- firstChecker .checkQueue ("Queue1" , true );
300
- DestinationChecker secondChecker = new DestinationChecker (secondContext );
301
- secondChecker .checkQueue ("Queue1" , true );
296
+ first .getBean (JmsTemplate .class ).convertAndSend ("Queue1" , "test" );
297
+ assertThat (secondContext .getBean (JmsTemplate .class ).receiveAndConvert ("Queue1" ))
298
+ .isEqualTo ("test" );
302
299
});
303
300
});
304
301
}
@@ -394,40 +391,31 @@ private TransportConfiguration getSingleTransportConfiguration(ActiveMQConnectio
394
391
395
392
private static final class DestinationChecker {
396
393
397
- private final JmsTemplate jmsTemplate ;
398
-
399
- private final DestinationResolver destinationResolver ;
394
+ private final EmbeddedJMS embeddedJms ;
400
395
401
396
private DestinationChecker (ApplicationContext applicationContext ) {
402
- this .jmsTemplate = applicationContext .getBean (JmsTemplate .class );
403
- this .destinationResolver = new DynamicDestinationResolver ();
397
+ this .embeddedJms = applicationContext .getBean (EmbeddedJMS .class );
404
398
}
405
399
406
400
public void checkQueue (String name , boolean shouldExist ) {
407
- checkDestination (name , false , shouldExist );
401
+ checkDestination (name , RoutingType . ANYCAST , shouldExist );
408
402
}
409
403
410
404
public void checkTopic (String name , boolean shouldExist ) {
411
- checkDestination (name , true , shouldExist );
405
+ checkDestination (name , RoutingType . MULTICAST , shouldExist );
412
406
}
413
407
414
- public void checkDestination (String name , final boolean pubSub , final boolean shouldExist ) {
415
- this .jmsTemplate .execute ((SessionCallback <Void >) (session ) -> {
416
- try {
417
- Destination destination = this .destinationResolver .resolveDestinationName (session , name , pubSub );
418
- if (!shouldExist ) {
419
- throw new IllegalStateException (
420
- "Destination '" + name + "' was not expected but got " + destination );
421
- }
422
- }
423
- catch (JMSException ex ) {
424
- if (shouldExist ) {
425
- throw new IllegalStateException (
426
- "Destination '" + name + "' was expected but got " + ex .getMessage ());
427
- }
408
+ public void checkDestination (String name , RoutingType routingType , boolean shouldExist ) {
409
+ try {
410
+ BindingQueryResult result = this .embeddedJms .getActiveMQServer ().bindingQuery (new SimpleString (name ));
411
+ assertThat (result .isExists ()).isEqualTo (shouldExist );
412
+ if (shouldExist ) {
413
+ assertThat (result .getAddressInfo ().getRoutingType ()).isEqualTo (routingType );
428
414
}
429
- return null ;
430
- });
415
+ }
416
+ catch (Exception ex ) {
417
+ throw new RuntimeException (ex );
418
+ }
431
419
}
432
420
433
421
}
0 commit comments