Skip to content

Commit

Permalink
update to use config to switch use of shared client
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Jan 3, 2022
1 parent 535456b commit ee398f8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 31 deletions.
2 changes: 2 additions & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ com.azure:azure-communication-identity;1.1.1;1.2.0-beta.1
com.azure:azure-communication-phonenumbers;1.0.3;1.1.0-beta.1
com.azure:azure-containers-containerregistry;1.0.0-beta.3;1.0.0-beta.4
com.azure:azure-core;1.18.0;1.19.0-beta.2
com.azure:azure-core-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core-amqp;2.3.0;2.4.0-beta.1
com.azure:azure-core-amqp-experimental;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core-experimental;1.0.0-beta.15;1.0.0-beta.16
Expand Down Expand Up @@ -315,6 +316,7 @@ com.azure.resourcemanager:azure-resourcemanager-azurearcdata;1.0.0-beta.1;1.0.0-
# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
unreleased_com.azure:azure-core-http-netty;1.11.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core-perf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.13.0</version> <!-- {x-version-update;com.azure:azure-storage-blob;dependency} -->
<version>12.13.0-beta.1</version> <!-- {x-version-update;com.azure:azure-storage-blob;dependency} -->
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

package com.azure.core.perf;

import com.azure.core.http.HttpClient;
import com.azure.core.http.netty.NettyAsyncHttpClientProvider;
import com.azure.core.perf.core.ServiceTest;
import com.azure.core.util.HttpClientOptions;
import com.azure.perf.test.core.PerfStressOptions;
import com.azure.storage.blob.BlobContainerAsyncClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceAsyncClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.models.BlobProperties;
import reactor.core.publisher.Mono;

import java.util.UUID;

public class GetBlobProperties extends ServiceTest<PerfStressOptions> {
public GetBlobProperties(PerfStressOptions options) {
super(options);
Expand All @@ -31,25 +31,52 @@ public Mono<Void> globalCleanupAsync() {

@Override
public void run() {
String blobName = "perfblobtest-" + UUID.randomUUID();

BlobServiceClient storageClient = blobServiceClientBuilder.buildClient();
if (useSharedClient) {
BlobServiceClient blobServiceClient = blobServiceClientBuilder.buildClient();
performGetProperties(blobServiceClient);
} else {
// use a customized http client
HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50);
HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions);

BlobServiceClient blobServiceClient = blobServiceClientBuilder
.httpClient(client1)
.buildClient();

BlobContainerClient blobContainerClient = storageClient.createBlobContainer("perfupload" + UUID.randomUUID());
BlobProperties blobProperties = blobContainerClient.getBlobClient(blobName).getProperties();
assert blobProperties.getCreationTime() != null;
assert blobProperties.getExpiresOn() != null;
performGetProperties(blobServiceClient);
}
}

@Override
public Mono<Void> runAsync() {
String blobName = "perfblobtest-" + UUID.randomUUID();

BlobServiceAsyncClient storageAsyncClient = blobServiceClientBuilder.buildAsyncClient();
if (useSharedClient) {
BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient();
return performGetPropertiesAsync(blobServiceAsyncClient);
} else {
// use a customized http client
HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50);
HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions);

BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder
.httpClient(client1)
.buildAsyncClient();

return performGetPropertiesAsync(blobServiceAsyncClient);
}
}

private void performGetProperties(BlobServiceClient blobServiceClient) {
BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer(CONTAINER_NAME);
blobContainerClient.getBlobClient(BLOB_NAME).getProperties();
}

