Skip to content

Commit

Permalink
[fix][test] Fix RangeConvert parse issue in the PerformanceProducer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc authored Jul 8, 2023
1 parent 0bac873 commit 3a9fca9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static class Arguments extends PerformanceTopicListArguments {

@Parameter(names = { "-dr", "--delay-range"}, description = "Mark messages with a given delay by a random"
+ " number of seconds. this value between the specified origin (inclusive) and the specified bound"
+ " (exclusive). e.g. \"1,300\"", converter = RangeConvert.class)
+ " (exclusive). e.g. 1,300", converter = RangeConvert.class)
public Range<Long> delayRange = null;

@Parameter(names = { "-set",
Expand Down Expand Up @@ -801,7 +801,7 @@ static class RangeConvert implements IStringConverter<Range<Long>> {
public Range<Long> convert(String rangeStr) {
try {
requireNonNull(rangeStr);
final String[] facts = rangeStr.substring(1, rangeStr.length() - 1).split(",");
final String[] facts = rangeStr.split(",");
final long min = Long.parseLong(facts[0].trim());
final long max = Long.parseLong(facts[1].trim());
return Range.closedOpen(min, max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
*/
package org.apache.pulsar.testclient;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.client.api.ClientBuilder;
Expand All @@ -35,13 +42,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;

@Slf4j
public class PerformanceProducerTest extends MockedPulsarServiceBaseTest {
private final String testTenant = "prop-xyz";
Expand Down Expand Up @@ -237,4 +237,12 @@ public void testMaxOutstanding() throws Exception {
});
consumer.close();
}

@Test
public void testRangeConvert() {
PerformanceProducer.RangeConvert rangeConvert = new PerformanceProducer.RangeConvert();
Range<Long> range = rangeConvert.convert("100,200");
Assert.assertEquals(range.lowerEndpoint(), 100);
Assert.assertEquals(range.upperEndpoint(), 200);
}
}

0 comments on commit 3a9fca9

Please sign in to comment.