|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2017 the original author or authors. |
| 2 | + * Copyright 2016-2020 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.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.amqp.rabbit.log4j2;
|
18 | 18 |
|
| 19 | +import static org.hamcrest.CoreMatchers.equalTo; |
19 | 20 | import static org.hamcrest.Matchers.instanceOf;
|
20 | 21 | import static org.hamcrest.Matchers.is;
|
21 | 22 | import static org.hamcrest.Matchers.startsWith;
|
|
37 | 38 | import java.net.URI;
|
38 | 39 | import java.util.Map;
|
39 | 40 | import java.util.concurrent.ArrayBlockingQueue;
|
| 41 | +import java.util.concurrent.BlockingQueue; |
40 | 42 | import java.util.concurrent.LinkedBlockingQueue;
|
41 | 43 |
|
42 | 44 | import org.apache.logging.log4j.LogManager;
|
|
54 | 56 | import org.springframework.amqp.core.Queue;
|
55 | 57 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
56 | 58 | import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
|
| 59 | +import org.springframework.amqp.rabbit.connection.RabbitUtils; |
57 | 60 | import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
58 | 61 | import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
59 | 62 | import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
@@ -178,55 +181,58 @@ public void testProperties() {
|
178 | 181 | assertEquals(ArrayBlockingQueue.class, events.getClass());
|
179 | 182 | }
|
180 | 183 |
|
181 |
| - @Test |
182 |
| - public void testAmqpAppenderEventQueueTypeDefaultsToLinkedBlockingQueue() throws Exception { |
183 |
| - Logger logger = LogManager.getLogger("default_queue_logger"); |
184 |
| - AmqpAppender appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders", |
185 |
| - Map.class).get("rabbitmq_default_queue"); |
186 |
| - |
187 |
| - Object events = TestUtils.getPropertyValue(appender, "events"); |
188 |
| - |
189 |
| - Object manager = TestUtils.getPropertyValue(appender, "manager"); |
190 |
| - assertTrue(TestUtils.getPropertyValue(manager, "addMdcAsHeaders", Boolean.class)); |
191 |
| - |
192 |
| - assertThat(events, instanceOf(LinkedBlockingQueue.class)); |
193 |
| - } |
194 |
| - |
195 | 184 | @Test
|
196 | 185 | public void testSaslConfig() {
|
197 | 186 | Logger logger = LogManager.getLogger("sasl");
|
198 | 187 | AmqpAppender appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders",
|
199 | 188 | Map.class).get("sasl1");
|
200 |
| - SaslConfig saslConfig = |
201 |
| - TestUtils.getPropertyValue(appender, "manager.connectionFactory.rabbitConnectionFactory", |
202 |
| - ConnectionFactory.class) |
203 |
| - .getSaslConfig(); |
| 189 | + SaslConfig saslConfig = RabbitUtils.stringToSaslConfig( |
| 190 | + TestUtils.getPropertyValue(appender, "manager.saslConfig", String.class), |
| 191 | + mock(ConnectionFactory.class)); |
204 | 192 | assertThat(saslConfig, instanceOf(DefaultSaslConfig.class));
|
205 | 193 | assertEquals("PLAIN", TestUtils.getPropertyValue(saslConfig, "mechanism"));
|
206 | 194 | appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders",
|
207 | 195 | Map.class).get("sasl2");
|
208 |
| - saslConfig = |
209 |
| - TestUtils.getPropertyValue(appender, "manager.connectionFactory.rabbitConnectionFactory", |
210 |
| - ConnectionFactory.class) |
211 |
| - .getSaslConfig(); |
| 196 | + saslConfig = RabbitUtils.stringToSaslConfig( |
| 197 | + TestUtils.getPropertyValue(appender, "manager.saslConfig", String.class), |
| 198 | + mock(ConnectionFactory.class)); |
212 | 199 | assertThat(saslConfig, instanceOf(DefaultSaslConfig.class));
|
213 | 200 | assertEquals("EXTERNAL", TestUtils.getPropertyValue(saslConfig, "mechanism"));
|
214 | 201 | appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders",
|
215 | 202 | Map.class).get("sasl3");
|
216 |
| - saslConfig = |
217 |
| - TestUtils.getPropertyValue(appender, "manager.connectionFactory.rabbitConnectionFactory", |
218 |
| - ConnectionFactory.class) |
219 |
| - .getSaslConfig(); |
| 203 | + saslConfig = RabbitUtils.stringToSaslConfig( |
| 204 | + TestUtils.getPropertyValue(appender, "manager.saslConfig", String.class), |
| 205 | + mock(ConnectionFactory.class)); |
220 | 206 | assertThat(saslConfig, instanceOf(JDKSaslConfig.class));
|
221 | 207 | appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders",
|
222 | 208 | Map.class).get("sasl4");
|
223 |
| - saslConfig = |
224 |
| - TestUtils.getPropertyValue(appender, "manager.connectionFactory.rabbitConnectionFactory", |
225 |
| - ConnectionFactory.class) |
226 |
| - .getSaslConfig(); |
| 209 | + saslConfig = RabbitUtils.stringToSaslConfig( |
| 210 | + TestUtils.getPropertyValue(appender, "manager.saslConfig", String.class), |
| 211 | + mock(ConnectionFactory.class)); |
227 | 212 | assertThat(saslConfig, instanceOf(CRDemoMechanism.CRDemoSaslConfig.class));
|
228 | 213 | }
|
229 | 214 |
|
| 215 | + @Test |
| 216 | + public void testAmqpAppenderEventQueueTypeDefaultsToLinkedBlockingQueue() throws InterruptedException { |
| 217 | + Logger logger = LogManager.getLogger("default_queue_logger"); |
| 218 | + logger.info("test"); |
| 219 | + AmqpAppender appender = (AmqpAppender) TestUtils.getPropertyValue(logger, "context.configuration.appenders", |
| 220 | + Map.class).get("rabbitmq_default_queue"); |
| 221 | + |
| 222 | + Object events = TestUtils.getPropertyValue(appender, "events"); |
| 223 | + |
| 224 | + Object manager = TestUtils.getPropertyValue(appender, "manager"); |
| 225 | + assertTrue(TestUtils.getPropertyValue(manager, "addMdcAsHeaders", Boolean.class)); |
| 226 | + |
| 227 | + assertThat(events.getClass(), equalTo(LinkedBlockingQueue.class)); |
| 228 | + BlockingQueue<?> queue = (BlockingQueue<?>) events; |
| 229 | + int n = 0; |
| 230 | + while (n++ < 100 && queue.size() > 0) { |
| 231 | + Thread.sleep(100); |
| 232 | + } |
| 233 | + assertThat(queue.size(), equalTo(0)); |
| 234 | + } |
| 235 | + |
230 | 236 | @Test
|
231 | 237 | public void testUriProperties() {
|
232 | 238 | Logger logger = LogManager.getLogger("bar");
|
|
0 commit comments