Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 2c63650

Browse files
author
jofriedm-msft
authored
Merge pull request #75 from jofriedm-msft/dev
Premium Page Blob Tiers
2 parents b0e4667 + 44be010 commit 2c63650

File tree

15 files changed

+946
-41
lines changed

15 files changed

+946
-41
lines changed

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2017.XX.XX Version X.X.X
22
* Added ErrorReceivingResponseEvent which fires when a network error occurs before the responseReceivedEvent fires. If the responseReceivedEvent fires sucessfully, this new event will not fire.
3+
* For Premium Accounts only, added support for getting and setting the tier on a page blob. The tier can also be set when creating or copying from an existing page blob.
34

45
2017.06.21 Version 5.3.1
56
* Fixed a bug in specific upload case for block blobs. This only affects uploads greater than the max put blob threshold, that have increased the streamWriteSizeInBytes beyond the 4 MB and storeBlobContentMD5 has been disabled.

microsoft-azure-storage-test/res/TestConfigurations.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<TestConfigurations>
22
<TargetTestTenant>ProductionTenant</TargetTestTenant>
3+
<TargetPremiumBlobTenant>ProductionTenant</TargetPremiumBlobTenant>
34
<TenantConfigurations>
45
<TenantConfiguration>
56
<TenantName>DevStore</TenantName>

microsoft-azure-storage-test/src/com/microsoft/azure/storage/TestHelper.java

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.microsoft.azure.storage;
1616

1717
import static org.junit.Assert.*;
18+
import static org.junit.Assume.assumeNotNull;
1819

1920
import java.io.ByteArrayInputStream;
2021
import java.io.File;
@@ -39,6 +40,7 @@
3940
import javax.xml.parsers.DocumentBuilderFactory;
4041
import javax.xml.parsers.ParserConfigurationException;
4142

