Skip to content

Commit f6bcc34

Browse files
committed
Add --server-name-indication option to performance tool
Fixes #12
1 parent bc63290 commit f6bcc34

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

src/main/java/com/rabbitmq/stream/perf/StreamPerfTest.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.rabbitmq.stream.ConsumerBuilder;
2727
import com.rabbitmq.stream.Environment;
2828
import com.rabbitmq.stream.EnvironmentBuilder;
29+
import com.rabbitmq.stream.EnvironmentBuilder.TlsConfiguration;
2930
import com.rabbitmq.stream.OffsetSpecification;
3031
import com.rabbitmq.stream.Producer;
3132
import com.rabbitmq.stream.StreamCreator;
@@ -71,6 +72,8 @@
7172
import java.util.function.Supplier;
7273
import java.util.stream.Collectors;
7374
import java.util.stream.IntStream;
75+
import javax.net.ssl.SNIServerName;
76+
import javax.net.ssl.SSLParameters;
7477
import org.slf4j.Logger;
7578
import org.slf4j.LoggerFactory;
7679
import picocli.CommandLine;
@@ -296,6 +299,13 @@ public class StreamPerfTest implements Callable<Integer> {
296299
defaultValue = "false")
297300
private boolean memoryReport;
298301

302+
@CommandLine.Option(
303+
names = {"--server-name-indication", "-sni"},
304+
description = "server names for Server Name Indication TLS parameter, separated by commas",
305+
defaultValue = "",
306+
converter = Utils.SniServerNamesConverter.class)
307+
private List<SNIServerName> sniServerNames;
308+
299309
private MetricsCollector metricsCollector;
300310
private PerformanceMetrics performanceMetrics;
301311

@@ -492,14 +502,18 @@ public Integer call() throws Exception {
492502
.maxConsumersByConnection(this.consumersByConnection);
493503

494504
if (tls) {
495-
environmentBuilder =
496-
environmentBuilder
497-
.tls()
498-
.sslContext(
499-
SslContextBuilder.forClient()
500-
.trustManager(Utils.TRUST_EVERYTHING_TRUST_MANAGER)
501-
.build())
502-
.environmentBuilder();
505+
TlsConfiguration tlsConfiguration = environmentBuilder.tls();
506+
tlsConfiguration =
507+
tlsConfiguration.sslContext(
508+
SslContextBuilder.forClient()
509+
.trustManager(Utils.TRUST_EVERYTHING_TRUST_MANAGER)
510+
.build());
511+
if (!this.sniServerNames.isEmpty()) {
512+
SSLParameters sslParameters = new SSLParameters();
513+
sslParameters.setServerNames(this.sniServerNames);
514+
tlsConfiguration = tlsConfiguration.sslParameters(sslParameters);
515+
}
516+
environmentBuilder = tlsConfiguration.environmentBuilder();
503517
}
504518

505519
Environment environment = environmentBuilder.build();

src/main/java/com/rabbitmq/stream/perf/Utils.java

+18
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
import java.util.function.BiFunction;
3939
import java.util.stream.Collectors;
4040
import java.util.stream.IntStream;
41+
import javax.net.ssl.SNIHostName;
42+
import javax.net.ssl.SNIServerName;
4143
import javax.net.ssl.X509TrustManager;
4244
import org.slf4j.Logger;
4345
import org.slf4j.LoggerFactory;
4446
import picocli.CommandLine;
47+
import picocli.CommandLine.ITypeConverter;
4548

4649
class Utils {
4750

@@ -161,6 +164,21 @@ public BiFunction<String, Integer, String> convert(String input) {
161164
}
162165
}
163166

167+
static class SniServerNamesConverter implements ITypeConverter<List<SNIServerName>> {
168+
169+
@Override
170+
public List<SNIServerName> convert(String value) throws Exception {
171+
if (value == null || value.trim().isEmpty()) {
172+
return Collections.emptyList();
173+
} else {
174+
return Arrays.stream(value.split(","))
175+
.map(s -> s.trim())
176+
.map(s -> new SNIHostName(s))
177+
.collect(Collectors.toList());
178+
}
179+
}
180+
}
181+
164182
static class RangeTypeConverter implements CommandLine.ITypeConverter<String> {
165183

166184
@Override

src/test/java/com/rabbitmq/stream/perf/StreamPerfTestTest.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ void offsetShouldNotBeStoredWhenOptionIsNotEnabled() throws Exception {
198198
@Test
199199
@DisabledIfTlsNotEnabled
200200
void shouldConnectWithTls() throws Exception {
201-
Future<?> run = run(builder().uris("rabbitmq-stream+tls://guest:guest@localhost:5551/%2f"));
201+
Future<?> run =
202+
run(
203+
builder()
204+
.uris("rabbitmq-stream+tls://guest:guest@localhost:5551/%2f")
205+
.serverNameIndication("localhost"));
202206
waitUntilStreamExists(s);
203207
waitOneSecond();
204208
run.cancel(true);
@@ -310,6 +314,11 @@ ArgumentsBuilder uris(String url) {
310314
return this;
311315
}
312316

317+
ArgumentsBuilder serverNameIndication(String sni) {
318+
arguments.put("server-name-indication", sni);
319+
return this;
320+
}
321+
313322
ArgumentsBuilder byteRates() {
314323
arguments.put("metrics-byte-rates", "");
315324
return this;

src/test/java/com/rabbitmq/stream/perf/UtilsTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.rabbitmq.stream.perf.Utils.CompressionTypeConverter;
2525
import com.rabbitmq.stream.perf.Utils.PatternConsumerNameStrategy;
2626
import com.rabbitmq.stream.perf.Utils.RangeTypeConverter;
27+
import com.rabbitmq.stream.perf.Utils.SniServerNamesConverter;
2728
import java.util.Arrays;
2829
import java.util.Collections;
2930
import java.util.List;
@@ -33,6 +34,7 @@
3334
import java.util.stream.IntStream;
3435
import java.util.stream.LongStream;
3536
import java.util.stream.Stream;
37+
import javax.net.ssl.SNIHostName;
3638
import org.junit.jupiter.api.Test;
3739
import org.junit.jupiter.params.ParameterizedTest;
3840
import org.junit.jupiter.params.provider.Arguments;
@@ -145,6 +147,16 @@ void consumerNameStrategy(String pattern, String expected) {
145147
assertThat(strategy.apply("s1", 2)).isEqualTo(expected);
146148
}
147149

150+
@Test
151+
void sniServerNamesConverter() throws Exception {
152+
SniServerNamesConverter converter = new SniServerNamesConverter();
153+
assertThat(converter.convert("")).isEmpty();
154+
assertThat(converter.convert("localhost,dummy"))
155+
.hasSize(2)
156+
.contains(new SNIHostName("localhost"))
157+
.contains(new SNIHostName("dummy"));
158+
}
159+
148160
@Test
149161
void writeReadLongInByteArray() {
150162
byte[] array = new byte[8];

0 commit comments

Comments
 (0)