Skip to content

Commit

Permalink
Merge pull request Azure#8 from alzimmermsft/AzStorage_Blobs_Tests
Browse files Browse the repository at this point in the history
Reenabled and Cleaned Up Storage Blob Tests
  • Loading branch information
jianghaolu authored Jun 21, 2019
2 parents 98119a5 + 3a1625d commit 3bcd1de
Show file tree
Hide file tree
Showing 5 changed files with 1,008 additions and 932 deletions.
47 changes: 32 additions & 15 deletions storage/client/src/test/java/com/azure/storage/blob/APISpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,18 @@ class APISpec extends Specification {
}
}

static byte[] getRandomByteArray(int size) {
Random rand = new Random(getRandomSeed())
byte[] data = new byte[size]
rand.nextBytes(data)
return data
}

/*
Size must be an int because ByteBuffer sizes can only be an int. Long is not supported.
*/
static ByteBuffer getRandomData(int size) {
Random rand = new Random(getRandomSeed())
byte[] data = new byte[size]
rand.nextBytes(data)
return ByteBuffer.wrap(data)
return ByteBuffer.wrap(getRandomByteArray(size))
}

/*
Expand Down Expand Up @@ -385,17 +389,17 @@ class APISpec extends Specification {
return request
}

// def waitForCopy(ContainerClient bu, CopyStatusType status) {
// OffsetDateTime start = OffsetDateTime.now()
// while (status != CopyStatusType.SUCCESS) {
// status = bu.getProperties().
// OffsetDateTime currentTime = OffsetDateTime.now()
// if (status == CopyStatusType.FAILED || currentTime.minusMinutes(1) == start) {
// throw new Exception("Copy failed or took too long")
// }
// sleep(1000)
// }
// }
def waitForCopy(ContainerClient bu, String status) {
OffsetDateTime start = OffsetDateTime.now()
while (status != CopyStatusType.SUCCESS.toString()) {
status = bu.getProperties().headers().value("x-ms-copy-status")
OffsetDateTime currentTime = OffsetDateTime.now()
if (status == CopyStatusType.FAILED.toString() || currentTime.minusMinutes(1) == start) {
throw new Exception("Copy failed or took too long")
}
sleep(1000)
}
}

/**
* Validates the presence of headers that are present on a large number of responses. These headers are generally
Expand Down Expand Up @@ -426,6 +430,19 @@ class APISpec extends Specification {

}

static Metadata getMetadataFromHeaders(HttpHeaders headers) {
Metadata metadata = new Metadata()

for (Map.Entry<String, String> header : headers.toMap()) {
if (header.getKey().startsWith("x-ms-meta-")) {
String metadataKey = header.getKey().substring(10)
metadata.put(metadataKey, header.getValue())
}
}

return metadata
}

def enableSoftDelete() {
primaryServiceURL.setProperties(new StorageServiceProperties()
.deleteRetentionPolicy(new RetentionPolicy().enabled(true).days(2)))
Expand Down
Loading

0 comments on commit 3bcd1de

Please sign in to comment.