Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored test header logic into a global spock extension #22573

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ known_content_issues:
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#3113']
- ['sdk/storage/azure-storage-blob-nio/README.md', '#3113']
- ['sdk/storage/azure-storage-common/README.md', '#3113']
- ['sdk/storage/azure-storage-data-movement/README.md', '#3113']
- ['sdk/storage/azure-storage-file/swagger/README.md', '#3113']
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#3113']
- ['sdk/storage/azure-storage-file-share/swagger/README.md','has other required sections']
Expand Down
5 changes: 5 additions & 0 deletions eng/jacoco-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
<artifactId>azure-storage-common</artifactId>
<version>12.13.0-beta.1</version> <!-- {x-version-update;com.azure:azure-storage-common;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-data-movement</artifactId>
<version>12.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-storage-data-movement;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ com.azure:azure-storage-blob-changefeed;12.0.0-beta.7;12.0.0-beta.8
com.azure:azure-storage-blob-cryptography;12.12.0;12.13.0-beta.1
com.azure:azure-storage-blob-nio;12.0.0-beta.7;12.0.0-beta.8
com.azure:azure-storage-common;12.12.0;12.13.0-beta.1
com.azure:azure-storage-data-movement;12.0.0-beta.1;12.0.0-beta.1
com.azure:azure-storage-file-share;12.10.0;12.11.0-beta.1
com.azure:azure-storage-file-datalake;12.6.0;12.7.0-beta.1
com.azure:azure-storage-internal-avro;12.0.5;12.1.0-beta.1
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<module>sdk/storage/azure-storage-blob-cryptography</module>
<module>sdk/storage/azure-storage-blob-nio</module>
<module>sdk/storage/azure-storage-common</module>
<module>sdk/storage/azure-storage-data-movement</module>
<module>sdk/storage/azure-storage-file-datalake</module>
<module>sdk/storage/azure-storage-file-share</module>
<module>sdk/storage/azure-storage-internal-avro</module>
Expand Down Expand Up @@ -317,6 +318,10 @@
<title>Azure Storage - Common</title>
<packages>com.azure.storage.common*</packages>
</group>
<group>
<title>Azure Storage - Data Movement</title>
<packages>com.azure.storage.data.movement*</packages>
</group>
<group>
<title>Azure Storage - Blobs</title>
<packages>com.azure.storage.blob*</packages>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import spock.lang.Specification

class OptionsBagTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

def "SetAccessTier constructor"() {
setup:
def url = "https://account.blob.core.windows.net/container/blob"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class BlobChangefeedPagedFluxTest extends Specification {
List<BlobChangefeedEventWrapper> mockEventWrappers

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
setupEvents()
mockContainer = mock(BlobContainerAsyncClient.class)
mockChangefeedFactory = mock(ChangefeedFactory.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class BlobChunkedDownloaderTest extends APISpec {
BlobChunkedDownloaderFactory factory

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
def cc = primaryBlobServiceAsyncClient.getBlobContainerAsyncClient(generateContainerName())
cc.create().block()
bc = Spy(cc.getBlobAsyncClient(generateBlobName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import java.time.OffsetDateTime

class ChangefeedCursorTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

String urlHost = 'testaccount.blob.core.windows.net'
OffsetDateTime endTime = OffsetDateTime.MAX

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class ChangefeedTest extends Specification {
String urlHost = 'testaccount.blob.core.windows.net'

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
mockContainer = mock(BlobContainerAsyncClient.class)
mockSegmentFactory = mock(SegmentFactory.class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class ChunkTest extends Specification {
List<AvroObject> mockAvroObjects

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
setupEvents()

mockContainer = mock(BlobContainerAsyncClient.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class SegmentTest extends Specification {
ChangefeedCursor cfCursor

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
mockContainer = mock(BlobContainerAsyncClient.class)
mockBlob = mock(BlobAsyncClient.class)
mockShardFactory = mock(ShardFactory.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class ShardTest extends Specification {
ChangefeedCursor segmentCursor

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
mockContainer = mock(BlobContainerAsyncClient.class)
mockChunkFactory = mock(ChunkFactory.class)
mockChunk0 = mock(Chunk.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import java.time.ZoneOffset

class TimeUtilsTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

@Unroll
def "convertPathToTime"() {
expect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ import java.time.ZoneOffset

class BlobServiceSasModelsTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

@Unroll
def "BlobSASPermissions toString"() {
setup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import java.util.concurrent.TimeUnit

class StorageBlockingSinkTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

def "min"() {
setup:
def blockingSink = new StorageBlockingSink()
Expand Down
25 changes: 16 additions & 9 deletions sdk/storage/azure-storage-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-common</artifactId>
<version>12.13.0-beta.1</version> <!-- {x-version-update;com.azure:azure-storage-common;current} -->
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
Expand Down Expand Up @@ -121,20 +129,19 @@

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-jar-plugin;external_dependency} -->
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>test-jar</id>
<phase>test-compile</phase>
<id>test-shared-jar</id>
<phase>process-test-classes</phase>
<goals>
<goal>test-jar</goal>
<goal>single</goal>
</goals>
<configuration>
<includes>
<include>com/azure/storage/common/test/shared/**/*</include>
<include>SpockConfig.groovy</include>
</includes>
<descriptors>
<descriptor>src/test-shared/assembly/assembly.xml</descriptor>
</descriptors>
Comment on lines +134 to +136
Copy link
Contributor

Choose a reason for hiding this comment

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

how does the output of this look like in target folder when you run mvn install?

@alzimmermsft does this affect how commons is released to mvncentral anyhow that we should be worried about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maven doesnt copy over the assembly folder/file into target since it's not specified as a resource. the manifests get transferred as a manifests folder into the target/test-classes folder, preventing it from getting caught with common tests, and the assembly plugin maps it where it needs to go in the artifact

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, but does test jar look the same ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I ran jar xf on it and the contents are the same.

Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't affect releasing to Maven central as this only affect building the library from source

</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}\test-classes</directory>
<outputDirectory>\</outputDirectory>
<includes>
<include>com\azure\storage\common\test\shared\**\*</include>
<include>SpockConfig.groovy</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}\test-classes\manifests</directory>
<outputDirectory>\</outputDirectory>
<includes>
<include>**\*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.azure.core.http.policy.HttpPipelinePolicy
import com.azure.core.test.InterceptorManager
import com.azure.core.test.TestMode
import com.azure.core.util.ServiceVersion
import com.azure.storage.common.test.shared.extensions.TestHeaderExtension
import spock.lang.Specification

class StorageSpec extends Specification {
Expand All @@ -19,10 +20,9 @@ class StorageSpec extends Specification {
private StorageResourceNamer namer

def setup() {
def testName = getTestName()
def testName = TestHeaderExtension.FeatureInterceptor.getTestName(specificationContext.getCurrentIteration())
Copy link
Contributor

Choose a reason for hiding this comment

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

we should create TestNameProvider or something like this and extract getTestName there and use it in both places.
Can be static code.

interceptorManager = new InterceptorManager(testName, ENVIRONMENT.testMode)
namer = new StorageResourceNamer(testName, ENVIRONMENT.testMode, interceptorManager.getRecordedData())
System.out.printf("========================= %s =========================%n", testName)
}

def cleanup() {
Expand Down Expand Up @@ -75,19 +75,4 @@ class StorageSpec extends Specification {
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.azure.storage.common.test.shared.extensions

import org.spockframework.runtime.extension.AbstractGlobalExtension
import org.spockframework.runtime.extension.IMethodInterceptor
import org.spockframework.runtime.extension.IMethodInvocation
import org.spockframework.runtime.extension.MethodInvocation
import org.spockframework.runtime.model.FieldInfo
import org.spockframework.runtime.model.IterationInfo
import org.spockframework.runtime.model.SpecInfo

class TestHeaderExtension extends AbstractGlobalExtension {
@Override
void visitSpec(SpecInfo spec) {
spec.allFeatures*.addIterationInterceptor(new FeatureInterceptor());
spec.addInitializerInterceptor(new FeatureInterceptor());
}

static class FeatureInterceptor implements IMethodInterceptor {
@Override
void intercept(IMethodInvocation inv) {
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s =========================%n", getTestName(inv.getIteration()))
inv.proceed();
FieldInfo field = new FieldInfo();
inv
}

static String getTestName(IterationInfo iterationInfo) {
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import spock.lang.Unroll
import java.nio.ByteBuffer

class BufferStagingAreaTest extends Specification {
def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

static def generateData(int numBuffs, int minBuffSize, int maxBuffSize) {
def random = new Random()
// Generate random sizes between minBuffSize and maxBuffSize for the buffers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ import java.nio.ByteBuffer

class FluxInputStreamTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

/* Network tests to be performed by implementors of the FluxInputStream. */
Flux<ByteBuffer> generateData(int num) {
List<ByteBuffer> buffers = new ArrayList<>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import java.time.ZoneOffset

class SasModelsTest extends Specification {

def setup() {
String fullTestName = specificationContext.getCurrentIteration().getName().replace(' ', '').toLowerCase()
String className = specificationContext.getCurrentSpec().getName()
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
System.out.printf("========================= %s.%s =========================%n", className, fullTestName)
}

@Unroll
def "AccountSasSignatureValues min"() {
setup:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.azure.storage.common.test.shared.extensions.TestHeaderExtension
7 changes: 7 additions & 0 deletions sdk/storage/azure-storage-data-movement/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release History

## 12.0.0-beta.1 (Unreleased)

### Features included in `azure-storage-data-movement`
- This package supports functionality for storage data movement library.
- Reactive streams support using [Project Reactor](https://projectreactor.io/).
Empty file.
Loading