-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storage] Queues - move resource naming into common test, enable para…
…llelization. (#21143) * draft. * fix pom. * fix readme. * blobs. * batch. * changefeed. * crypto * nio * datalake * files * how about this? * that isn't necessary. * let's see. * excess plugin. * Queues: Move resource naming to common test. Enable queue parallelization at record and playback. * recordings. * fix build. * checkstyle. * make sure we can record other modules... * that check isn't needed. * pr feedback. * avoid name collision...
- Loading branch information
1 parent
ff88711
commit e78062b
Showing
313 changed files
with
6,758 additions
and
8,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ommon/src/test-shared/java/com/azure/storage/common/test/shared/StorageResourceNamer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.storage.common.test.shared; | ||
|
||
import com.azure.core.test.TestMode; | ||
import com.azure.core.test.models.RecordedData; | ||
import com.azure.core.test.utils.TestResourceNamer; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.time.OffsetDateTime; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.zip.CRC32; | ||
|
||
public class StorageResourceNamer { | ||
private final TestResourceNamer testResourceNamer; | ||
private final String resourcePrefix; | ||
|
||
public StorageResourceNamer(String testName, TestMode testMode, RecordedData recordedData) { | ||
Objects.requireNonNull(testName); | ||
Objects.requireNonNull(testMode); | ||
resourcePrefix = getCrc32(testName); | ||
testResourceNamer = new TestResourceNamer(resourcePrefix, testMode, recordedData); | ||
} | ||
|
||
public String getResourcePrefix() { | ||
return resourcePrefix; | ||
} | ||
|
||
public String getRandomName(int maxLength) { | ||
return testResourceNamer.randomName(getResourcePrefix(), maxLength); | ||
} | ||
|
||
public String getRandomName(String prefix, int maxLength) { | ||
Objects.requireNonNull(prefix); | ||
return testResourceNamer.randomName(prefix, maxLength); | ||
} | ||
|
||
public OffsetDateTime getUtcNow() { | ||
return testResourceNamer.now(); | ||
} | ||
|
||
public String getRandomUuid() { | ||
return testResourceNamer.randomUuid(); | ||
} | ||
|
||
private static String getCrc32(String input) { | ||
CRC32 crc32 = new CRC32(); | ||
crc32.update(input.getBytes(StandardCharsets.UTF_8)); | ||
return String.format(Locale.US, "%08X", crc32.getValue()).toLowerCase(); | ||
} | ||
} |
70 changes: 68 additions & 2 deletions
70
...orage-common/src/test-shared/java/com/azure/storage/common/test/shared/StorageSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,76 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.storage.common.test.shared; | ||
package com.azure.storage.common.test.shared | ||
|
||
import spock.lang.Specification; | ||
import com.azure.core.http.HttpClient | ||
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder | ||
import com.azure.core.http.policy.HttpPipelinePolicy | ||
import com.azure.core.test.InterceptorManager | ||
import com.azure.core.test.TestMode | ||
import spock.lang.Specification | ||
|
||
class StorageSpec extends Specification { | ||
protected static final TestEnvironment ENVIRONMENT = new TestEnvironment(); | ||
|
||
private String testName | ||
private InterceptorManager interceptorManager | ||
private StorageResourceNamer namer | ||
|
||
def setup() { | ||
testName = getTestName() | ||
if (shouldUseThisToRecord()) { | ||
interceptorManager = new InterceptorManager(testName, ENVIRONMENT.testMode) | ||
namer = new StorageResourceNamer(testName, ENVIRONMENT.testMode, interceptorManager.getRecordedData()) | ||
} | ||
System.out.printf("========================= %s =========================%n", testName) | ||
} | ||
|
||
def cleanup() { | ||
if (shouldUseThisToRecord()) { | ||
interceptorManager.close() | ||
} | ||
} | ||
|
||
// TODO (kasobol-msft) Remove this when all modules are migrated. | ||
protected shouldUseThisToRecord() { | ||
return false | ||
} | ||
|
||
protected StorageResourceNamer getNamer() { | ||
Objects.requireNonNull(namer, "namer has not been initialized yet") | ||
return namer | ||
} | ||
|
||
protected HttpPipelinePolicy getRecordPolicy() { | ||
if (ENVIRONMENT.testMode == TestMode.RECORD) { | ||
return interceptorManager.getRecordPolicy() | ||
} else { | ||
return { context, next -> return next.process() } | ||
} | ||
} | ||
|
||
protected HttpClient getHttpClient() { | ||
if (ENVIRONMENT.testMode != TestMode.PLAYBACK) { | ||
NettyAsyncHttpClientBuilder builder = new NettyAsyncHttpClientBuilder() | ||
return builder.build() | ||
} else { | ||
return interceptorManager.getPlaybackClient() | ||
} | ||
} | ||
|
||
private String getTestName() { | ||
def iterationInfo = specificationContext.currentIteration | ||
def featureInfo = iterationInfo.getParent() | ||
def specInfo = featureInfo.getParent() | ||
def fullName = specInfo.getName() + featureInfo.getName().split(" ").collect { it.capitalize() }.join("") | ||
|
||
if (iterationInfo.getDataValues().length == 0) { | ||
return fullName | ||
} | ||
def prefix = fullName | ||
def suffix = "[" + iterationInfo.getIterationIndex() + "]" | ||
|
||
return prefix + suffix | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.