Fix destination checking in Artemis auto-configuration tests
Closes gh-18319
This commit is contained in:
parent
7533bfd0d3
commit
9df356ec4c
|
@ -21,14 +21,15 @@ import java.io.IOException;
|
|||
import java.util.UUID;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
|
||||
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
|
||||
import org.apache.activemq.artemis.core.server.BindingQueryResult;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.artemis.jms.server.config.JMSConfiguration;
|
||||
import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
|
||||
|
@ -50,9 +51,6 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.connection.CachingConnectionFactory;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.SessionCallback;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.jms.support.destination.DynamicDestinationResolver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -208,9 +206,9 @@ public class ArtemisAutoConfigurationTests {
|
|||
DestinationChecker checker = new DestinationChecker(context);
|
||||
checker.checkQueue("Queue1", true);
|
||||
checker.checkQueue("Queue2", true);
|
||||
checker.checkQueue("QueueWillNotBeAutoCreated", true);
|
||||
checker.checkQueue("NonExistentQueue", false);
|
||||
checker.checkTopic("Topic1", true);
|
||||
checker.checkTopic("TopicWillBeAutoCreated", true);
|
||||
checker.checkTopic("NonExistentTopic", false);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -230,8 +228,8 @@ public class ArtemisAutoConfigurationTests {
|
|||
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2").run((context) -> {
|
||||
DestinationChecker checker = new DestinationChecker(context);
|
||||
checker.checkQueue("custom", true); // See CustomJmsConfiguration
|
||||
checker.checkQueue("Queue1", true);
|
||||
checker.checkQueue("Queue2", true);
|
||||
checker.checkQueue("Queue1", false);
|
||||
checker.checkQueue("Queue2", false);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -275,10 +273,10 @@ public class ArtemisAutoConfigurationTests {
|
|||
.isLessThan(secondProperties.getEmbedded().getServerId());
|
||||
DestinationChecker firstChecker = new DestinationChecker(first);
|
||||
firstChecker.checkQueue("Queue1", true);
|
||||
firstChecker.checkQueue("Queue2", true);
|
||||
firstChecker.checkQueue("Queue2", false);
|
||||
DestinationChecker secondChecker = new DestinationChecker(second);
|
||||
secondChecker.checkQueue("Queue1", false);
|
||||
secondChecker.checkQueue("Queue2", true);
|
||||
secondChecker.checkQueue("Queue1", true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -295,10 +293,9 @@ public class ArtemisAutoConfigurationTests {
|
|||
// Do not start a specific one
|
||||
"spring.artemis.embedded.enabled=false")
|
||||
.run((secondContext) -> {
|
||||
DestinationChecker firstChecker = new DestinationChecker(first);
|
||||
firstChecker.checkQueue("Queue1", true);
|
||||
DestinationChecker secondChecker = new DestinationChecker(secondContext);
|
||||
secondChecker.checkQueue("Queue1", true);
|
||||
first.getBean(JmsTemplate.class).convertAndSend("Queue1", "test");
|
||||
assertThat(secondContext.getBean(JmsTemplate.class).receiveAndConvert("Queue1"))
|
||||
.isEqualTo("test");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -394,40 +391,31 @@ public class ArtemisAutoConfigurationTests {
|
|||
|
||||
private static final class DestinationChecker {
|
||||
|
||||
private final JmsTemplate jmsTemplate;
|
||||
|
||||
private final DestinationResolver destinationResolver;
|
||||
private final EmbeddedJMS embeddedJms;
|
||||
|
||||
private DestinationChecker(ApplicationContext applicationContext) {
|
||||
this.jmsTemplate = applicationContext.getBean(JmsTemplate.class);
|
||||
this.destinationResolver = new DynamicDestinationResolver();
|
||||
this.embeddedJms = applicationContext.getBean(EmbeddedJMS.class);
|
||||
}
|
||||
|
||||
public void checkQueue(String name, boolean shouldExist) {
|
||||
checkDestination(name, false, shouldExist);
|
||||
checkDestination(name, RoutingType.ANYCAST, shouldExist);
|
||||
}
|
||||
|
||||
public void checkTopic(String name, boolean shouldExist) {
|
||||
checkDestination(name, true, shouldExist);
|
||||
checkDestination(name, RoutingType.MULTICAST, shouldExist);
|
||||
}
|
||||
|
||||
public void checkDestination(String name, final boolean pubSub, final boolean shouldExist) {
|
||||
this.jmsTemplate.execute((SessionCallback<Void>) (session) -> {
|
||||
try {
|
||||
Destination destination = this.destinationResolver.resolveDestinationName(session, name, pubSub);
|
||||
if (!shouldExist) {
|
||||
throw new IllegalStateException(
|
||||
"Destination '" + name + "' was not expected but got " + destination);
|
||||
}
|
||||
public void checkDestination(String name, RoutingType routingType, boolean shouldExist) {
|
||||
try {
|
||||
BindingQueryResult result = this.embeddedJms.getActiveMQServer().bindingQuery(new SimpleString(name));
|
||||
assertThat(result.isExists()).isEqualTo(shouldExist);
|
||||
if (shouldExist) {
|
||||
assertThat(result.getAddressInfo().getRoutingType()).isEqualTo(routingType);
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
if (shouldExist) {
|
||||
throw new IllegalStateException(
|
||||
"Destination '" + name + "' was expected but got " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue