Skip to content

Commit e793322

Browse files
committed
Use producer message count limit to limit run or not
Fixes #128
1 parent 60e2e38 commit e793322

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/main/java/com/rabbitmq/perf/MulticastParams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static boolean queueExists(Connection connection, final String queueName
417417
}
418418

419419
public boolean hasLimit() {
420-
return this.timeLimit > 0 || this.consumerMsgCount > 0 || this.producerCount > 0;
420+
return this.timeLimit > 0 || this.consumerMsgCount > 0 || this.producerMsgCount > 0;
421421
}
422422

423423
public void setExclusive(boolean exclusive) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
15+
16+
package com.rabbitmq.perf;
17+
18+
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.params.ParameterizedTest;
20+
import org.junit.jupiter.params.provider.Arguments;
21+
import org.junit.jupiter.params.provider.MethodSource;
22+
23+
import java.util.function.Consumer;
24+
import java.util.stream.Stream;
25+
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.params.provider.Arguments.of;
28+
29+
public class MulticastParamsTest {
30+
31+
MulticastParams params;
32+
33+
static Stream<Arguments> hasLimitArguments() {
34+
return Stream.of(
35+
of(tc("No limit when time or message count are not limited", -1, -1, -1, false)),
36+
of(tc("Limited if time limit", 10, -1, -1, true)),
37+
of(tc("Limited if consumer message count limit", -1, 1000, -1, true)),
38+
of(tc("Limited if producer message count limit", -1, -1, 1000, true)),
39+
of(tc("Limited if consumer message and producer message count limit", -1, 1000, 1000, true)),
40+
of(tc("Limited if time and consumer message count limit", 10, 1000, -1, true)),
41+
of(tc("Limited if time and producer message count limit", 10, -1, 1000, true)),
42+
of(tc("Limited if time, consumer message, producer message count limit", 10, 1000, 1000, true))
43+
);
44+
}
45+
46+
static TestConfiguration tc(String description, int timeLimit, int consumerMsgCount, int producerMsgCount, boolean expected) {
47+
return new TestConfiguration(description, p -> {
48+
p.setTimeLimit(timeLimit);
49+
p.setConsumerMsgCount(consumerMsgCount);
50+
p.setProducerMsgCount(producerMsgCount);
51+
}, expected);
52+
}
53+
54+
@BeforeEach
55+
public void init() {
56+
params = new MulticastParams();
57+
}
58+
59+
@ParameterizedTest
60+
@MethodSource("hasLimitArguments")
61+
public void hasLimit(TestConfiguration tc) {
62+
tc.configurer.accept(params);
63+
assertEquals(tc.expected, params.hasLimit(), tc.description);
64+
}
65+
66+
static class TestConfiguration {
67+
68+
String description;
69+
Consumer<MulticastParams> configurer;
70+
boolean expected;
71+
72+
public TestConfiguration(String description, Consumer<MulticastParams> configurer, boolean expected) {
73+
this.description = description;
74+
this.configurer = configurer;
75+
this.expected = expected;
76+
}
77+
}
78+
79+
}

0 commit comments

Comments
 (0)