List of usage examples for org.apache.commons.logging Log isDebugEnabled
boolean isDebugEnabled();
From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java
@Test public void testReuse() throws Exception { AbstractClientConnectionFactory factory = mock(AbstractClientConnectionFactory.class); when(factory.isRunning()).thenReturn(true); TcpConnectionSupport mockConn1 = makeMockConnection("conn1"); TcpConnectionSupport mockConn2 = makeMockConnection("conn2"); when(factory.getConnection()).thenReturn(mockConn1).thenReturn(mockConn2); CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 2); cachingFactory.start();/* w w w.ja va 2 s. co m*/ TcpConnection conn1 = cachingFactory.getConnection(); // INT-3652 TcpConnectionInterceptorSupport cachedConn1 = (TcpConnectionInterceptorSupport) conn1; Log logger = spy(TestUtils.getPropertyValue(cachedConn1, "logger", Log.class)); when(logger.isDebugEnabled()).thenReturn(true); new DirectFieldAccessor(cachedConn1).setPropertyValue("logger", logger); cachedConn1.onMessage(new ErrorMessage(new RuntimeException())); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(logger).debug(captor.capture()); assertThat(captor.getValue(), startsWith("Message discarded; no listener:")); // end INT-3652 assertEquals("Cached:" + mockConn1.toString(), conn1.toString()); conn1.close(); conn1 = cachingFactory.getConnection(); assertEquals("Cached:" + mockConn1.toString(), conn1.toString()); TcpConnection conn2 = cachingFactory.getConnection(); assertEquals("Cached:" + mockConn2.toString(), conn2.toString()); conn1.close(); conn2.close(); }
From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java
@SuppressWarnings("unchecked") @Test //INT-3722//ww w . j a v a2 s .co m public void testGatewayRelease() throws Exception { TcpNetServerConnectionFactory in = new TcpNetServerConnectionFactory(0); in.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); final TcpSendingMessageHandler handler = new TcpSendingMessageHandler(); handler.setConnectionFactory(in); final AtomicInteger count = new AtomicInteger(2); in.registerListener(message -> { if (!(message instanceof ErrorMessage)) { if (count.decrementAndGet() < 1) { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } handler.handleMessage(message); } return false; }); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.start(); TestingUtilities.waitListening(in, null); int port = in.getPort(); TcpNetClientConnectionFactory out = new TcpNetClientConnectionFactory("localhost", port); out.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); CachingClientConnectionFactory cache = new CachingClientConnectionFactory(out, 2); final TcpOutboundGateway gate = new TcpOutboundGateway(); gate.setConnectionFactory(cache); QueueChannel outputChannel = new QueueChannel(); gate.setOutputChannel(outputChannel); gate.setBeanFactory(mock(BeanFactory.class)); gate.afterPropertiesSet(); Log logger = spy(TestUtils.getPropertyValue(gate, "logger", Log.class)); new DirectFieldAccessor(gate).setPropertyValue("logger", logger); when(logger.isDebugEnabled()).thenReturn(true); doAnswer(new Answer<Void>() { private final CountDownLatch latch = new CountDownLatch(2); @Override public Void answer(InvocationOnMock invocation) throws Throwable { invocation.callRealMethod(); String log = invocation.getArgument(0); if (log.startsWith("Response")) { Executors.newSingleThreadScheduledExecutor() .execute(() -> gate.handleMessage(new GenericMessage<>("bar"))); // hold up the first thread until the second has added its pending reply latch.await(10, TimeUnit.SECONDS); } else if (log.startsWith("Added")) { latch.countDown(); } return null; } }).when(logger).debug(anyString()); gate.start(); gate.handleMessage(new GenericMessage<String>("foo")); Message<byte[]> result = (Message<byte[]>) outputChannel.receive(10000); assertNotNull(result); assertEquals("foo", new String(result.getPayload())); result = (Message<byte[]>) outputChannel.receive(10000); assertNotNull(result); assertEquals("bar", new String(result.getPayload())); handler.stop(); gate.stop(); verify(logger, never()).error(anyString()); }
From source file:org.springframework.integration.ip.tcp.connection.ConnectionFactoryTests.java
private void testEarlyClose(final AbstractServerConnectionFactory factory, String property, String message) throws Exception { factory.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); factory.setBeanName("foo"); factory.registerListener(mock(TcpListener.class)); factory.afterPropertiesSet();// w w w . j a v a 2s .c o m Log logger = spy(TestUtils.getPropertyValue(factory, "logger", Log.class)); new DirectFieldAccessor(factory).setPropertyValue("logger", logger); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final CountDownLatch latch3 = new CountDownLatch(1); when(logger.isInfoEnabled()).thenReturn(true); when(logger.isDebugEnabled()).thenReturn(true); doAnswer(invocation -> { latch1.countDown(); // wait until the stop nulls the channel latch2.await(10, TimeUnit.SECONDS); return null; }).when(logger).info(contains("Listening")); doAnswer(invocation -> { latch3.countDown(); return null; }).when(logger).debug(contains(message)); factory.start(); assertTrue("missing info log", latch1.await(10, TimeUnit.SECONDS)); // stop on a different thread because it waits for the executor Executors.newSingleThreadExecutor().execute(() -> factory.stop()); int n = 0; DirectFieldAccessor accessor = new DirectFieldAccessor(factory); while (n++ < 200 && accessor.getPropertyValue(property) != null) { Thread.sleep(100); } assertTrue("Stop was not invoked in time", n < 200); latch2.countDown(); assertTrue("missing debug log", latch3.await(10, TimeUnit.SECONDS)); String expected = "foo, port=" + factory.getPort() + message; ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(logger, atLeast(1)).debug(captor.capture()); assertThat(captor.getAllValues(), hasItem(expected)); factory.stop(); }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
private void onMessageSync(javax.jms.Message message, String correlationId) { try {/*from w w w .j ava 2 s. c om*/ LinkedBlockingQueue<javax.jms.Message> queue = this.replies.get(correlationId); if (queue == null) { if (this.correlationKey != null) { Log debugLogger = LogFactory.getLog("si.jmsgateway.debug"); if (debugLogger.isDebugEnabled()) { Object siMessage = this.messageConverter.fromMessage(message); debugLogger.debug("No pending reply for " + siMessage + " with correlationId: " + correlationId + " pending replies: " + this.replies.keySet()); } throw new RuntimeException("No sender waiting for reply"); } synchronized (this.earlyOrLateReplies) { queue = this.replies.get(correlationId); if (queue == null) { if (logger.isDebugEnabled()) { logger.debug("Reply for correlationId " + correlationId + " received early or late"); } this.earlyOrLateReplies.put(correlationId, new TimedReply(message)); } } } if (queue != null) { if (logger.isDebugEnabled()) { logger.debug("Received reply with correlationId " + correlationId); } queue.add(message); } } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Failed to consume reply with correlationId " + correlationId, e); } } }
From source file:org.springframework.integration.mqtt.MqttAdapterTests.java
@Test public void testReconnect() throws Exception { final IMqttClient client = mock(IMqttClient.class); MqttPahoMessageDrivenChannelAdapter adapter = buildAdapter(client, null, ConsumerStopAction.UNSUBSCRIBE_NEVER); adapter.setRecoveryInterval(10);// w ww .j a va 2s .c o m Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class)); new DirectFieldAccessor(adapter).setPropertyValue("logger", logger); given(logger.isDebugEnabled()).willReturn(true); final AtomicInteger attemptingReconnectCount = new AtomicInteger(); willAnswer(i -> { if (attemptingReconnectCount.getAndIncrement() == 0) { adapter.connectionLost(new RuntimeException("while schedule running")); } i.callRealMethod(); return null; }).given(logger).debug("Attempting reconnect"); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.initialize(); adapter.setTaskScheduler(taskScheduler); adapter.start(); adapter.connectionLost(new RuntimeException("initial")); Thread.sleep(1000); // the following assertion should be equalTo, but leq to protect against a slow CI server assertThat(attemptingReconnectCount.get(), lessThanOrEqualTo(2)); adapter.stop(); taskScheduler.destroy(); }
From source file:org.springframework.integration.smb.session.SmbSession.java
/** * Static configuration of the JCIFS library. * The log level of this class is mapped to a suitable <code>jcifs.util.loglevel</code> */// w w w . j av a 2 s . c o m static void configureJcifs() { // TODO jcifs.Config.setProperty("jcifs.smb.client.useExtendedSecurity", "false"); // TODO jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", "false"); // set JCIFS SMB client library' log level unless already configured by system property final String sysPropLogLevel = "jcifs.util.loglevel"; if (jcifs.Config.getProperty(sysPropLogLevel) == null) { // set log level according to this class' logger's log level. Log log = LogFactory.getLog(SmbSession.class); if (log.isTraceEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "N"); } else if (log.isDebugEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "3"); } else { jcifs.Config.setProperty(sysPropLogLevel, "1"); } } }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testDebugNoEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.DEBUG); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); logger.log(() -> "foo"); verify(theLogger).isDebugEnabled();//www . j a v a2s. c om verify(theLogger).debug(any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testTraceNoEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.TRACE); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); given(theLogger.isTraceEnabled()).willReturn(true); logger.log(() -> "foo"); verify(theLogger).isTraceEnabled();//from w w w . jav a 2 s. c om verify(theLogger).trace(any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testDebugWithEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.DEBUG); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); logger.log(() -> "foo", rte); verify(theLogger).isDebugEnabled();//from ww w . java2s .com verify(theLogger).debug(any(), any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testTraceWithEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.TRACE); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); given(theLogger.isTraceEnabled()).willReturn(true); logger.log(() -> "foo", rte); verify(theLogger).isTraceEnabled();//ww w .ja v a 2s . co m verify(theLogger).trace(any(), any()); verifyNoMoreInteractions(theLogger); }