Control queue type with annotation in JMS tests

This commit is contained in:
Arnaud Cogoluègnes 2025-02-13 10:44:09 +01:00
parent d574e66dcc
commit 7d8f83c919
No known key found for this signature in database
GPG Key ID: D5C8C4DFAD43AFA8
3 changed files with 17 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import static com.rabbitmq.amqp.tests.jms.TestUtils.protonConnection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import com.rabbitmq.amqp.tests.jms.TestUtils.Classic;
import com.rabbitmq.qpid.protonj2.client.Client;
import com.rabbitmq.qpid.protonj2.client.Delivery;
import com.rabbitmq.qpid.protonj2.client.Receiver;
@ -150,7 +151,7 @@ public class JmsTest {
// Test that Request/reply pattern using a TemporaryQueue works.
// https://jakarta.ee/specifications/messaging/3.1/jakarta-messaging-spec-3.1#requestreply-pattern-using-a-temporaryqueue-jakarta-ee
@Test
public void temporary_queue_rpc(Queue requestQueue) throws Exception {
public void temporary_queue_rpc(@Classic Queue requestQueue) throws Exception {
try (JMSContext clientContext = factory.createContext()) {
Destination responseQueue = clientContext.createTemporaryQueue();
JMSConsumer clientConsumer = clientContext.createConsumer(responseQueue);

View File

@ -20,6 +20,7 @@ import static java.util.Collections.singletonMap;
import com.rabbitmq.client.amqp.Connection;
import com.rabbitmq.client.amqp.Environment;
import com.rabbitmq.client.amqp.Management;
import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Queue;
@ -55,6 +56,12 @@ final class JmsTestInfrastructureExtension
return Queue.class.isAssignableFrom(parameter.getType());
}
private static Management.QueueType queueType(Parameter parameter) {
return parameter.isAnnotationPresent(TestUtils.Classic.class)
? Management.QueueType.CLASSIC
: Management.QueueType.QUORUM;
}
@Override
public void beforeEach(ExtensionContext context) throws Exception {
if (context.getTestMethod().isPresent()) {
@ -66,7 +73,8 @@ final class JmsTestInfrastructureExtension
try (Environment environment = new AmqpEnvironmentBuilder().build();
Connection connection =
environment.connectionBuilder().uri(TestUtils.brokerUri()).build()) {
connection.management().queue(queueName).declare();
Management.QueueType type = queueType(parameter);
connection.management().queue(queueName).type(type).declare();
}
store(context).put("queueName", queueName);
Context jndiContext = TestUtils.context(singletonMap("queue." + queueName, queueAddress));

View File

@ -21,6 +21,7 @@ import static java.lang.String.format;
import com.rabbitmq.qpid.protonj2.client.Client;
import com.rabbitmq.qpid.protonj2.client.ConnectionOptions;
import com.rabbitmq.qpid.protonj2.client.exceptions.ClientException;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
@ -126,4 +127,9 @@ final class TestUtils {
return format(
"%s_%s%s", testClass.getSimpleName(), testMethod, uuid.substring(uuid.length() / 2));
}
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Classic {}
}