Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
34 changes: 34 additions & 0 deletions sdk/core/azure-core-experimental-perf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Azure Core Experimental Performance test client library for Java

Represents Performance tests for Azure Core SDK for Java.

## Getting started

### Prerequisites

- Java Development Kit (JDK) with version 8 or above

### Adding the package to your product


## Key concepts


## Examples

## Troubleshooting

## Next steps

## Contributing

If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft
Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html).

1. Fork it
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Push to the branch (`git push origin my-new-feature`)
1. Create new Pull Request

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fcore%2Fexperimental-perf-test%2FREADME.png)
64 changes: 64 additions & 0 deletions sdk/core/azure-core-experimental-perf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.azure</groupId>
<artifactId>azure-client-sdk-parent</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} -->
<relativePath>../../parents/azure-client-sdk-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>azure-core-experimental-perf</artifactId>
<version>1.0.0-beta.1</version>


<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.14.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>perf-test-core</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:perf-test-core;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.11</version> <!-- {x-version-update;com.azure:azure-core-experimental-perf;current} -->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-assembly-plugin;external_dependency} -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.azure.core.perf.App
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.perf;

import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.experimental.http.policy.ARMChallengeAuthenticationPolicy;
import com.azure.core.experimental.http.policy.BearerTokenAuthenticationChallengePolicy;
import com.azure.core.experimental.implementation.AzureEnvironment;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.perf.core.MockHttpClient;
import com.azure.core.perf.core.MyRestProxyService;
import com.azure.core.perf.models.MockHttpResponse;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.perf.test.core.PerfStressOptions;
import com.azure.perf.test.core.PerfStressTest;
import reactor.core.publisher.Mono;

import java.time.OffsetDateTime;
import java.util.HashMap;

/**
* The Performance Test class for Bearer Token Authentication Challenge Policy.
*/
public class ARMChallengeAuthenticationPolicyTest extends PerfStressTest<PerfStressOptions> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this named ARM? This isn't related to the management plane right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this policy is for ARM SDK.
We will work with ARM folks and move it there later on.

private static final String CLAIMS_ACCESS_TOKEN = "CLAIMS-ACCESS-TOKEN";
private static final String ACCESS_TOKEN = "ACCESS-TOKEN";
private static final String AUTHORIZATION = "Authorization";
private static final String APPLICATION_JSON = "application/json";
private static final String CONTENT_TYPE = "Content-Type";
private static final String MOCK_CHALLENGE = "Bearer authorization_uri="
+ "\"https://login.windows-ppe.net/\", error=\"invalid_token\","
+ " error_description=\"User session has been revoked\","
+ " claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0=\"";

private final ClientLogger logger = new ClientLogger(ARMChallengeAuthenticationPolicyTest.class);
private final MockHttpClient mockHTTPClient;
private final MyRestProxyService service;
private boolean trigger = false;

/**
* Creates an instance of the ARMChallengeAuthenticationPolicyTest class.
* @param options the command line options to run the performance test.
*/
public ARMChallengeAuthenticationPolicyTest(PerfStressOptions options) {
super(options);
mockHTTPClient = new MockHttpClient((httpRequest) -> {
String bearerToken = httpRequest.getHeaders().getValue(AUTHORIZATION);
if (bearerToken.contains(CLAIMS_ACCESS_TOKEN)) {
return createMockSuccessResponse(httpRequest, APPLICATION_JSON);
} else {
return createMockClaimsResponse(httpRequest, "application/json");
}
});
final HttpPipeline pipeline = new HttpPipelineBuilder()
.policies(new ARMChallengeAuthenticationPolicy(new TokenCredential() {
@Override
public Mono<AccessToken> getToken(TokenRequestContext request) {
return Mono.defer(() -> {
AccessToken token;
if (!CoreUtils.isNullOrEmpty(request.getClaims()) && request.getClaims().length() > 1) {
token = new AccessToken(CLAIMS_ACCESS_TOKEN, OffsetDateTime.now().plusDays(1));
} else {
token = new AccessToken(ACCESS_TOKEN, OffsetDateTime.now().plusDays(1));
}
return Mono.just(token);
});
}
}, new AzureEnvironment(new HashMap<>()), "Dummy-Scope"))
.httpClient(mockHTTPClient)
.build();

service = RestProxy.create(MyRestProxyService.class, pipeline);
}

@Override
public void run() {
throw logger.logExceptionAsError(new UnsupportedOperationException());
}

@Override
public Mono<Void> runAsync() {
if (!trigger) {
trigger = true;
return service.listSubscriptions().then();
} else {
return Mono.empty();
}

}

private HttpResponse createMockClaimsResponse(HttpRequest httpRequest, String contentType) {
HttpHeaders headers = new HttpHeaders().set(CONTENT_TYPE, contentType);
headers.set(BearerTokenAuthenticationChallengePolicy.WWW_AUTHENTICATE, MOCK_CHALLENGE);
HttpResponse res = new MockHttpResponse(httpRequest, 401, headers);
return res;
}

private HttpResponse createMockSuccessResponse(HttpRequest httpRequest, String contentType) {
HttpHeaders headers = new HttpHeaders().set(CONTENT_TYPE, contentType);
HttpResponse res = new MockHttpResponse(httpRequest, 200, headers);
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.perf;

import com.azure.perf.test.core.PerfStressProgram;

/**
* Runs the Storage performance test.
*
* <p>To run from command line. Package the project into a jar with dependencies via mvn clean package.
* Then run the program via java -jar 'compiled-jar-with-dependencies-path' </p>
*
* <p> To run from IDE, set all the required environment variables in IntelliJ via Run -&gt; EditConfigurations
* section.
* Then run the App's main method via IDE.</p>
*/
public class App {

/**
* The main method for the performance testing package.
* @param args the command line arguments.
* @throws RuntimeException if the performance tests implementation classes cannot be found.
*/
public static void main(String[] args) {
Class<?>[] testClasses;

try {
testClasses = new Class<?>[]{
Class.forName("com.azure.core.perf.ARMChallengeAuthenticationPolicyTest")
};
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

PerfStressProgram.run(testClasses, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.perf.core;

import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import reactor.core.publisher.Mono;

import java.util.function.Function;

/**
* The Mock Http Client to send recorded responses back to the Http Pipeline.
*/
public class MockHttpClient implements HttpClient {
private final Function<HttpRequest, HttpResponse> responseSupplier;

/**
* Creates an instance of the {@link MockHttpClient}
*
* @param responseSupplier the supplier to supply the {@link HttpResponse}
*/
public MockHttpClient(Function<HttpRequest, HttpResponse> responseSupplier) {
this.responseSupplier = responseSupplier;
}

@Override
public Mono<HttpResponse> send(HttpRequest request) {
return Mono.just(responseSupplier.apply(request));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.perf.core;

import com.azure.core.annotation.Get;
import com.azure.core.annotation.Host;

import com.azure.core.annotation.ServiceInterface;
import reactor.core.publisher.Mono;


/**
* Mock Rest Proxy Service for Performance Testing.
*/
@Host("https://unused")
@ServiceInterface(name = "MyMockService")
public interface MyRestProxyService {

/**
* List all the subscriptions
* @return A {@link Mono} containing Void.
*/
@Get("ListSubscriptions")
Mono<Void> listSubscriptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* Core package of azure-core-experimental-perf.
*/
package com.azure.core.perf.core;
Loading