Improve logging in spring-messaging

Before this change the amount of logging was too little or too much
with TRACE turned on. This change separates useful debugging
information and logs it under DEBUG and leaves more detailed
information to be logged under TRACE.
This commit is contained in:
Rossen Stoyanchev
2013-11-12 16:34:25 -05:00
parent 72dec7d0fe
commit df5d22e120
21 changed files with 187 additions and 117 deletions

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging;
import java.util.ArrayList;
import java.util.List;
/**
* A stub MessageChannel that saves all sent messages.
*
* @author Rossen Stoyanchev
*/
public class StubMessageChannel implements MessageChannel {
private final List<Message<byte[]>> messages = new ArrayList<>();
public List<Message<byte[]>> getMessages() {
return this.messages;
}
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message) {
this.messages.add((Message<byte[]>) message);
return true;
}
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message, long timeout) {
this.messages.add((Message<byte[]>) message);
return true;
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.messaging.simp.handler;
import org.apache.activemq.transport.stomp.Stomp;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -25,6 +26,8 @@ import org.springframework.messaging.core.MessageSendingOperations;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.TestPrincipal;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.MessageBuilder;
import static org.junit.Assert.assertEquals;

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.StubMessageChannel;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
@@ -47,16 +47,13 @@ public class StompBrokerRelayMessageHandlerTests {
private StubTcpOperations tcpClient;
private StubMessageChannel responseChannel;
@Before
public void setup() {
this.responseChannel = new StubMessageChannel();
this.tcpClient = new StubTcpOperations();
this.brokerRelay = new StompBrokerRelayMessageHandler(this.responseChannel, Arrays.asList("/topic"));
this.brokerRelay = new StompBrokerRelayMessageHandler(new StubMessageChannel(), Arrays.asList("/topic"));
this.brokerRelay.setTcpClient(tcpClient);
}
@@ -161,25 +158,4 @@ public class StompBrokerRelayMessageHandlerTests {
}
}
private static class StubMessageChannel implements MessageChannel {
private final List<Message<byte[]>> messages = new ArrayList<>();
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message) {
this.messages.add((Message<byte[]>) message);
return true;
}
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message, long timeout) {
this.messages.add((Message<byte[]>) message);
return true;
}
}
}