43+
import org.junit.AssumptionViolatedException;
4244
import org.w3c.dom.DOMException;
4345
import org.w3c.dom.Document;
4446
import org.w3c.dom.Node;
@@ -58,6 +60,9 @@ public class TestHelper {
5860
private static Tenant tenant;
5961
private static StorageCredentialsAccountAndKey credentials;
6062
private static CloudStorageAccount account;
63+
private static Tenant premiumBlobTenant;
64+
private static StorageCredentialsAccountAndKey premiumBlobCredentials;
65+
private static CloudStorageAccount premiumBlobAccount;
6166

6267
private final static boolean enableFiddler = true;
6368
private final static boolean requireSecondaryEndpoint = false;
@@ -67,6 +72,11 @@ public static CloudBlobClient createCloudBlobClient() throws StorageException {
6772
return client;
6873
}
6974

75+
public static CloudBlobClient createPremiumCloudBlobClient() throws StorageException {
76+
CloudBlobClient client = getPremiumBlobAccount().createCloudBlobClient();
77+
return client;
78+
}
79+
7080
public static CloudBlobClient createCloudBlobClient(SharedAccessAccountPolicy policy, boolean useHttps)
7181
throws StorageException, InvalidKeyException, URISyntaxException {
7282

@@ -328,12 +338,12 @@ private static CloudStorageAccount getAccount() throws StorageException {
328338
account = CloudStorageAccount.parse(cloudAccount);
329339
}
330340
else if (accountConfig != null) {
331-
tenant = readTestConfigsFromXml(new File(accountConfig));
341+
readTestConfigsFromXml(new File(accountConfig), false);
332342
setAccountAndCredentials();
333343
}
334344
else {
335345
URL localTestConfig = TestHelper.class.getClassLoader().getResource("TestConfigurations.xml");
336-
tenant = readTestConfigsFromXml(new File(localTestConfig.getPath()));
346+
readTestConfigsFromXml(new File(localTestConfig.getPath()), false);
337347
setAccountAndCredentials();
338348
}
339349
}
@@ -344,6 +354,47 @@ else if (accountConfig != null) {
344354
return account;
345355
}
346356

357+
private static CloudStorageAccount getPremiumBlobAccount() throws StorageException {
358+
// Only do this the first time TestBase is called as storage account is static
359+
if (premiumBlobAccount == null) {
360+
//enable fiddler
361+
if (enableFiddler)
362+
enableFiddler();
363+
364+
// try to get the environment variable with the test configuration file path
365+
String accountConfig;
366+
try {
367+
accountConfig = System.getenv("storageTestConfiguration");
368+
}
369+
catch (SecurityException e) {
370+
accountConfig = null;
371+
}
372+
373+
// if storageConnection is set, use that as an account string
374+
// if storageTestConfiguration is set, use that as a path to the configurations file
375+
// if neither are set, use the local configurations file at TestConfigurations.xml
376+
try {
377+
if (accountConfig != null) {
378+
readTestConfigsFromXml(new File(accountConfig), true);
379+
setAccountAndCredentials();
380+
}
381+
else {
382+
URL localTestConfig = TestHelper.class.getClassLoader().getResource("TestConfigurations.xml");
383+
readTestConfigsFromXml(new File(localTestConfig.getPath()), true);
384+
setAccountAndCredentials();
385+
}
386+
}
387+
catch (AssumptionViolatedException e) {
388+
throw e;
389+
}
390+
catch (Exception e) {
391+
throw StorageException.translateClientException(e);
392+
}
393+
}
394+
395+
return premiumBlobAccount;
396+
}
397+
347398
private static void setAccountAndCredentials() {
348399
if (requireSecondaryEndpoint)
349400
tenant.assertSecondaryEndpoint();
@@ -353,9 +404,17 @@ private static void setAccountAndCredentials() {
353404
tenant.getQueueServiceSecondaryEndpoint()), new StorageUri(tenant.getTableServiceEndpoint(),
354405
tenant.getTableServiceSecondaryEndpoint()), new StorageUri(tenant.getFileServiceEndpoint(),
355406
tenant.getFileServiceSecondaryEndpoint()));
407+
408+
if (premiumBlobTenant != null) {
409+
premiumBlobCredentials = new StorageCredentialsAccountAndKey(premiumBlobTenant.getAccountName(), premiumBlobTenant.getAccountKey());
410+
premiumBlobAccount = new CloudStorageAccount(premiumBlobCredentials, new StorageUri(premiumBlobTenant.getBlobServiceEndpoint(), premiumBlobTenant.getBlobServiceSecondaryEndpoint()),
411+
null,
412+
null,
413+
null);
414+
}
356415
}
357416

358-
private static Tenant readTestConfigsFromXml(File testConfigurations) throws ParserConfigurationException,
417+
private static void readTestConfigsFromXml(File testConfigurations, boolean premiumBlob) throws ParserConfigurationException,
359418
SAXException, IOException, DOMException, URISyntaxException {
360419

361420
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -372,7 +431,14 @@ private static Tenant readTestConfigsFromXml(File testConfigurations) throws Par
372431
throw new IllegalArgumentException("No TargetTestTenant specified.");
373432
}
374433

