Skip to content

Commit 0b7d8f0

Browse files
committed
Add test condition to test x-match=all-with-x
Broker version >= 3.10. References #725
1 parent 4efd47f commit 0b7d8f0

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

src/test/java/com/rabbitmq/client/test/TestUtils.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import com.rabbitmq.client.impl.NetworkConnection;
2020
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
2121
import com.rabbitmq.tools.Host;
22+
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
25+
import java.lang.annotation.Target;
26+
import java.lang.reflect.Method;
2227
import java.util.List;
2328
import org.assertj.core.api.Assertions;
2429
import org.junit.AssumptionViolatedException;
@@ -130,6 +135,10 @@ public static boolean isVersion38orLater(Connection connection) {
130135
return atLeastVersion("3.8.0", connection);
131136
}
132137

138+
public static boolean isVersion310orLater(Connection connection) {
139+
return atLeastVersion("3.10.0", connection);
140+
}
141+
133142
private static boolean atLeastVersion(String expectedVersion, Connection connection) {
134143
String currentVersion = null;
135144
try {
@@ -408,4 +417,52 @@ protected DefaultTestSuite(Class<?> klass, List<Runner> runners)
408417
super(klass, runners);
409418
}
410419
}
420+
421+
@Target({ElementType.METHOD})
422+
@Retention(RetentionPolicy.RUNTIME)
423+
public @interface TestExecutionCondition {
424+
425+
Class<? extends ExecutionCondition>[] value();
426+
427+
}
428+
429+
interface ExecutionCondition {
430+
431+
void check(Description description) throws Exception;
432+
433+
}
434+
435+
public static class BrokerAtLeast310Condition implements ExecutionCondition {
436+
437+
private static final String VERSION = "3.10.0";
438+
439+
@Override
440+
public void check(Description description) throws Exception {
441+
try (Connection c = TestUtils.connectionFactory().newConnection()) {
442+
if (!TestUtils.atLeastVersion(VERSION, c)) {
443+
throw new AssumptionViolatedException("Broker version < " + VERSION + ", skipping.");
444+
}
445+
}
446+
}
447+
}
448+
449+
public static class ExecutionConditionRule implements TestRule {
450+
451+
@Override
452+
public Statement apply(Statement base, Description description) {
453+
return new Statement() {
454+
@Override
455+
public void evaluate() throws Throwable {
456+
Method testMethod = description.getTestClass().getDeclaredMethod(description.getMethodName());
457+
TestExecutionCondition conditionAnnotation = testMethod.getAnnotation(
458+
TestExecutionCondition.class);
459+
if (conditionAnnotation != null) {
460+
conditionAnnotation.value()[0].getConstructor().newInstance()
461+
.check(description);
462+
}
463+
base.evaluate();
464+
}
465+
};
466+
}
467+
}
411468
}

src/test/java/com/rabbitmq/client/test/functional/HeadersExchangeValidation.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Java client library, is triple-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -17,6 +17,7 @@
1717

1818
import static org.junit.Assert.fail;
1919

20+
import com.rabbitmq.client.test.TestUtils;
2021
import java.io.IOException;
2122
import java.util.HashMap;
2223

@@ -48,11 +49,13 @@ public class HeadersExchangeValidation extends BrokerTestCase {
4849
arguments.put("x-match", "any");
4950
succeedBind(queue, arguments);
5051

51-
arguments.put("x-match", "all-with-x");
52-
succeedBind(queue, arguments);
52+
if (TestUtils.isVersion310orLater(connection)) {
53+
arguments.put("x-match", "all-with-x");
54+
succeedBind(queue, arguments);
5355

54-
arguments.put("x-match", "any-with-x");
55-
succeedBind(queue, arguments);
56+
arguments.put("x-match", "any-with-x");
57+
succeedBind(queue, arguments);
58+
}
5659
}
5760

5861
private void failBind(String queue, HashMap<String, Object> arguments) {

src/test/java/com/rabbitmq/client/test/functional/Routing.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Java client library, is triple-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -21,13 +21,17 @@
2121
import static org.junit.Assert.assertNull;
2222
import static org.junit.Assert.fail;
2323

24+
import com.rabbitmq.client.test.TestUtils.BrokerAtLeast310Condition;
25+
import com.rabbitmq.client.test.TestUtils.ExecutionConditionRule;
26+
import com.rabbitmq.client.test.TestUtils.TestExecutionCondition;
2427
import java.io.IOException;
2528
import java.util.ArrayList;
2629
import java.util.HashMap;
2730
import java.util.List;
2831
import java.util.Map;
2932
import java.util.concurrent.TimeoutException;
3033

34+
import org.junit.Rule;
3135
import org.junit.Test;
3236

3337
import com.rabbitmq.client.AMQP;
@@ -36,10 +40,13 @@
3640
import com.rabbitmq.client.ReturnListener;
3741
import com.rabbitmq.client.test.BrokerTestCase;
3842
import com.rabbitmq.utility.BlockingCell;
43+
import org.junit.rules.TestRule;
3944

4045
public class Routing extends BrokerTestCase
4146
{
4247

48+
@Rule public TestRule executionConditionRule = new ExecutionConditionRule();
49+
4350
protected final String E = "MRDQ";
4451
protected final String Q1 = "foo";
4552
protected final String Q2 = "bar";
@@ -245,7 +252,9 @@ private void checkGet(String queue, boolean messageExpected)
245252
checkGet(Q2, false);
246253
}
247254

248-
@Test public void headersWithXRouting() throws Exception {
255+
@Test
256+
@TestExecutionCondition(BrokerAtLeast310Condition.class)
257+
public void headersWithXRouting() throws Exception {
249258
Map<String, Object> spec = new HashMap<String, Object>();
250259
spec.put("x-key-1", "value-1");
251260
spec.put("x-key-2", "value-2");

0 commit comments

Comments
 (0)