Fix Stomp Test Race Condition
Test wasn't waiting until the adapter was subscribed after restart.
This commit is contained in:
committed by
Artem Bilan
parent
0fd5f5ced8
commit
1ad51b8051
@@ -23,6 +23,7 @@ import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
* The {@link StompIntegrationEvent} for the STOMP {@code RECEIPT} Frames or lost receipts.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.2
|
||||
* @see org.springframework.integration.stomp.inbound.StompInboundChannelAdapter
|
||||
* @see org.springframework.integration.stomp.outbound.StompMessageHandler
|
||||
@@ -72,4 +73,11 @@ public class StompReceiptEvent extends StompIntegrationEvent {
|
||||
public void setMessage(Message<?> message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StompReceiptEvent [destination=" + destination + ", receiptId=" + receiptId + ", stompCommand="
|
||||
+ stompCommand + ", lost=" + lost + ", message=" + message + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertThat;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
@@ -46,6 +47,7 @@ import org.springframework.integration.stomp.event.StompReceiptEvent;
|
||||
import org.springframework.integration.stomp.inbound.StompInboundChannelAdapter;
|
||||
import org.springframework.integration.stomp.outbound.StompMessageHandler;
|
||||
import org.springframework.integration.support.converter.PassThruMessageConverter;
|
||||
import org.springframework.integration.test.support.LongRunningIntegrationTest;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
@@ -58,10 +60,14 @@ import org.springframework.util.SocketUtils;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.2
|
||||
*/
|
||||
public class StompServerIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
|
||||
private static BrokerService activeMQBroker;
|
||||
|
||||
private static Reactor2TcpStompClient stompClient;
|
||||
@@ -140,6 +146,14 @@ public class StompServerIntegrationTests {
|
||||
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) receive12.getPayload());
|
||||
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) receive22.getPayload());
|
||||
|
||||
eventMessage = stompEvents2.receive(10000);
|
||||
assertNotNull(eventMessage);
|
||||
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
|
||||
stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
|
||||
assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
|
||||
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
|
||||
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) stompReceiptEvent.getMessage().getPayload());
|
||||
|
||||
Lifecycle stompInboundChannelAdapter2 = context2.getBean("stompInboundChannelAdapter", Lifecycle.class);
|
||||
stompInboundChannelAdapter2.stop();
|
||||
|
||||
@@ -153,6 +167,13 @@ public class StompServerIntegrationTests {
|
||||
|
||||
stompInboundChannelAdapter2.start();
|
||||
|
||||
eventMessage = stompEvents2.receive(10000);
|
||||
assertNotNull(eventMessage);
|
||||
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
|
||||
stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
|
||||
assertEquals(StompCommand.SUBSCRIBE, stompReceiptEvent.getStompCommand());
|
||||
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
|
||||
|
||||
stompOutputChannel1.send(new GenericMessage<byte[]>("???".getBytes()));
|
||||
|
||||
Message<?> receive24 = stompInputChannel2.receive(10000);
|
||||
|
||||
@@ -4,6 +4,6 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %c{1} [%t] : %m%n
|
||||
|
||||
log4j.category.org.springframework.messaging=DEBUG
|
||||
log4j.category.org.springframework.integration=DEBUG
|
||||
#log4j.category.org.springframework.integration.stomp=WARN
|
||||
#log4j.category.org.springframework.messaging=DEBUG
|
||||
#log4j.category.org.springframework.integration=DEBUG
|
||||
log4j.category.org.springframework.integration.stomp=WARN
|
||||
|
||||
Reference in New Issue
Block a user