375-
Tenant tenant = null;
434+
Node premiumBlobTenantNode = testConfigs.getElementsByTagName("TargetPremiumBlobTenant").item(0);
435+
String premiumBlobTenantName = null;
436+
if (premiumBlobTenantNode != null) {
437+
premiumBlobTenantName = premiumBlobTenantNode.getTextContent();
438+
}
439+
440+
tenant = null;
441+
premiumBlobTenant = null;
376442
final NodeList tenantNodes = testConfigs.getElementsByTagName("TenantName");
377443
for (int i = 0; i < tenantNodes.getLength(); i++) {
378444
if (tenantNodes.item(i).getTextContent().equals(targetTenant)) {
@@ -436,18 +502,50 @@ else if (name.equals("TableHttpsPortOverride")) {
436502
else if (name.equals("FileHttpsPortOverride")) {
437503
tenant.setFileHttpsPortOverride(Integer.parseInt(node.getTextContent()));
438504
}
439-
else {
505+
else if (!premiumBlob){
440506
throw new IllegalArgumentException(String.format(
441507
"Invalid child of TenantConfiguration with name: %s", name));
442508
}
443509
}
444510
}
445511
}
512+
513+
if (tenantNodes.item(i).getTextContent().equals(premiumBlobTenantName)) {
514+
premiumBlobTenant = new Tenant();
515+
Node parent = tenantNodes.item(i).getParentNode();
516+
final NodeList childNodes = parent.getChildNodes();
517+
for (int j = 0; j < childNodes.getLength(); j++) {
518+
final Node node = childNodes.item(j);
519+
520+
if (node.getNodeType() != Node.ELEMENT_NODE) {
521+
// do nothing
522+
} else {
523+
final String name = node.getNodeName();
524+
525+
if (name.equals("TenantName")) {
526+
premiumBlobTenant.setTenantName(node.getTextContent());
527+
} else if (name.equals("TenantType")) {
528+
// do nothing, we don't track this field
529+
} else if (name.equals("AccountName")) {
530+
premiumBlobTenant.setAccountName(node.getTextContent());
531+
} else if (name.equals("AccountKey")) {
532+
premiumBlobTenant.setAccountKey(node.getTextContent());
533+
} else if (name.equals("BlobServiceEndpoint")) {
534+
premiumBlobTenant.setBlobServiceEndpoint(new URI(node.getTextContent()));
535+
} else if (name.equals("BlobServiceSecondaryEndpoint")) {
536+
premiumBlobTenant.setBlobServiceSecondaryEndpoint(new URI(node.getTextContent()));
537+
}
538+
}
539+
}
540+
}
446541
}
447542

448-
if (tenant == null) {
543+
if (tenant == null && !premiumBlob) {
449544
throw new IllegalArgumentException("TargetTestTenant specified did not exist in TenantConfigurations.");
450545
}
451-
return tenant;
546+
547+
if (premiumBlobTenant == null && premiumBlob) {
548+
assumeNotNull(premiumBlobTenant);
549+
}
452550
}
453551
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/TestRunners.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public interface CloudTests {
105105
public interface DevFabricTests {
106106
}
107107

108+
public interface PremiumBlobTests {
109+
}
110+
108111
// Test suites
109112
@RunWith(Suite.class)
110113
@SuiteClasses({ AccountSasTests.class, EventFiringTests.class, GenericTests.class, LoggerTests.class,
@@ -116,7 +119,8 @@ public static class CoreTestSuite {
116119
@RunWith(Suite.class)
117120
@SuiteClasses({ BlobOutputStreamTests.class, CloudBlobClientTests.class, CloudBlobContainerTests.class,
118121
CloudBlobDirectoryTests.class, CloudAppendBlobTests.class, CloudBlockBlobTests.class, CloudPageBlobTests.class,
119-
CloudBlobClientEncryptionTests.class, CloudBlobServerEncryptionTests.class, LeaseTests.class, SasTests.class })
122+
CloudBlobClientEncryptionTests.class, CloudBlobServerEncryptionTests.class, LeaseTests.class, SasTests.class,
123+
PremiumBlobTests.class })
120124
public static class BlobTestSuite {
121125
}
122126

@@ -177,4 +181,9 @@ public static class DevFabricNoSecondarySuite {
177181
@SuiteClasses(AllTestSuite.class)
178182
public static class FastTestSuite {
179183
}
184+
185+
@RunWith(Categories.class)
186+
@IncludeCategory(PremiumBlobTests.class)
187+
public static class PremiumBlobTestSuite {
188+
}
180189
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/BlobTestHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public static CloudBlobContainer getRandomContainerReference() throws URISyntaxE
5050
return container;
5151
}
5252

53+
public static CloudBlobContainer getRandomPremiumBlobContainerReference() throws URISyntaxException, StorageException {
54+
String containerName = generateRandomContainerName();
55+
CloudBlobClient bClient = TestHelper.createPremiumCloudBlobClient();
56+
CloudBlobContainer container = bClient.getContainerReference(containerName);
57+
58+
return container;
59+
}
60+
5361
public static String generateRandomBlobNameWithPrefix(String prefix) {
5462
if (prefix == null) {
5563
prefix = "";

0 commit comments

Comments
 (0)