|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 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.
|
|
69 | 69 | import org.springframework.amqp.core.AnonymousQueue;
|
70 | 70 | import org.springframework.amqp.core.Message;
|
71 | 71 | import org.springframework.amqp.core.MessageBuilder;
|
| 72 | +import org.springframework.amqp.core.MessageListener; |
72 | 73 | import org.springframework.amqp.core.MessagePostProcessor;
|
73 | 74 | import org.springframework.amqp.core.Queue;
|
74 | 75 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
@@ -650,6 +651,31 @@ public Message postProcessMessage(Message message) throws AmqpException {
|
650 | 651 | assertThat(afterReceivePostProcessors).containsExactly(mpp2, mpp3);
|
651 | 652 | }
|
652 | 653 |
|
| 654 | + @Test |
| 655 | + void setConcurrency() throws Exception { |
| 656 | + ConnectionFactory connectionFactory = mock(ConnectionFactory.class); |
| 657 | + Connection connection = mock(Connection.class); |
| 658 | + Channel channel = mock(Channel.class); |
| 659 | + given(connectionFactory.createConnection()).willReturn(connection); |
| 660 | + given(connection.createChannel(false)).willReturn(channel); |
| 661 | + final AtomicReference<Consumer> consumer = new AtomicReference<>(); |
| 662 | + willAnswer(invocation -> { |
| 663 | + consumer.set(invocation.getArgument(6)); |
| 664 | + consumer.get().handleConsumeOk("1"); |
| 665 | + return "1"; |
| 666 | + }).given(channel) |
| 667 | + .basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), |
| 668 | + any(Consumer.class)); |
| 669 | + final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); |
| 670 | + container.setQueueNames("foo", "bar"); |
| 671 | + container.setMessageListener(mock(MessageListener.class)); |
| 672 | + container.setConcurrency("5-10"); |
| 673 | + container.start(); |
| 674 | + await().until(() -> TestUtils.getPropertyValue(container, "consumers", Collection.class).size() == 5); |
| 675 | + container.setConcurrency("10-10"); |
| 676 | + assertThat(TestUtils.getPropertyValue(container, "consumers", Collection.class)).hasSize(10); |
| 677 | + } |
| 678 | + |
653 | 679 | private Answer<Object> messageToConsumer(final Channel mockChannel, final SimpleMessageListenerContainer container,
|
654 | 680 | final boolean cancel, final CountDownLatch latch) {
|
655 | 681 | return invocation -> {
|
|
0 commit comments