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 all 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
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
28 changes: 19 additions & 9 deletions sdk/storage/azure-storage-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<version>3.0.0</version> <!-- {x-version-update;org.codehaus.mojo:build-helper-maven-plugin;external_dependency} -->
<executions>
<execution>
<id>compile-samples-source</id>
<id>compile-test-shared-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
Expand All @@ -121,24 +121,34 @@

<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> <!-- {x-version-update;org.apache.maven.plugins:maven-assembly-plugin;external_dependency} -->
<executions>
<execution>
<id>test-jar</id>
<id>package-test-shared-jar</id>
<phase>test-compile</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>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${settings.localRepository}/com/azure/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}-tests.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>

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>${file.separator}</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>${file.separator}</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class StorageSpec extends Specification {
private StorageResourceNamer namer

def setup() {
def testName = getTestName()
def testName = TestNameProvider.getTestName(specificationContext.getCurrentIteration());
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 @@ -88,19 +87,4 @@ class StorageSpec extends Specification {
.map { it.getToken() }
.block()
}

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,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.common.test.shared;

import org.spockframework.runtime.model.FeatureInfo;
import org.spockframework.runtime.model.IterationInfo;
import org.spockframework.runtime.model.SpecInfo;

import java.util.Arrays;
import java.util.stream.Collectors;

public final class TestNameProvider {
public static String getTestName(IterationInfo iterationInfo) {
FeatureInfo featureInfo = iterationInfo.getFeature();
SpecInfo specInfo = featureInfo.getSpec();

String fullName = specInfo.getName() + Arrays.stream(featureInfo.getName().split(" "))
.map(it -> it.substring(0, 1).toUpperCase() + it.substring(1))
.collect(Collectors.joining(""));

return (iterationInfo.getDataValues().length == 0)
? fullName
: String.format("%s[%d]", fullName, iterationInfo.getIterationIndex());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.common.test.shared.extensions;

import com.azure.storage.common.test.shared.TestNameProvider;
import org.spockframework.runtime.extension.AbstractGlobalExtension;
import org.spockframework.runtime.extension.IMethodInterceptor;
import org.spockframework.runtime.extension.IMethodInvocation;
import org.spockframework.runtime.model.SpecInfo;

public final class TestHeaderExtension extends AbstractGlobalExtension {

@Override
public void visitSpec(SpecInfo specInfo) {
specInfo.getAllFeatures().forEach(feature ->
feature.addIterationInterceptor(new TestHeaderIterationInterceptor()));
}

private static class TestHeaderIterationInterceptor implements IMethodInterceptor {
@Override
public void intercept(IMethodInvocation invocation) {
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
String testName = TestNameProvider.getTestName(invocation.getIteration());
System.out.printf("========================= %s =========================%n", testName);
try {
invocation.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ import java.time.ZoneOffset

class DataLakeServiceSasModelsTest 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 "PathSASPermissions toString"() {
setup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import spock.lang.Unroll

class HelperTest 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 "File range"() {
expect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import java.nio.ByteBuffer

class AvroParserStateTest 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 "constructor"() {
setup:
AvroParserState state = new AvroParserState()
Expand Down
Loading