Skip to content

Commit 788efe2

Browse files
committed
Add test condition to test x-match=all-with-x
Broker version >= 3.10. References #725 (cherry picked from commit 0b7d8f0) Conflicts: src/test/java/com/rabbitmq/client/test/TestUtils.java
1 parent 5965bad commit 788efe2

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 org.assertj.core.api.Assertions;
2328
import org.junit.AssumptionViolatedException;
2429
import org.junit.rules.TestRule;
@@ -121,6 +126,10 @@ public static boolean isVersion38orLater(Connection connection) {
121126
return atLeastVersion("3.8.0", connection);
122127
}
123128

129+
public static boolean isVersion310orLater(Connection connection) {
130+
return atLeastVersion("3.10.0", connection);
131+
}
132+
124133
private static boolean atLeastVersion(String expectedVersion, Connection connection) {
125134
String currentVersion = null;
126135
try {
@@ -364,4 +373,52 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp
364373

365374
return messageReceived;
366375
}
376+
377+
@Target({ElementType.METHOD})
378+
@Retention(RetentionPolicy.RUNTIME)
379+
public @interface TestExecutionCondition {
380+
381+
Class<? extends ExecutionCondition>[] value();
382+
383+
}
384+
385+
interface ExecutionCondition {
386+
387+
void check(Description description) throws Exception;
388+
389+
}
390+
391+
public static class BrokerAtLeast310Condition implements ExecutionCondition {
392+
393+
private static final String VERSION = "3.10.0";
394+
395+
@Override
396+
public void check(Description description) throws Exception {
397+
try (Connection c = TestUtils.connectionFactory().newConnection()) {
398+
if (!TestUtils.atLeastVersion(VERSION, c)) {
399+
throw new AssumptionViolatedException("Broker version < " + VERSION + ", skipping.");
400+
}
401+
}
402+
}
403+
}
404+
405+
public static class ExecutionConditionRule implements TestRule {
406+
407+
@Override
408+
public Statement apply(Statement base, Description description) {
409+
return new Statement() {
410+
@Override
411+
public void evaluate() throws Throwable {
412+
Method testMethod = description.getTestClass().getDeclaredMethod(description.getMethodName());
413+
TestExecutionCondition conditionAnnotation = testMethod.getAnnotation(
414+
TestExecutionCondition.class);
415+
if (conditionAnnotation != null) {
416+
conditionAnnotation.value()[0].getConstructor().newInstance()
417+
.check(description);
418+
}
419+
base.evaluate();
420+
}
421+
};
422+
}
423+
}
367424
}

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)