Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into update-identity-liv…
Browse files Browse the repository at this point in the history
…e-tests
  • Loading branch information
g2vinay committed Nov 1, 2024
2 parents 0853563 + d05d525 commit ff9d5e1
Show file tree
Hide file tree
Showing 6,680 changed files with 251,778 additions and 152,840 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
"VMSS",
"reimaged",
"isdirectory",
"SSDLRS"
"SSDLRS",
"VMGUEST"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions common/perf-test-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.15.5</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
<version>1.15.6</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.12.4</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
<version>1.12.5</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-jdk-httpclient</artifactId>
<version>1.0.0-beta.17</version> <!-- {x-version-update;com.azure:azure-core-http-jdk-httpclient;dependency} -->
<version>1.0.0-beta.18</version> <!-- {x-version-update;com.azure:azure-core-http-jdk-httpclient;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-vertx</artifactId>
<version>1.0.0-beta.22</version> <!-- {x-version-update;com.azure:azure-core-http-vertx;dependency} -->
<version>1.0.0-beta.23</version> <!-- {x-version-update;com.azure:azure-core-http-vertx;dependency} -->
</dependency>
<dependency>
<groupId>io.vertx</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ private static HttpClient createHttpClient(PerfStressOptions options) {
if (httpClientType.equals(NETTY)) {
if (options.isInsecure()) {
try {
SslContext sslContext = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
SslContext sslContext
= SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();

reactor.netty.http.client.HttpClient nettyHttpClient =
reactor.netty.http.client.HttpClient.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
reactor.netty.http.client.HttpClient nettyHttpClient = reactor.netty.http.client.HttpClient.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));

return new NettyAsyncHttpClientBuilder(nettyHttpClient).build();
} catch (SSLException e) {
Expand All @@ -109,12 +107,12 @@ private static HttpClient createHttpClient(PerfStressOptions options) {
if (options.isInsecure()) {
try {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(
null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), new SecureRandom());
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.sslSocketFactory(sslContext.getSocketFactory(),
(X509TrustManager) InsecureTrustManagerFactory.INSTANCE.getTrustManagers()[0])
.build();
sslContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), new SecureRandom());
OkHttpClient okHttpClient
= new OkHttpClient.Builder()
.sslSocketFactory(sslContext.getSocketFactory(),
(X509TrustManager) InsecureTrustManagerFactory.INSTANCE.getTrustManagers()[0])
.build();
return new OkHttpAsyncHttpClientBuilder(okHttpClient).build();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IllegalStateException(e);
Expand All @@ -128,13 +126,13 @@ private static HttpClient createHttpClient(PerfStressOptions options) {
throw new UnsupportedOperationException("Can't configure JDK HttpClient for insecure mode.");
} else {
// we want to support friendly name for jdk, but can't use JdkHttpClientProvider on Java 8
httpClientType = PerfStressOptions.HttpClientType.fromString("com.azure.core.http.jdk.httpclient.JdkHttpClientProvider");
httpClientType = PerfStressOptions.HttpClientType
.fromString("com.azure.core.http.jdk.httpclient.JdkHttpClientProvider");
}
} else if (httpClientType.equals(VERTX)) {
if (options.isInsecure()) {
HttpClientOptions vertxOptions = new io.vertx.core.http.HttpClientOptions()
.setSsl(true)
.setTrustAll(true);
HttpClientOptions vertxOptions
= new io.vertx.core.http.HttpClientOptions().setSsl(true).setTrustAll(true);
return createVertxReflectivelyUntilNameChangeReleases(vertxOptions);
} else {
httpClientProvider = getVertxClientProviderReflectivelyUntilNameChangeReleases();
Expand Down Expand Up @@ -170,7 +168,8 @@ private static HttpClient createVertxReflectivelyUntilNameChangeReleases(HttpCli
}

try {
httpClientBuilder.getClass().getDeclaredMethod("httpClientOptions", HttpClientOptions.class)
httpClientBuilder.getClass()
.getDeclaredMethod("httpClientOptions", HttpClientOptions.class)
.invoke(httpClientBuilder, vertxOptions);

return (HttpClient) httpClientBuilder.getClass().getDeclaredMethod("build").invoke(httpClientBuilder);
Expand All @@ -197,14 +196,16 @@ private static Class<? extends HttpClientProvider> getVertxClientProviderReflect
}

@SuppressWarnings("unchecked")
private static Class<? extends HttpClientProvider> getHttpClientProvider(PerfStressOptions.HttpClientType httpClientType) {
private static Class<? extends HttpClientProvider>
getHttpClientProvider(PerfStressOptions.HttpClientType httpClientType) {
String providerClassName = httpClientType.toString();
try {
Class<?> provider = Class.forName(providerClassName, false, ApiPerfTestBase.class.getClassLoader());
if (HttpClientProvider.class.isAssignableFrom(provider)) {
return (Class<? extends HttpClientProvider>) provider;
} else {
throw new IllegalArgumentException("Http client type does not match HttpClientProvider implementation: " + providerClassName);
throw new IllegalArgumentException(
"Http client type does not match HttpClientProvider implementation: " + providerClassName);
}
} catch (Throwable e) {
throw new IllegalArgumentException("Http client provider type is not found: " + providerClassName, e);
Expand All @@ -214,9 +215,8 @@ private static Class<? extends HttpClientProvider> getHttpClientProvider(PerfStr
private static reactor.netty.http.client.HttpClient createRecordPlaybackClient(PerfStressOptions options) {
if (options.isInsecure()) {
try {
SslContext sslContext = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
SslContext sslContext
= SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
return reactor.netty.http.client.HttpClient.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
} catch (SSLException e) {
Expand Down Expand Up @@ -264,18 +264,15 @@ public Mono<Void> runAllAsync(long endNanoTime) {
long startNanoTime = System.nanoTime();

return Flux.generate(sink -> {
if (System.nanoTime() < endNanoTime) {
sink.next(1);
} else {
sink.complete();
}
})
.flatMap(ignored -> runTestAsync(), 1)
.doOnNext(result -> {
completedOperations += result;
lastCompletionNanoTime = System.nanoTime() - startNanoTime;
})
.then();
if (System.nanoTime() < endNanoTime) {
sink.next(1);
} else {
sink.complete();
}
}).flatMap(ignored -> runTestAsync(), 1).doOnNext(result -> {
completedOperations += result;
lastCompletionNanoTime = System.nanoTime() - startNanoTime;
}).then();
}

public CompletableFuture<Void> runAllAsyncWithCompletableFuture(long endNanoTime) {
Expand All @@ -289,12 +286,10 @@ public CompletableFuture<Void> runAllAsyncWithCompletableFuture(long endNanoTime
try {
semaphore.acquire();
// Each runTestAsyncWithCompletableFuture() call runs independently
CompletableFuture<Void> testFuture = runTestAsyncWithCompletableFuture()
.thenAccept(result -> {
completedOperations += result;
lastCompletionNanoTime = System.nanoTime() - startNanoTime;
})
.whenComplete((res, ex) -> semaphore.release());
CompletableFuture<Void> testFuture = runTestAsyncWithCompletableFuture().thenAccept(result -> {
completedOperations += result;
lastCompletionNanoTime = System.nanoTime() - startNanoTime;
}).whenComplete((res, ex) -> semaphore.release());
futures.add(testFuture);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -424,54 +419,46 @@ Runnable runTestAsyncWithVirtualThread() {
* @return An empty {@link Mono}.
*/
public Mono<Void> stopPlaybackAsync() {
return recordPlaybackHttpClient
.headers(h -> {
// The Recording id to track the recording session on the Test Proxy Server.
h.set("x-recording-id", recordingId);
// Indicates Test Proxy Server to purge the cached recording.
h.set("x-purge-inmemory-recording", Boolean.toString(true));
})
.post()
.uri(testProxy.resolve("/playback/stop"))
.response()
.doOnSuccess(response -> {
testProxyPolicy.setMode(null);
testProxyPolicy.setRecordingId(null);
})
.then();
return recordPlaybackHttpClient.headers(h -> {
// The Recording id to track the recording session on the Test Proxy Server.
h.set("x-recording-id", recordingId);
// Indicates Test Proxy Server to purge the cached recording.
h.set("x-purge-inmemory-recording", Boolean.toString(true));
}).post().uri(testProxy.resolve("/playback/stop")).response().doOnSuccess(response -> {
testProxyPolicy.setMode(null);
testProxyPolicy.setRecordingId(null);
}).then();
}

private Mono<Void> startRecordingAsync() {
return Mono.defer(() -> recordPlaybackHttpClient
.post()
return Mono.defer(() -> recordPlaybackHttpClient.post()
.uri(testProxy.resolve("/record/start"))
.response()
.doOnNext(response -> {
recordingId = response.responseHeaders().get("x-recording-id");
}).then());
})
.then());
}

private Mono<Void> stopRecordingAsync() {
return Mono.defer(() -> recordPlaybackHttpClient
.headers(h -> h.set("x-recording-id", recordingId))
return Mono.defer(() -> recordPlaybackHttpClient.headers(h -> h.set("x-recording-id", recordingId))
.post()
.uri(testProxy.resolve("/record/stop"))
.response()
.then());
}

private Mono<Void> startPlaybackAsync() {
return Mono.defer(() -> recordPlaybackHttpClient
.headers(h -> h.set("x-recording-id", recordingId))
return Mono.defer(() -> recordPlaybackHttpClient.headers(h -> h.set("x-recording-id", recordingId))
.post()
.uri(testProxy.resolve("/playback/start"))
.response()
.doOnNext(response -> {
recordingId = response.responseHeaders().get("x-recording-id");
}).then());
})
.then());
}


/**
* Records responses and starts tests in playback mode.
*
Expand All @@ -482,21 +469,15 @@ Mono<Void> postSetupAsync() {
if (testProxyPolicy != null) {

// Make one call to Run() before starting recording, to avoid capturing one-time setup like authorization requests.
return runSyncOrAsync()
.then(startRecordingAsync())
.then(Mono.defer(() -> {
testProxyPolicy.setRecordingId(recordingId);
testProxyPolicy.setMode("record");
return Mono.empty();
}))
.then(runSyncOrAsync())
.then(stopRecordingAsync())
.then(startPlaybackAsync())
.then(Mono.defer(() -> {
testProxyPolicy.setRecordingId(recordingId);
testProxyPolicy.setMode("playback");
return Mono.empty();
}));
return runSyncOrAsync().then(startRecordingAsync()).then(Mono.defer(() -> {
testProxyPolicy.setRecordingId(recordingId);
testProxyPolicy.setMode("record");
return Mono.empty();
})).then(runSyncOrAsync()).then(stopRecordingAsync()).then(startPlaybackAsync()).then(Mono.defer(() -> {
testProxyPolicy.setRecordingId(recordingId);
testProxyPolicy.setMode("playback");
return Mono.empty();
}));
}
return Mono.empty();
}
Expand All @@ -508,9 +489,9 @@ private Mono<Void> runSyncOrAsync() {
} else if (options.isCompletableFuture()) {
return Mono.fromFuture(CompletableFuture.supplyAsync(() -> runTestAsyncWithCompletableFuture())).then();
} else if (options.isExecutorService()) {
return Mono.fromRunnable(runTestAsyncWithExecutorService());
return Mono.fromRunnable(runTestAsyncWithExecutorService());
} else if (options.isVirtualThread()) {
return Mono.fromRunnable(this::runTestAsyncWithVirtualThread);
return Mono.fromRunnable(this::runTestAsyncWithVirtualThread);
} else {
return runTestAsync().then();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public BatchPerfTest(TOptions options) {
super(options);
}


/**
* Run batch operation API perf test.
* @return the number of operations successfully completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void eventRaised() {
completedOps.getAndIncrement();
lastCompletionNanoTime = System.nanoTime() - startTime;
}

/**
* Indicates an error was raised, and stops the performance test flow.
*/
Expand All @@ -69,7 +70,8 @@ public void runAll(long endNanoTime) {
synchronized (this) {
try {
wait((endNanoTime - startTime) / 1000000);
} catch (InterruptedException e) { }
} catch (InterruptedException e) {
}
if (errorRaised) {
throw new RuntimeException(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class HttpPipelineOptions extends PerfStressOptions {
@Parameter(names = { "-u", "--url" }, description = "URL to fetch", required = true)
private URL url;

@Parameter(names = { "--first-run-extra-requests" }, description = "Extra requests to send on first run. "
+ "Simulates SDKs which require extra requests (like authentication) on first API call.")
@Parameter(
names = { "--first-run-extra-requests" },
description = "Extra requests to send on first run. "
+ "Simulates SDKs which require extra requests (like authentication) on first API call.")
private int firstRunExtraRequests = 0;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,16 @@ public Mono<Void> runAsync() {
*/
public Mono<Void> sendRequest() {
HttpRequest request = new HttpRequest(HttpMethod.GET, options.getUrl());
return httpPipeline
.send(request)
.flatMapMany(HttpResponse::getBody)
.map(b -> {
int readCount = 0;
int remaining = b.remaining();
while (readCount < remaining) {
int expectedReadCount = Math.min(remaining - readCount, BUFFER_SIZE);
b.get(buffer, 0, expectedReadCount);
readCount += expectedReadCount;
}
return httpPipeline.send(request).flatMapMany(HttpResponse::getBody).map(b -> {
int readCount = 0;
int remaining = b.remaining();
while (readCount < remaining) {
int expectedReadCount = Math.min(remaining - readCount, BUFFER_SIZE);
b.get(buffer, 0, expectedReadCount);
readCount += expectedReadCount;
}

return 1;
})
.then();
return 1;
}).then();
}
}
Loading

0 comments on commit ff9d5e1

Please sign in to comment.