Skip to content

Commit

Permalink
[Storage] Tests - Live and playback only annotations. (#21264)
Browse files Browse the repository at this point in the history
* Live and playback only annotations.

* missing pieces.

* checkstyle.

* compiler.
  • Loading branch information
kasobol-msft authored May 10, 2021
1 parent 76cc1f6 commit 317887a
Show file tree
Hide file tree
Showing 39 changed files with 301 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<!-- Don't apply custom Checkstyle rules to files under test package -->
<suppress
checks="com\.azure\.tools\.checkstyle\.checks\.(ExternalDependencyExposedCheck|NoImplInPublicAPI|ServiceClientCheck|ServiceClientBuilderCheck|ServiceInterfaceCheck|HttpPipelinePolicyCheck|JavaDocFormatting|JavadocThrowsChecks|EnforceFinalFieldsCheck|ThrowFromClientLoggerCheck|GoodLoggingCheck)"
files=".*[/\\]src[/\\]test[/\\]java[/\\].*\.java"/>
files=".*[/\\]src[/\\]test(-shared)?[/\\]java[/\\].*\.java"/>

<!-- Do not worry about leaking implementation API out of azure-core-test -->
<suppress checks="com.azure.tools.checkstyle.checks.NoImplInPublicAPI" files="com.azure.core.test.*"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ import com.azure.storage.blob.specialized.BlobLeaseClientBuilder
import com.azure.storage.common.StorageSharedKeyCredential
import com.azure.storage.common.test.shared.StorageSpec
import com.azure.storage.common.test.shared.TestAccount
import org.spockframework.runtime.model.IterationInfo
import spock.lang.Requires
import spock.lang.Shared

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.time.OffsetDateTime
import java.util.function.Supplier

class APISpec extends StorageSpec {
@Shared
ClientLogger logger = new ClientLogger(APISpec.class)

Integer entityNo = 0 // Used to generate stable container names for recording tests requiring multiple containers.

Expand All @@ -61,12 +56,7 @@ class APISpec extends StorageSpec {
BlobServiceAsyncClient primaryBlobServiceAsyncClient
BlobServiceClient versionedBlobServiceClient

private boolean recordLiveMode

def setup() {
// If the test doesn't have the Requires tag record it in live mode.
recordLiveMode = specificationContext.getCurrentFeature().getFeatureMethod().getAnnotation(Requires.class) == null

primaryBlobServiceClient = setClient(env.primaryAccount)
primaryBlobServiceAsyncClient = getServiceAsyncClient(env.primaryAccount)
versionedBlobServiceClient = setClient(env.versionedAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ import java.util.concurrent.TimeUnit
@Timeout(value = 5, unit = TimeUnit.MINUTES)
class APISpec extends StorageSpec {

@Shared
ClientLogger logger = new ClientLogger(APISpec.class)

Integer entityNo = 0 // Used to generate stable container names for recording tests requiring multiple containers.

BlobServiceClient primaryBlobServiceClient
BlobServiceAsyncClient primaryBlobServiceAsyncClient

boolean recordLiveMode
String containerName

def setupSpec() {
Expand All @@ -56,9 +52,6 @@ class APISpec extends StorageSpec {
}

def setup() {
// If the test doesn't have the Requires tag record it in live mode.
recordLiveMode = specificationContext.getCurrentFeature().getFeatureMethod().getAnnotation(Requires.class) != null

primaryBlobServiceClient = setClient(env.primaryAccount)
primaryBlobServiceAsyncClient = getServiceAsyncClient(env.primaryAccount)

Expand All @@ -78,10 +71,6 @@ class APISpec extends StorageSpec {
}
}

static boolean playbackMode() {
return env.testMode == TestMode.PLAYBACK
}

def generateContainerName() {
generateResourceName(entityNo++)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.azure.core.test.TestMode
import com.azure.core.util.logging.ClientLogger
import com.azure.storage.blob.changefeed.implementation.models.ChangefeedCursor
import com.azure.storage.blob.changefeed.models.BlobChangefeedEvent
import com.azure.storage.common.test.shared.extensions.PlaybackOnly
import spock.lang.Ignore
import reactor.test.StepVerifier
import spock.lang.Requires
Expand Down Expand Up @@ -34,7 +35,7 @@ class ChangefeedNetworkTest extends APISpec {
.verifyComplete()
}

@Requires( { playbackMode() })
@PlaybackOnly
def "historical"() {
setup:
/* Uncomment when recording. */
Expand All @@ -56,7 +57,7 @@ class ChangefeedNetworkTest extends APISpec {
.verifyComplete()
}

@Requires( { playbackMode() })
@PlaybackOnly
def "last hour"() {
setup:
/* Uncomment when recording. */
Expand All @@ -81,7 +82,7 @@ class ChangefeedNetworkTest extends APISpec {
* To setup recording have an account where changes are generated quite frequently (i.e. every 1 minute).
* This test runs long in recording mode as it waits multiple times for events.
*/
@Requires( { playbackMode() })
@PlaybackOnly
def "tail events"() {
setup:
/* Uncomment when recording. */
Expand Down Expand Up @@ -146,7 +147,7 @@ class ChangefeedNetworkTest extends APISpec {
eventIds2.intersect(eventIds3).size() == 0
}

@Requires( { playbackMode() })
@PlaybackOnly
def "page size"() {
setup:
int pageSize1 = 50
Expand Down Expand Up @@ -200,7 +201,7 @@ class ChangefeedNetworkTest extends APISpec {

}

@Requires( { playbackMode() })
@PlaybackOnly
def "resume from the middle of a chunk"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand Down Expand Up @@ -292,7 +293,7 @@ class ChangefeedNetworkTest extends APISpec {
* However. Some shards should be empty. Easiest way to set this up is to have just one blob and keep modifying it.
* Changes related to same blobName are guaranteed to end up in same shard.
*/
@Requires( { playbackMode() })
@PlaybackOnly
def "resume from the middle of a chunk with some empty shards"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand Down Expand Up @@ -389,7 +390,7 @@ class ChangefeedNetworkTest extends APISpec {
* However. Some shards should be empty. Easiest way to set this up is to have just one blob and keep modifying it.
* Changes related to same blobName are guaranteed to end up in same shard.
*/
@Requires( { playbackMode() })
@PlaybackOnly
def "resume from the middle of a chunk with many non-empty shards"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand Down Expand Up @@ -483,7 +484,7 @@ class ChangefeedNetworkTest extends APISpec {
allEventIds == unionIds
}

@Requires( { playbackMode() })
@PlaybackOnly
def "resume from historical yields no events"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand Down Expand Up @@ -513,7 +514,7 @@ class ChangefeedNetworkTest extends APISpec {
eventIds1.size() > 0
}

@Requires( { playbackMode() })
@PlaybackOnly
def "immediate resume from last hour yields no events"() {
/* Uncomment when recording. */
// OffsetDateTime startTime = OffsetDateTime.now()
Expand Down Expand Up @@ -551,7 +552,7 @@ class ChangefeedNetworkTest extends APISpec {
* To setup account for this test have a steady stream of events (i.e. some changes every 1 minute) that covers at least from an hour before start time
* to an hour after end time.
*/
@Requires( { playbackMode() })
@PlaybackOnly
def "already rounded boundaries"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand All @@ -577,7 +578,7 @@ class ChangefeedNetworkTest extends APISpec {
* To setup account for this test have a steady stream of events (i.e. some changes every 1 minute) that covers at least from an hour before start time
* to an hour after end time.
*/
@Requires( { playbackMode() })
@PlaybackOnly
def "non rounded boundaries"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand All @@ -601,7 +602,7 @@ class ChangefeedNetworkTest extends APISpec {
!events.any { event -> event.getEventTime().isAfter(roundedEndTime.plusMinutes(15)) } /* There is no event 15 minutes after end */
}

@Requires( { playbackMode() })
@PlaybackOnly
def "cursor format"() {
setup:
/* Hardcoded for playback stability. If modifying, make sure to re-record. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ class APISpec extends StorageSpec {

static final String garbageLeaseID = UUID.randomUUID().toString()

@Shared
ClientLogger logger = new ClientLogger(APISpec.class)

private boolean recordLiveMode

// Fields used for conveniently creating blobs with data.
static final String defaultText = "default"

Expand All @@ -88,15 +83,6 @@ class APISpec extends StorageSpec {
@Shared
protected KB = 1024

def setup() {
// If the test doesn't have the Requires tag record it in live mode.
recordLiveMode = specificationContext.getCurrentFeature().getFeatureMethod().getAnnotation(Requires.class) == null
}

static boolean liveMode() {
return env.testMode == TestMode.LIVE
}

/*
Size must be an int because ByteBuffer sizes can only be an int. Long is not supported.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.azure.storage.blob.BlobContainerClient
import com.azure.storage.blob.models.BlobErrorCode
import com.azure.storage.blob.models.BlobStorageException
import com.azure.storage.common.implementation.Constants
import com.azure.storage.common.test.shared.extensions.LiveOnly
import spock.lang.Requires
import spock.lang.Shared

Expand Down Expand Up @@ -41,7 +42,7 @@ class EncryptedBlobOutputStreamTest extends APISpec {
.buildEncryptedBlobClient()
}

@Requires({ liveMode() })
@LiveOnly
def "Encrypted blob output stream not a no op"() {
setup:
def data = getRandomByteArray(10 * Constants.MB)
Expand All @@ -58,7 +59,7 @@ class EncryptedBlobOutputStreamTest extends APISpec {
os.toByteArray() != data
}

@Requires({ liveMode() })
@LiveOnly
def "Encrypted blob output stream"() {
setup:
def data = getRandomByteArray(10 * Constants.MB)
Expand All @@ -72,7 +73,7 @@ class EncryptedBlobOutputStreamTest extends APISpec {
convertInputStreamToByteArray(bec.openInputStream()) == data
}

@Requires({ liveMode() })
@LiveOnly
def "Encrypted blob output stream default no overwrite"() {
setup:
def data = getRandomByteArray(10 * Constants.MB)
Expand All @@ -89,7 +90,7 @@ class EncryptedBlobOutputStreamTest extends APISpec {
thrown(IllegalArgumentException)
}

@Requires({ liveMode() })
@LiveOnly
def "Encrypted blob output stream default no overwrite interrupted"() {
setup:
def data = getRandomByteArray(10 * Constants.MB)
Expand All @@ -110,7 +111,7 @@ class EncryptedBlobOutputStreamTest extends APISpec {
((BlobStorageException) e.getCause()).getErrorCode() == BlobErrorCode.BLOB_ALREADY_EXISTS
}

@Requires({ liveMode() })
@LiveOnly
def "Encrypted blob output stream overwrite"() {
setup:
def data = getRandomByteArray(10 * Constants.MB)
Expand Down
Loading

0 comments on commit 317887a

Please sign in to comment.