Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.35k stars 1.99k forks source link

Record/Playback Integration in Storage code #3022

Closed g2vinay closed 5 years ago

g2vinay commented 5 years ago

High level Strategy to integrate Record Playback followed in Java Central Repo:

  1. Take dependency on following libraries com.microsoft.azure azure-mgmt-resources test
com.microsoft.azure azure-mgmt-resources test-jar test com.microsoft.rest client-runtime com.microsoft.azure azure-client-runtime
  1. Update the Test Base Class In the Test Base class where service client is instantiated. In @BeforeMethod, perform Rest client setup based on the test mode: Record/Playback.

In Record mode, rest client needs to be setup in a way similar to this. You need to pass your custom RestClient to the service client(Keyvault, Storage etc.)

interceptorManager = InterceptorManager.create(testName.getMethodName(), testMode); RestClient restClient; ServiceClientCredentials credentials = createTestCredentials(); if (isRecordMode()) { restClient = buildRestClient(new RestClient.Builder().withBaseUrl(<Service/Resource Endpoint URL>) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials) .withLogLevel(LogLevel.NONE) .withNetworkInterceptor(new LoggingInterceptor(LogLevel.BODY_AND_HEADERS)) .withNetworkInterceptor(interceptorManager.initInterceptor()) .withInterceptor(new ResourceManagerThrottlingInterceptor())); -- Utilize this Rest Client to instantiate the service client (e.g KeyvaultClient) } else{ //Playback mode restClient = new RestClient.Builder().withBaseUrl("http://localhost:") .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials) .withLogLevel(LogLevel.NONE) .withNetworkInterceptor(new LoggingInterceptor(LogLevel.BODY_AND_HEADERS)) .withNetworkInterceptor(interceptorManager.initInterceptor()) .withInterceptor(new ResourceManagerThrottlingInterceptor()).build(); -- Utilize this Rest Client to instantiate the service client (e.g KeyvaultClient) }

  1. In the afterMethod,
    Call, interceptorManager.finalizeInterceptor(); -- This step writes the recorded test to a file in record mode, which is used to playback the test later.
sima-zhu commented 5 years ago

Successfully ran the live tests for storage. https://dev.azure.com/azure-sdk/playground/_build/results?buildId=28127

Breakdowns:

  1. Enable record for tests. Get the record-sessions json files.
  2. Add necessary test base for one test case, make it run in playback mode.
  3. Run all tests.
sima-zhu commented 5 years ago

Proposal is ready: https://microsoft-my.sharepoint.com/personal/sizhu_microsoft_com/Documents/Proposal_storage_playback.pptm?web=1

sima-zhu commented 5 years ago

The recode json files has successfully generated. 26 of 1078 tests failed. https://dev.azure.com/azure-sdk/playground/_build/results?buildId=33918&view=ms.vss-test-web.build-test-results-tab&runId=1217924&resultId=100349&paneView=debug

Needs to figure out the reason of failing.

sima-zhu commented 5 years ago

Put along the failed record tests into the second part. Worked on successful ones. Make playback tests run on the success record tests.

https://github.com/Azure/azure-sdk-for-java/issues/3728

sima-zhu commented 5 years ago

Phase 1: Storage API level PR: #3782 Phase 2: Storage Func tests. Phase 3 Transfer Manager

sima-zhu commented 5 years ago

PR out for all the tests: https://github.com/Azure/azure-sdk-for-java/pull/3793