Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package com.azure.perf.test.core;

import java.net.URI;
import java.util.Arrays;
import java.util.List;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.converters.IParameterSplitter;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
Expand All @@ -19,8 +22,8 @@ public class PerfStressOptions {
@Parameter(names = { "--insecure" }, description = "Allow untrusted SSL server certs")
private boolean insecure = false;

@Parameter(names = { "-x", "--test-proxy" }, description = "URI of TestProxy Server")
private URI testProxy;
@Parameter(names = { "-x", "--test-proxies" }, splitter = SemiColonSplitter.class, description = "URIs of TestProxy Servers (separated by ';')")
private List<URI> testProxies;

@Parameter(names = { "-i", "--iterations" }, description = "Number of iterations of main test loop")
private int iterations = 1;
Expand Down Expand Up @@ -79,8 +82,8 @@ public boolean isInsecure() {
* Get the configured test proxy for performance test.
* @return The configured test proxy.
*/
public URI getTestProxy() {
return testProxy;
public List<URI> getTestProxies() {
return testProxies;
}

/**
Expand Down Expand Up @@ -122,4 +125,10 @@ public int getWarmup() {
public boolean isSync() {
return sync;
}

private static class SemiColonSplitter implements IParameterSplitter {
public List<String> split(String value) {
return Arrays.asList(value.split(";"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void run(Class<?> testClass, PerfStressOptions options) {
Flux.just(tests).flatMap(PerfStressTest::setupAsync).blockLast();
setupStatus.dispose();

if (options.getTestProxy() != null) {
if (options.getTestProxies() != null && !options.getTestProxies().isEmpty()) {
Disposable recordStatus = printStatus("=== Record and Start Playback ===", () -> ".", false, false);
Flux.just(tests).flatMap(PerfStressTest::recordAndStartPlaybackAsync).blockLast();
startedPlayback = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import reactor.core.publisher.Mono;

import java.lang.reflect.Method;
import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.SSLException;

/**
Expand All @@ -28,6 +30,7 @@
*/
public abstract class PerfStressTest<TOptions extends PerfStressOptions> {
private final reactor.netty.http.client.HttpClient recordPlaybackHttpClient;
private final URI testProxy;
private final TestProxyPolicy testProxyPolicy;
private String recordingId;

Expand All @@ -38,13 +41,17 @@ public abstract class PerfStressTest<TOptions extends PerfStressOptions> {
protected final HttpClient httpClient;
protected final Iterable<HttpPipelinePolicy> policies;

private static final AtomicInteger globalParallelIndex = new AtomicInteger();
protected final int parallelIndex;

/**
* Creates an instance of performance test.
* @param options the options configured for the test.
* @throws IllegalStateException if SSL context cannot be created.
*/
public PerfStressTest(TOptions options) {
this.options = options;
this.parallelIndex = globalParallelIndex.getAndIncrement();

final SslContext sslContext;

Expand All @@ -66,18 +73,20 @@ public PerfStressTest(TOptions options) {
httpClient = null;
}

if (options.getTestProxy() != null) {
if (options.getTestProxies() != null && !options.getTestProxies().isEmpty()) {
if (options.isInsecure()) {
recordPlaybackHttpClient = reactor.netty.http.client.HttpClient.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
} else {
recordPlaybackHttpClient = reactor.netty.http.client.HttpClient.create();
}

testProxyPolicy = new TestProxyPolicy(options.getTestProxy());
testProxy = options.getTestProxies().get(parallelIndex % options.getTestProxies().size());
testProxyPolicy = new TestProxyPolicy(testProxy);
policies = Arrays.asList(testProxyPolicy);
} else {
recordPlaybackHttpClient = null;
testProxy = null;
testProxyPolicy = null;
policies = null;
}
Expand Down Expand Up @@ -179,7 +188,7 @@ public Mono<Void> stopPlaybackAsync() {
h.set("x-purge-inmemory-recording", Boolean.toString(true));
})
.post()
.uri(options.getTestProxy().resolve("/playback/stop"))
.uri(testProxy.resolve("/playback/stop"))
.response()
.doOnSuccess(response -> {
testProxyPolicy.setMode(null);
Expand Down Expand Up @@ -207,7 +216,7 @@ public Mono<Void> globalCleanupAsync() {
private Mono<Void> startRecordingAsync() {
return recordPlaybackHttpClient
.post()
.uri(options.getTestProxy().resolve("/record/start"))
.uri(testProxy.resolve("/record/start"))
.response()
.doOnNext(response -> {
recordingId = response.responseHeaders().get("x-recording-id");
Expand All @@ -219,7 +228,7 @@ private Mono<Void> stopRecordingAsync() {
return recordPlaybackHttpClient
.headers(h -> h.set("x-recording-id", recordingId))
.post()
.uri(options.getTestProxy().resolve("/record/stop"))
.uri(testProxy.resolve("/record/stop"))
.response()
.then();
}
Expand All @@ -228,7 +237,7 @@ private Mono<Void> startPlaybackAsync() {
return recordPlaybackHttpClient
.headers(h -> h.set("x-recording-id", recordingId))
.post()
.uri(options.getTestProxy().resolve("/playback/start"))
.uri(testProxy.resolve("/playback/start"))
.response()
.doOnNext(response -> {
recordingId = response.responseHeaders().get("x-recording-id");
Expand Down