1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -371,24 +371,33 @@ public void testNoListenerAllowed2() {
371
371
@ SuppressWarnings ("unchecked" )
372
372
public void testRoutingConnectionFactory () throws Exception {
373
373
org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory1 =
374
- Mockito . mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
374
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
375
375
org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory2 =
376
- Mockito .mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
376
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
377
+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory3 =
378
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
379
+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory4 =
380
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
377
381
Map <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory > factories =
378
382
new HashMap <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory >(2 );
379
383
factories .put ("foo" , connectionFactory1 );
380
384
factories .put ("bar" , connectionFactory2 );
385
+ factories .put ("baz" , connectionFactory3 );
386
+ factories .put ("qux" , connectionFactory4 );
381
387
382
388
383
389
AbstractRoutingConnectionFactory connectionFactory = new SimpleRoutingConnectionFactory ();
384
390
connectionFactory .setTargetConnectionFactories (factories );
385
391
386
392
final RabbitTemplate template = new RabbitTemplate (connectionFactory );
387
- Expression expression = new SpelExpressionParser ()
393
+ Expression sendExpression = new SpelExpressionParser ()
388
394
.parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
389
395
".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'foo' : 'bar'" );
390
- template .setSendConnectionFactorySelectorExpression (expression );
391
- template .setReceiveConnectionFactorySelectorExpression (expression );
396
+ template .setSendConnectionFactorySelectorExpression (sendExpression );
397
+ Expression receiveExpression = new SpelExpressionParser ()
398
+ .parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
399
+ ".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'baz' : 'qux'" );
400
+ template .setReceiveConnectionFactorySelectorExpression (receiveExpression );
392
401
393
402
for (int i = 0 ; i < 3 ; i ++) {
394
403
try {
@@ -411,8 +420,10 @@ public void testRoutingConnectionFactory() throws Exception {
411
420
}
412
421
}
413
422
414
- Mockito .verify (connectionFactory1 , Mockito .times (5 )).createConnection ();
415
- Mockito .verify (connectionFactory2 , Mockito .times (4 )).createConnection ();
423
+ Mockito .verify (connectionFactory1 , times (2 )).createConnection ();
424
+ Mockito .verify (connectionFactory2 , times (1 )).createConnection ();
425
+ Mockito .verify (connectionFactory3 , times (3 )).createConnection ();
426
+ Mockito .verify (connectionFactory4 , times (3 )).createConnection ();
416
427
}
417
428
418
429
@ Test
0 commit comments