private Mono<Void> performGetPropertiesAsync(BlobServiceAsyncClient blobServiceAsyncClient) {
BlobContainerAsyncClient blobContainerAsyncClient
= blobServiceAsyncClient.createBlobContainer(CONTAINER_NAME).block();

BlobContainerAsyncClient
blobContainerAsyncClient = storageAsyncClient.createBlobContainer("perfupload" + UUID.randomUUID()).block();
return blobContainerAsyncClient.getBlobAsyncClient(blobName)
return blobContainerAsyncClient.getBlobAsyncClient(BLOB_NAME)
.getProperties()
.then();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

package com.azure.core.perf;

import com.azure.core.http.HttpClient;
import com.azure.core.http.netty.NettyAsyncHttpClientProvider;
import com.azure.core.perf.core.ServiceTest;
import com.azure.core.util.HttpClientOptions;
import com.azure.perf.test.core.PerfStressOptions;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceAsyncClient;
import com.azure.storage.blob.BlobServiceClient;
import reactor.core.publisher.Mono;

import java.util.UUID;

public class UploadFromFileTest extends ServiceTest<PerfStressOptions> {
public UploadFromFileTest(PerfStressOptions options) {
super(options);
Expand All @@ -30,25 +31,52 @@ public Mono<Void> globalCleanupAsync() {

@Override
public void run() {
String blobName = "perfblobtest-" + UUID.randomUUID();

BlobServiceClient storageClient = blobServiceClientBuilder.buildClient();
if (useSharedClient) {
BlobServiceClient blobServiceClient = blobServiceClientBuilder.buildClient();
performUploadFromFile(blobServiceClient);

BlobContainerClient blobContainerClient = storageClient.createBlobContainer("perfupload" + UUID.randomUUID());
BlobClient blobClient = blobContainerClient.getBlobClient(blobName);
blobClient.uploadFromFile(filePath, true);
} else {
// use a customized http client
HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50);
HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions);

BlobServiceClient blobServiceClient = blobServiceClientBuilder
.httpClient(client1)
.buildClient();

performUploadFromFile(blobServiceClient);
}
}

@Override
public Mono<Void> runAsync() {
String blobName = "perfblobtest-" + UUID.randomUUID();

BlobServiceAsyncClient storageAsyncClient = blobServiceClientBuilder.buildAsyncClient();
if (useSharedClient) {
BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient();
return performUploadFromFileAsync(blobServiceAsyncClient);
} else {
// use a customized http client
HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50);
HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions);

return storageAsyncClient.createBlobContainer("perfupload" + UUID.randomUUID())
.flatMap(blobContainerAsyncClient -> blobContainerAsyncClient.getBlobAsyncClient(blobName)
.uploadFromFile(filePath, true));
BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder
.httpClient(client1)
.buildAsyncClient();

return performUploadFromFileAsync(blobServiceAsyncClient);
}
}

private void performUploadFromFile(BlobServiceClient blobServiceClient) {
BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer(CONTAINER_NAME);
BlobClient blobClient = blobContainerClient.getBlobClient(BLOB_NAME);
blobClient.uploadFromFile(filePath, true);
}

private Mono<Void> performUploadFromFileAsync(BlobServiceAsyncClient blobServiceAsyncClient) {
return blobServiceAsyncClient.createBlobContainer(CONTAINER_NAME)
.flatMap(blobContainerAsyncClient -> blobContainerAsyncClient.getBlobAsyncClient(BLOB_NAME)
.uploadFromFile(filePath, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
import com.azure.perf.test.core.PerfStressTest;
import com.azure.storage.blob.BlobServiceClientBuilder;

import java.util.UUID;

public abstract class ServiceTest<TOptions extends PerfStressOptions> extends PerfStressTest<TOptions> {

protected final BlobServiceClientBuilder blobServiceClientBuilder;
protected BlobServiceClientBuilder blobServiceClientBuilder;
protected final String filePath;
protected final boolean useSharedClient;
protected static final String CONTAINER_NAME = "perfstress-" + UUID.randomUUID();
protected static final String BLOB_NAME = "perfblobtest-" + UUID.randomUUID();

private final Configuration configuration;

public ServiceTest(TOptions options) {
super(options);
configuration = Configuration.getGlobalConfiguration().clone();
String connectionString = configuration.get("STORAGE_CONNECTION_STRING");
filePath = configuration.get("FILE_PATH");

useSharedClient = CoreUtils.isNullOrEmpty(configuration.get("USE_SHARED_CLIENT"));

if (CoreUtils.isNullOrEmpty(connectionString)) {
throw new IllegalStateException("Environment variable STORAGE_CONNECTION_STRING must be set");
Expand All @@ -30,7 +36,6 @@ public ServiceTest(TOptions options) {
throw new IllegalStateException("Environment variable 'FILE_PATH' must be set");
}


// Set up the service client builder
blobServiceClientBuilder = new BlobServiceClientBuilder().connectionString(connectionString);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.10.1</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
<version>1.11.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-http-netty;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down

0 comments on commit ee398f8

Please sign in to comment.