use of org.springframework.core.log.LogAccessor in project spring-integration by spring-projects.
the class AmqpOutboundChannelAdapterParserTests method testInt3430FailForNotLazyConnect.
@Test
public void testInt3430FailForNotLazyConnect() {
RabbitTemplate amqpTemplate = spy(new RabbitTemplate());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
RuntimeException toBeThrown = new RuntimeException("Test Connection Exception");
doThrow(toBeThrown).when(connectionFactory).createConnection();
when(amqpTemplate.getConnectionFactory()).thenReturn(connectionFactory);
AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(amqpTemplate);
LogAccessor logger = spy(TestUtils.getPropertyValue(handler, "logger", LogAccessor.class));
new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
doNothing().when(logger).error(toBeThrown, "Failed to eagerly establish the connection.");
ApplicationContext context = mock(ApplicationContext.class);
handler.setApplicationContext(context);
handler.setBeanFactory(context);
handler.afterPropertiesSet();
handler.start();
handler.stop();
verify(logger, never()).error(any(RuntimeException.class), anyString());
handler.setLazyConnect(false);
handler.start();
verify(logger).error(toBeThrown, "Failed to eagerly establish the connection.");
handler.stop();
}
use of org.springframework.core.log.LogAccessor in project spring-integration by spring-projects.
the class DirectChannelTests method testSend.
@Test
void testSend() {
DirectChannel channel = new DirectChannel();
LogAccessor logger = spy(TestUtils.getPropertyValue(channel, "logger", LogAccessor.class));
when(logger.isDebugEnabled()).thenReturn(true);
new DirectFieldAccessor(channel).setPropertyValue("logger", logger);
ThreadNameExtractingTestTarget target = new ThreadNameExtractingTestTarget();
channel.subscribe(target);
GenericMessage<String> message = new GenericMessage<>("test");
assertThat(channel.send(message)).isTrue();
assertThat(target.threadName).isEqualTo(Thread.currentThread().getName());
DirectFieldAccessor channelAccessor = new DirectFieldAccessor(channel);
UnicastingDispatcher dispatcher = (UnicastingDispatcher) channelAccessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
Object loadBalancingStrategy = dispatcherAccessor.getPropertyValue("loadBalancingStrategy");
assertThat(loadBalancingStrategy instanceof RoundRobinLoadBalancingStrategy).isTrue();
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(2)).debug(captor.capture());
List<String> logs = captor.getAllValues();
assertThat(logs.size()).isEqualTo(2);
assertThat(logs.get(0)).startsWith("preSend");
assertThat(logs.get(1)).startsWith("postSend");
}
use of org.springframework.core.log.LogAccessor in project spring-integration by spring-projects.
the class P2pChannelTests method testPubSubChannelLoggingWithMoreThenOneSubscriber.
@Test
public void testPubSubChannelLoggingWithMoreThenOneSubscriber() {
final PublishSubscribeChannel channel = new PublishSubscribeChannel();
channel.setBeanName("pubSubChannel");
final LogAccessor logger = mock(LogAccessor.class);
when(logger.isInfoEnabled()).thenReturn(true);
ReflectionUtils.doWithFields(AbstractMessageChannel.class, field -> {
if ("logger".equals(field.getName())) {
field.setAccessible(true);
field.set(channel, logger);
}
});
channel.subscribe(mock(MessageHandler.class));
channel.subscribe(mock(MessageHandler.class));
verify(logger, times(2)).info(Mockito.anyString());
}
use of org.springframework.core.log.LogAccessor in project spring-integration by spring-projects.
the class P2pChannelTests method testExecutorChannelLoggingWithMoreThenOneSubscriber.
@Test
public void testExecutorChannelLoggingWithMoreThenOneSubscriber() {
final ExecutorChannel channel = new ExecutorChannel(mock(Executor.class));
channel.setBeanName("executorChannel");
final LogAccessor logger = mock(LogAccessor.class);
when(logger.isInfoEnabled()).thenReturn(true);
ReflectionUtils.doWithFields(AbstractMessageChannel.class, field -> {
if ("logger".equals(field.getName())) {
field.setAccessible(true);
field.set(channel, logger);
}
});
channel.subscribe(mock(MessageHandler.class));
channel.subscribe(mock(MessageHandler.class));
verify(logger, times(2)).info(Mockito.anyString());
}
use of org.springframework.core.log.LogAccessor in project spring-integration by spring-projects.
the class GatewayParserTests method testCustomCompletableNoAsyncAttemptAsync.
@Test
public void testCustomCompletableNoAsyncAttemptAsync() throws Exception {
Object gateway = context.getBean("&customCompletableAttemptAsync");
LogAccessor logger = spy(TestUtils.getPropertyValue(gateway, "logger", LogAccessor.class));
when(logger.isDebugEnabled()).thenReturn(true);
new DirectFieldAccessor(gateway).setPropertyValue("logger", logger);
QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
final AtomicReference<Thread> thread = new AtomicReference<>();
requestChannel.addInterceptor(new ChannelInterceptor() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
thread.set(Thread.currentThread());
return message;
}
});
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
this.startResponder(requestChannel, replyChannel);
TestService service = context.getBean("customCompletableAttemptAsync", TestService.class);
MyCompletableFuture result = service.customCompletable("flowCustomCompletable");
String reply = result.get(10, TimeUnit.SECONDS);
assertThat(reply).isEqualTo("SYNC_CUSTOM_COMPLETABLE");
assertThat(thread.get()).isEqualTo(Thread.currentThread());
assertThat(TestUtils.getPropertyValue(gateway, "asyncExecutor")).isNotNull();
verify(logger).debug(ArgumentMatchers.<Supplier<String>>argThat(logMessage -> logMessage.get().equals("AsyncTaskExecutor submit*() return types are incompatible " + "with the method return type; " + "running on calling thread; the downstream flow must return the required Future: " + "MyCompletableFuture")));
}
Aggregations