Skip to content

Commit

Permalink
Flip Spotless skip (#42634)
Browse files Browse the repository at this point in the history
Flip Spotless skip
  • Loading branch information
alzimmermsft authored Oct 28, 2024
1 parent 191763b commit e9f1ef0
Show file tree
Hide file tree
Showing 453 changed files with 254 additions and 553 deletions.
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public class MockBatchReceiverTest extends BatchPerfTest<MockBatchReceiverTest.MockReceiverOptions> {
final MockReceiver mockReceiver;

/**
* Creates an instance of performance test.
*
Expand All @@ -36,17 +37,18 @@ public int runBatch() {
@Override
public Mono<Integer> runBatchAsync() {
return mockReceiver.receiveAsync(options.minMessageCount, options.maxMessageCount)
.count().map(count -> count.intValue());
.count()
.map(count -> count.intValue());
}

/**
* Options class for Mock Receiver Test.
*/
public static class MockReceiverOptions extends PerfStressOptions {
@Parameter(names = {"--max-message-count" }, description = "Max messages to Receive")
@Parameter(names = { "--max-message-count" }, description = "Max messages to Receive")
private int maxMessageCount = 10;

@Parameter(names = {"--min-message-count" }, description = "Min messages to Receive")
@Parameter(names = { "--min-message-count" }, description = "Min messages to Receive")
private int minMessageCount = 0;

/**
Expand All @@ -73,7 +75,7 @@ public IterableStream<Integer> receive(int minMessageCount, int maxMessageCount)
return IterableStream.of(IntStream.range(1, returnedMessages).boxed().collect(Collectors.toList()));
}

public Flux<Integer> receiveAsync(int minMessageCount, int maxMessageCount) {
public Flux<Integer> receiveAsync(int minMessageCount, int maxMessageCount) {
return Flux.fromIterable(receive(minMessageCount, maxMessageCount));
}
}
Expand Down
Loading

0 comments on commit e9f1ef0

Please sign in to comment.