Skip to content

Commit

Permalink
Allow PerfTestMulti to use quorum queues
Browse files Browse the repository at this point in the history
Fixes #448
  • Loading branch information
acogoluegnes committed Dec 15, 2022
1 parent 0627606 commit 803bf09
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
31 changes: 30 additions & 1 deletion html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,38 @@ The following parameters can be specified for a scenario:
- consumer-msg-count: number of messages to be consumed by the consumer. Defaults to `0`.
- msg-count: single flag to set the previous two counts to the same value.
- flags: flags to pass to the producer, like `"mandatory"`,
or `"persistent"`. Defaults to an empty list.
or `"persistent"`, separated by commas. Defaults to an empty list.
- predeclared: tells the benchmark tool if the exchange/queue name
provided already exists in the broker. Defaults to `false`.
- queue-arguments: key/value pairs separated by commas, e.g. `x-max-length=10,x-dead-letter-exchange=some.exchange.name`.

### Using Quorum Queues

PerfTestMulti requires several parameters to declare [quorum queues](https://rabbitmq.com/quorum-queues.html).
The queue type argument must be set to `quorum`, the `persistent` flag must be used,
`auto-delete` must be set to `false`, and the queue name(s) must be specified because quorum queues cannot have server-generated names.

Here is an example of a specification file that tells PerfTestMulti to use a quorum queue:

```json
[
{
"name": "consume",
"type": "simple",
"params": [
{
"time-limit": 30,
"producer-count": 1,
"consumer-count": 1,
"queue-arguments": "x-queue-type=quorum",
"flags": "persistent",
"auto-delete": "false",
"queue-names": "my-queue"
}
]
}
]
```

## Starting a web server to display the results ##

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/rabbitmq/perf/MulticastParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class MulticastParams {
private boolean randomRoutingKey = false;
private boolean skipBindingQueues = false;

private List<?> flags = new ArrayList<>();
private List<String> flags = new ArrayList<>();

private int multiAckEvery = 0;
private boolean autoAck = false;
Expand Down Expand Up @@ -253,14 +253,22 @@ public void setMsgCount(int msgCount) {
setConsumerMsgCount(msgCount);
}

public void setFlags(List<?> flags) {
public void setFlags(List<String> flags) {
this.flags = flags;
}

List<String> getFlags() {
return flags;
}

public void setAutoDelete(boolean autoDelete) {
this.autoDelete = autoDelete;
}

boolean isAutoDelete() {
return autoDelete;
}

public void setPredeclared(boolean predeclared) {
this.predeclared = predeclared;
}
Expand Down Expand Up @@ -357,6 +365,10 @@ List<String> getBodyFiles() {
return Collections.unmodifiableList(this.bodyFiles);
}

Map<String, Object> getQueueArguments() {
return queueArguments;
}

public void setBodyContentType(String bodyContentType) {
this.bodyContentType = bodyContentType;
}
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/rabbitmq/perf/PerfUtil.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
Expand All @@ -17,6 +17,9 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PerfUtil {
public static void setValue(Object obj, Object name, Object value) {
Expand Down Expand Up @@ -67,11 +70,21 @@ private static Object convert(Class<?> targetType, Object value) {
} else {
return Long.valueOf(value.toString());
}
} else if (isBoolean(targetType)) {
return Boolean.valueOf(value.toString());
} else if (isMap(targetType)) {
return PerfTest.convertKeyValuePairs(value.toString());
} else if (isList(targetType)) {
return Arrays.asList(value.toString().split(","));
}
}
return value;
}

private static boolean isBoolean(Class<?> targetType) {
return (targetType.equals(Boolean.class) || "boolean".equals(targetType.getSimpleName()));
}

private static boolean isInt(Class<?> targetType) {
return (targetType.equals(Integer.class) || "int".equals(targetType.getSimpleName()));
}
Expand All @@ -83,4 +96,12 @@ private static boolean isFloat(Class<?> targetType) {
private static boolean isLong(Class<?> targetType) {
return (targetType.equals(Long.class) || "long".equals(targetType.getSimpleName()));
}

private static boolean isMap(Class<?> targetType) {
return targetType.isAssignableFrom(Map.class);
}

private static boolean isList(Class<?> targetType) {
return targetType.isAssignableFrom(List.class);
}
}
13 changes: 11 additions & 2 deletions src/test/java/com/rabbitmq/perf/ScenarioFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2020 VMware, Inc. or its affiliates. All rights reserved.
// Copyright (c) 2019-2022 VMware, Inc. or its affiliates. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
Expand Down Expand Up @@ -32,7 +32,10 @@ public void paramsFromJSON() {
"[{'time-limit': 30, 'producer-count': 4, 'consumer-count': 2, " +
" 'rate': 10, 'exclusive': true, " +
" 'confirm': 10, " +
" 'body': ['file1.json','file2.json'], 'body-content-type' : 'application/json'}]}]";
" 'queue-arguments': 'x-max-length=10,x-dead-letter-exchange=some.exchange.name,x-single-active-consumer=true', " +
" 'flags': 'persistent,mandatory', " +
" 'auto-delete': 'false', " +
" 'body': ['file1.json','file2.json'], 'body-content-type' : 'application/json'}]}]";
List<Map> scenariosJson = new Gson().fromJson(spec, List.class);
Map scenario = scenariosJson.get(0);
MulticastParams params = ScenarioFactory.paramsFromJSON((Map) ((List) scenario.get("params")).get(0));
Expand All @@ -45,6 +48,12 @@ public void paramsFromJSON() {
assertThat(params.getBodyFiles()).hasSize(2);
assertThat(params.getBodyFiles()).contains("file1.json", "file2.json");
assertThat(params.getBodyContentType()).isEqualTo("application/json");
assertThat(params.getQueueArguments()).hasSize(3)
.containsEntry("x-max-length", 10L)
.containsEntry("x-dead-letter-exchange", "some.exchange.name")
.containsEntry("x-single-active-consumer", true);
assertThat(params.getFlags()).hasSize(2).containsExactly("persistent", "mandatory");
assertThat(params.isAutoDelete()).isFalse();
}

}

0 comments on commit 803bf09

Please sign in to comment.