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