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

Commit 89003df

Browse files
committed
Change the way the default retention policy works and fix some tests.
* Made non-null retention policy represent an uploaded policy, like other settings. ** By default retention policy is null because it doesn't apply to all services. ** A new retention policy is disabled by default. * Fixed service property tests to handle no retention policy by default. ** These tests were already failing before this change; this fix was necessary either way. * Removed sleep in service property tests and removed the slow tag.
1 parent 41dccee commit 89003df

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import static org.junit.Assert.*;
3737

38-
@Category({ SlowTests.class, DevFabricTests.class, DevStoreTests.class, CloudTests.class })
38+
@Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class })
3939
public class ServicePropertiesTests {
4040

4141
/**
@@ -48,6 +48,7 @@ public class ServicePropertiesTests {
4848
public void testAnalyticsDisable() throws StorageException, InterruptedException {
4949
ServiceClient client = TestHelper.createCloudBlobClient();
5050
ServiceProperties props = new ServiceProperties();
51+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
5152
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
5253
testAnalyticsDisable(client, props);
5354

@@ -91,6 +92,7 @@ private void testAnalyticsDisable(ServiceClient client, ServiceProperties props)
9192
public void testAnalyticsDefaultServiceVersion() throws StorageException, InterruptedException {
9293
ServiceClient client = TestHelper.createCloudBlobClient();
9394
ServiceProperties props = new ServiceProperties();
95+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
9496
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
9597
testAnalyticsDefaultServiceVersion(client, props);
9698

@@ -151,6 +153,7 @@ private void testAnalyticsDefaultServiceVersion(ServiceClient client, ServicePro
151153
public void testAnalyticsLoggingOperations() throws StorageException, InterruptedException {
152154
ServiceClient client = TestHelper.createCloudBlobClient();
153155
ServiceProperties props = new ServiceProperties();
156+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
154157
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
155158
testAnalyticsLoggingOperations(client, props);
156159

@@ -191,6 +194,7 @@ private void testAnalyticsLoggingOperations(ServiceClient client, ServicePropert
191194
public void testAnalyticsHourMetricsLevel() throws StorageException, InterruptedException {
192195
ServiceClient client = TestHelper.createCloudBlobClient();
193196
ServiceProperties props = new ServiceProperties();
197+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
194198
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
195199
testAnalyticsHourMetricsLevel(client, props, null);
196200

@@ -259,6 +263,7 @@ private void testAnalyticsHourMetricsLevel(
259263
public void testAnalyticsMinuteMetricsLevel() throws StorageException, InterruptedException {
260264
ServiceClient client = TestHelper.createCloudBlobClient();
261265
ServiceProperties props = new ServiceProperties();
266+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
262267
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
263268
testAnalyticsMinuteMetricsLevel(client, props, null);
264269

@@ -327,6 +332,7 @@ private void testAnalyticsMinuteMetricsLevel(
327332
public void testAnalyticsRetentionPolicies() throws StorageException, InterruptedException {
328333
ServiceClient client = TestHelper.createCloudBlobClient();
329334
ServiceProperties props = new ServiceProperties();
335+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
330336
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
331337
testAnalyticsRetentionPolicies(client, props);
332338

@@ -426,6 +432,7 @@ private void testValidDeleteRetentionPolicy(ServiceClient client, boolean enable
426432

427433
try {
428434
ServiceProperties expectedServiceProperties = new ServiceProperties();
435+
expectedServiceProperties.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
429436
expectedServiceProperties.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
430437

431438
if (enabled) {
@@ -435,7 +442,7 @@ private void testValidDeleteRetentionPolicy(ServiceClient client, boolean enable
435442
} else {
436443
// interval and retained versions per blob would both be ignored by the service in case the policy is not enabled
437444
ServiceProperties propertiesToUpload = new ServiceProperties();
438-
propertiesToUpload.getDeleteRetentionPolicy().setEnabled(false);
445+
propertiesToUpload.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
439446
propertiesToUpload.getDeleteRetentionPolicy().setRetentionIntervalInDays(interval);
440447

441448
expectedServiceProperties.getDeleteRetentionPolicy().setEnabled(false);
@@ -448,7 +455,7 @@ private void testValidDeleteRetentionPolicy(ServiceClient client, boolean enable
448455
finally {
449456
// reset the delete retention policy
450457
ServiceProperties disabledDeleteRetentionPolicy = new ServiceProperties();
451-
disabledDeleteRetentionPolicy.getDeleteRetentionPolicy().setEnabled(false);
458+
disabledDeleteRetentionPolicy.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
452459
callUploadServiceProps(client, disabledDeleteRetentionPolicy, null);
453460
}
454461
}
@@ -483,6 +490,7 @@ private void testInvalidDeleteRetentionPolicy(ServiceClient client, boolean enab
483490

484491
// Arrange
485492
ServiceProperties serviceProperties = new ServiceProperties();
493+
serviceProperties.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
486494
serviceProperties.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
487495

488496
if (enabled) {
@@ -522,6 +530,7 @@ public void testEmptyDeleteRetentionPolicy() throws StorageException, Interrupte
522530
try {
523531
// set up initial delete retention policy
524532
ServiceProperties currentServiceProperties = new ServiceProperties();
533+
currentServiceProperties.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
525534
currentServiceProperties.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
526535
currentServiceProperties.getDeleteRetentionPolicy().setEnabled(true);
527536
currentServiceProperties.getDeleteRetentionPolicy().setRetentionIntervalInDays(5);
@@ -540,7 +549,7 @@ public void testEmptyDeleteRetentionPolicy() throws StorageException, Interrupte
540549
finally {
541550
// reset the delete retention policy
542551
ServiceProperties disabledDeleteRetentionPolicy = new ServiceProperties();
543-
disabledDeleteRetentionPolicy.getDeleteRetentionPolicy().setEnabled(false);
552+
disabledDeleteRetentionPolicy.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
544553
callUploadServiceProps(client, disabledDeleteRetentionPolicy, null);
545554
}
546555
}
@@ -555,6 +564,7 @@ public void testEmptyDeleteRetentionPolicy() throws StorageException, Interrupte
555564
public void testCloudValidCorsRules() throws StorageException, InterruptedException {
556565
ServiceClient client = TestHelper.createCloudBlobClient();
557566
ServiceProperties props = new ServiceProperties();
567+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
558568
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
559569
testCloudValidCorsRules(client, props, null);
560570

@@ -678,6 +688,7 @@ private void testCloudValidCorsRules(
678688
public void testCorsExpectedExceptions() throws StorageException {
679689
ServiceClient client = TestHelper.createCloudBlobClient();
680690
ServiceProperties props = new ServiceProperties();
691+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
681692
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
682693
testCorsExpectedExceptions(client, props, null);
683694

@@ -741,6 +752,7 @@ private void testCorsExpectedExceptions(
741752
public void testCorsMaxOrigins() throws StorageException, InterruptedException {
742753
ServiceClient client = TestHelper.createCloudBlobClient();
743754
ServiceProperties props = new ServiceProperties();
755+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
744756
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
745757
testCorsMaxOrigins(client, props, null);
746758

@@ -792,6 +804,7 @@ private void testCorsMaxOrigins(
792804
public void testCorsMaxHeaders() throws StorageException, InterruptedException {
793805
ServiceClient client = TestHelper.createCloudBlobClient();
794806
ServiceProperties props = new ServiceProperties();
807+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
795808
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
796809
testCorsMaxHeaders(client, props, null);
797810

@@ -895,6 +908,7 @@ private void testCorsMaxHeaders(
895908
public void testOptionalServiceProperties() throws StorageException, InterruptedException {
896909
ServiceClient client = TestHelper.createCloudBlobClient();
897910
ServiceProperties props = new ServiceProperties();
911+
props.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
898912
props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION);
899913
testOptionalServiceProperties(client, props);
900914

@@ -977,8 +991,9 @@ else if (client.getClass().equals(CloudFileClient.class)) {
977991
else {
978992
fail();
979993
}
980-
981-
Thread.sleep(30000);
994+
995+
// It may take up to 30 seconds for the settings to take effect, but the new properties are immediately
996+
// visible when querying service properties.
982997
}
983998

984999
private ServiceProperties callDownloadServiceProperties(ServiceClient client) throws StorageException {
@@ -1015,7 +1030,6 @@ private void testCorsRules(CorsRule rule, ServiceClient client, ServicePropertie
10151030
} else {
10161031
CloudFileClient fileClient = ((CloudFileClient) client);
10171032
fileClient.uploadServiceProperties(fileServiceProperties);
1018-
Thread.sleep(30000);
10191033
assertFileServicePropertiesAreEqual(fileServiceProperties, fileClient.downloadServiceProperties());
10201034
}
10211035
}
@@ -1039,7 +1053,6 @@ private void testCorsRules(List<CorsRule> corsRules, ServiceClient client, Servi
10391053
} else {
10401054
CloudFileClient fileClient = ((CloudFileClient) client);
10411055
fileClient.uploadServiceProperties(fileServiceProperties);
1042-
Thread.sleep(30000);
10431056
assertFileServicePropertiesAreEqual(fileServiceProperties, fileClient.downloadServiceProperties());
10441057
}
10451058
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public static class CoreTestSuite {
118118

119119
@RunWith(Suite.class)
120120
@SuiteClasses({ BlobOutputStreamTests.class, CloudBlobClientTests.class, CloudBlobContainerTests.class,
121-
CloudBlobDirectoryTests.class, CloudAppendBlobTests.class, CloudBlockBlobTests.class, CloudPageBlobTests.class,
122-
CloudBlobClientEncryptionTests.class, CloudBlobServerEncryptionTests.class, LeaseTests.class, SasTests.class,
123-
PremiumBlobTestSuite.class })
121+
CloudBlobDirectoryTests.class, CloudAppendBlobTests.class, CloudBlockBlobTests.class,
122+
CloudPageBlobTests.class, CloudBlobClientEncryptionTests.class, CloudBlobServerEncryptionTests.class,
123+
LeaseTests.class, SasTests.class })
124124
public static class BlobTestSuite {
125125
}
126126

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package com.microsoft.azure.storage.blob;
1616

17+
import com.microsoft.azure.storage.DeleteRetentionPolicy;
1718
import com.microsoft.azure.storage.OperationContext;
1819
import com.microsoft.azure.storage.StorageCredentials;
1920
import com.microsoft.azure.storage.StorageException;
@@ -440,6 +441,7 @@ public static void assertAreEqual(CopyState copy1, CopyState copy2) {
440441

441442
public static void enableSoftDelete() throws StorageException, URISyntaxException, InterruptedException {
442443
ServiceProperties serviceProperties = new ServiceProperties();
444+
serviceProperties.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
443445
serviceProperties.getDeleteRetentionPolicy().setEnabled(true);
444446
serviceProperties.getDeleteRetentionPolicy().setRetentionIntervalInDays(3);
445447

@@ -450,7 +452,7 @@ public static void enableSoftDelete() throws StorageException, URISyntaxExceptio
450452

451453
public static void disableSoftDelete() throws StorageException, URISyntaxException, InterruptedException {
452454
ServiceProperties serviceProperties = new ServiceProperties();
453-
serviceProperties.getDeleteRetentionPolicy().setEnabled(false);
455+
serviceProperties.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
454456

455457
CloudBlobClient bClient = TestHelper.createCloudBlobClient();
456458
bClient.uploadServiceProperties(serviceProperties);

microsoft-azure-storage/src/com/microsoft/azure/storage/DeleteRetentionPolicy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class DeleteRetentionPolicy {
2222
/**
2323
* Indicates whether a deleted blob or snapshot is retained or immediately removed by a delete operation.
2424
*/
25-
private Boolean enabled;
25+
private boolean enabled = false;
2626

2727
/**
2828
* Required only if Enabled is true. Indicates the number of days that deleted blobs are retained.
@@ -32,11 +32,11 @@ public class DeleteRetentionPolicy {
3232
private Integer retentionIntervalInDays;
3333

3434
/**
35-
* Return a Boolean indicating whether the DeleteRetentionPolicy is enabled.
35+
* Return a boolean indicating whether the DeleteRetentionPolicy is enabled.
3636
*
37-
* @return A <code>Boolean</code> indicating whether a deleted blob or snapshot is retained or immediately removed by a delete operation.
37+
* @return A <code>boolean</code> indicating whether a deleted blob or snapshot is retained or immediately removed by a delete operation.
3838
*/
39-
public Boolean getEnabled() {
39+
public boolean getEnabled() {
4040
return this.enabled;
4141
}
4242

@@ -50,7 +50,7 @@ public Integer getRetentionIntervalInDays() {
5050
}
5151

5252
/**
53-
* Set the Boolean indicating whether the DeleteRetentionPolicy is enabled.
53+
* Set a boolean indicating whether the DeleteRetentionPolicy is enabled.
5454
* @param enabled indicates whether the DeleteRetentionPolicy is enabled.
5555
*/
5656
public void setEnabled(boolean enabled) {

microsoft-azure-storage/src/com/microsoft/azure/storage/ServiceProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public ServiceProperties() {
5858
this.setHourMetrics(new MetricsProperties());
5959
this.setMinuteMetrics(new MetricsProperties());
6060
this.setCors(new CorsProperties());
61-
this.setDeleteRetentionPolicy(new DeleteRetentionPolicy());
6261
}
6362

6463
/**

microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesSerializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static byte[] serializeToByteArray(final ServiceProperties properties) th
7777
}
7878

7979
// Delete retention policy
80-
if (properties.getDeleteRetentionPolicy() != null && properties.getDeleteRetentionPolicy().getEnabled() != null) {
80+
if (properties.getDeleteRetentionPolicy() != null) {
8181
writeDeleteRetentionPolicy(xmlw, properties.getDeleteRetentionPolicy());
8282
}
8383

@@ -110,10 +110,10 @@ private static void writeDeleteRetentionPolicy(final XMLStreamWriter xmlw, final
110110

111111
// Enabled
112112
xmlw.writeStartElement(Constants.AnalyticsConstants.ENABLED_ELEMENT);
113-
xmlw.writeCharacters(deleteRetentionPolicy.getEnabled() != null && deleteRetentionPolicy.getEnabled() ? Constants.TRUE : Constants.FALSE);
113+
xmlw.writeCharacters(deleteRetentionPolicy.getEnabled() ? Constants.TRUE : Constants.FALSE);
114114
xmlw.writeEndElement();
115115

116-
if (deleteRetentionPolicy.getEnabled() != null && deleteRetentionPolicy.getEnabled()) {
116+
if (deleteRetentionPolicy.getEnabled()) {
117117
// Include retention days and retained versions per blob
118118
xmlw.writeStartElement(Constants.AnalyticsConstants.DAYS_ELEMENT);
119119
xmlw.writeCharacters(deleteRetentionPolicy.getRetentionIntervalInDays().toString());

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public void uploadServiceProperties(final ServiceProperties properties, BlobRequ
560560
options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.UNSPECIFIED, this);
561561

562562
Utility.assertNotNull("properties", properties);
563-
if (properties.getDeleteRetentionPolicy() != null && properties.getDeleteRetentionPolicy().getEnabled() != null
563+
if (properties.getDeleteRetentionPolicy() != null
564564
&& properties.getDeleteRetentionPolicy().getEnabled()) {
565565
Utility.assertNotNull("RetentionIntervalInDays", properties.getDeleteRetentionPolicy().getRetentionIntervalInDays());
566566
}

0 commit comments

Comments
 (0)