Skip to content

Commit 2f43352

Browse files
committed
Added versions to canonicalized query params and updated unit tests
1 parent 8f5df5f commit 2f43352

File tree

5 files changed

+48
-54
lines changed

5 files changed

+48
-54
lines changed

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/VersionedObject_Test.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
package com.spectralogic.ds3client.integration;
1717

1818
import com.spectralogic.ds3client.Ds3Client;
19+
import com.spectralogic.ds3client.commands.GetBucketRequest;
20+
import com.spectralogic.ds3client.commands.GetBucketResponse;
21+
import com.spectralogic.ds3client.commands.spectrads3.GetBulkJobSpectraS3Request;
1922
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
2023
import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds;
2124
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
2225
import com.spectralogic.ds3client.models.ChecksumType;
2326
import com.spectralogic.ds3client.models.VersioningLevel;
27+
import com.spectralogic.ds3client.models.bulk.Ds3Object;
2428
import org.junit.AfterClass;
2529
import org.junit.BeforeClass;
2630
import org.junit.Test;
@@ -29,9 +33,13 @@
2933

3034
import java.io.IOException;
3135
import java.net.URISyntaxException;
36+
import java.util.List;
3237
import java.util.UUID;
38+
import java.util.stream.Collectors;
3339

3440
import static com.spectralogic.ds3client.integration.Util.*;
41+
import static org.hamcrest.Matchers.is;
42+
import static org.junit.Assert.assertThat;
3543

3644
public class VersionedObject_Test {
3745

@@ -40,7 +48,6 @@ public class VersionedObject_Test {
4048
private static final Ds3Client CLIENT = Util.fromEnv();
4149
private static final Ds3ClientHelpers HELPERS = Ds3ClientHelpers.wrap(CLIENT);
4250
private static final String TEST_ENV_NAME = "java_versioned_object_test";
43-
private static final int RETRIES = 5;
4451

4552
private static TempStorageIds envStorageIds;
4653
private static UUID envDataPolicyId;
@@ -79,10 +86,20 @@ public void getObjectsWithVersioning() throws IOException, URISyntaxException {
7986
loadTestBook(CLIENT, BOOKS[0], objectName, TEST_ENV_NAME); // putting beowulf as content
8087
loadTestBook(CLIENT, BOOKS[1], objectName, TEST_ENV_NAME); // putting sherlock holmes as content
8188

82-
// TODO Get the version of the objects
89+
// Get the version of the objects
90+
final GetBucketRequest getBucketRequest = new GetBucketRequest(TEST_ENV_NAME).withVersions(true);
91+
final GetBucketResponse getBucketResponse = CLIENT.getBucket(getBucketRequest);
8392

84-
// TODO Create bulk get job with both versions of object specified
93+
assertThat(getBucketResponse.getListBucketResult().getObjects().size(), is(0));
94+
assertThat(getBucketResponse.getListBucketResult().getVersionedObjects().size(), is(2));
8595

96+
// Create bulk get job with both versions of object specified
97+
final List<Ds3Object> objects = getBucketResponse.getListBucketResult().getVersionedObjects().stream()
98+
.map(obj -> new Ds3Object(obj.getKey(), obj.getVersionId()))
99+
.collect(Collectors.toList());
100+
101+
final GetBulkJobSpectraS3Request getBulkRequest = new GetBulkJobSpectraS3Request(TEST_ENV_NAME, objects);
102+
CLIENT.getBulkJobSpectraS3(getBulkRequest);
86103

87104
} finally {
88105
cancelAllJobsForBucket(CLIENT, TEST_ENV_NAME);

ds3-sdk/src/main/java/com/spectralogic/ds3client/models/bulk/Ds3Object.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,6 @@ public Ds3Object() {
4141
//This constructor is used just for serialization.
4242
}
4343

44-
/**
45-
* Use this constructor when getting a version of a file from DS3.
46-
* @param name The name of the object to get from DS3
47-
* @param size The size of the object to get from DS3
48-
* @param versionId The version ID of the object to get from DS3
49-
*/
50-
public Ds3Object(final String name, final long size, final UUID versionId) {
51-
this.name = name;
52-
this.size = size;
53-
this.versionId = versionId.toString();
54-
}
55-
56-
/**
57-
* Use this constructor when getting a version of a file from DS3.
58-
* @param name The name of the object to get from DS3
59-
* @param size The size of the object to get from DS3
60-
* @param versionId The version ID of the object to get from DS3
61-
*/
62-
public Ds3Object(final String name, final long size, final String versionId) {
63-
this.name = name;
64-
this.size = size;
65-
this.versionId = versionId;
66-
}
67-
6844
/**
6945
* Use this constructor when putting files to DS3.
7046
* @param name The name of the object that will be put to DS3
@@ -124,14 +100,22 @@ public void setSize(final long size) {
124100
this.size = size;
125101
}
126102

103+
public String getVersionId() {
104+
return versionId;
105+
}
106+
107+
public void setVersionId(String versionId) {
108+
this.versionId = versionId;
109+
}
110+
127111
@Override
128112
public String toString() {
129113
return this.name + ":" + this.size;
130114
}
131115

132116
@Override
133117
public int hashCode() {
134-
return java.util.Objects.hash(this.name, this.size);
118+
return java.util.Objects.hash(this.name, this.size, this.versionId);
135119
}
136120

137121
@Override
@@ -144,12 +128,4 @@ public boolean equals(final Object obj) {
144128
ds3Obj.getSize() == this.getSize() &&
145129
ds3Obj.getVersionId().equals(this.getVersionId());
146130
}
147-
148-
public String getVersionId() {
149-
return versionId;
150-
}
151-
152-
public void setVersionId(String versionId) {
153-
this.versionId = versionId;
154-
}
155131
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/utils/Signature.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,18 @@ public static String canonicalizeResource(final String path, final Map<String, S
9191
canonicalizedResource.append(path);
9292

9393
if (queryParams != null) {
94+
// canonicalize resources in alphabetical order
9495
if (queryParams.containsKey("delete")) {
9596
canonicalizedResource.append("?delete");
9697
}
98+
if (queryParams.containsKey("uploads")) {
99+
canonicalizedResource.append("?uploads");
100+
}
97101
if (queryParams.containsKey("versioning")) {
98102
canonicalizedResource.append("?versioning=").append(queryParams.get("versioning"));
99103
}
100-
if (queryParams.containsKey("uploads")) {
101-
canonicalizedResource.append("?uploads");
104+
if (queryParams.containsKey("versions")) {
105+
canonicalizedResource.append("?versions");
102106
}
103107
}
104108
return canonicalizedResource.toString();

ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ public void getPhysicalPlacementForObjectsWithFullDetailsTest() throws IOExcepti
14251425

14261426
@Test
14271427
public void verifyPhysicalPlacementForObjectsTest() throws IOException {
1428-
final String responsePayload = "<Data><AzureTargets/><Ds3Targets/><Pools/><S3Targets/><Tapes><Tape><AssignedToStorageDomain>false</AssignedToStorageDomain><AvailableRawCapacity>10000</AvailableRawCapacity><BarCode>t1</BarCode><BucketId/><DescriptionForIdentification/><EjectDate/><EjectLabel/><EjectLocation/><EjectPending/><FullOfData>false</FullOfData><Id>48d30ecb-84f1-4721-9832-7aa165a1dd77</Id><LastAccessed/><LastCheckpoint/><LastModified/><LastVerified/><PartiallyVerifiedEndOfTape/><PartitionId>76343269-c32a-4cb0-aec4-57a9dccce6ea</PartitionId><PreviousState/><SerialNumber/><State>INSPECTION_PENDING</State><TakeOwnershipPending>false</TakeOwnershipPending><TotalRawCapacity>20000</TotalRawCapacity><Type>LTO5</Type><VerifyPending/><WriteProtected>false</WriteProtected></Tape></Tapes></Data>";
1428+
final String responsePayload = "<Data><AzureTargets/><Ds3Targets/><Pools/><S3Targets/><Tapes><Tape><AssignedToStorageDomain>false</AssignedToStorageDomain><AvailableRawCapacity>10000</AvailableRawCapacity><BarCode>t1</BarCode><BucketId/><DescriptionForIdentification/><EjectDate/><EjectLabel/><EjectLocation/><EjectPending/><FullOfData>false</FullOfData><Id>48d30ecb-84f1-4721-9832-7aa165a1dd77</Id><LastAccessed/><LastCheckpoint/><LastModified/><LastVerified/><PartiallyVerifiedEndOfTape/><PartitionId>76343269-c32a-4cb0-aec4-57a9dccce6ea</PartitionId><PreviousState/><SerialNumber/><State>PENDING_INSPECTION</State><TakeOwnershipPending>false</TakeOwnershipPending><TotalRawCapacity>20000</TotalRawCapacity><Type>LTO5</Type><VerifyPending/><WriteProtected>false</WriteProtected></Tape></Tapes></Data>";
14291429
final String bucketName = "BucketName";
14301430

14311431
final Map<String, String> queryParams = new HashMap<>();
@@ -1445,7 +1445,7 @@ public void verifyPhysicalPlacementForObjectsTest() throws IOException {
14451445

14461446
@Test
14471447
public void verifyPhysicalPlacementForObjectsWithFullDetailsTest() throws IOException {
1448-
final String responsePayload = "<Data><Object Bucket=\"b1\" Id=\"15ad85a5-aab6-4d85-bf33-831bcba13b8e\" InCache=\"false\" Latest=\"true\" Length=\"10\" Name=\"o1\" Offset=\"0\" Version=\"1\"><PhysicalPlacement><AzureTargets/><Ds3Targets/><Pools/><S3Targets/><Tapes><Tape><AssignedToStorageDomain>false</AssignedToStorageDomain><AvailableRawCapacity>10000</AvailableRawCapacity><BarCode>t1</BarCode><BucketId/><DescriptionForIdentification/><EjectDate/><EjectLabel/><EjectLocation/><EjectPending/><FullOfData>false</FullOfData><Id>5a7bb215-4aff-4806-b217-5fe01ade6a2c</Id><LastAccessed/><LastCheckpoint/><LastModified/><LastVerified/><PartiallyVerifiedEndOfTape/><PartitionId>2e5b25fc-546e-45b0-951e-8f3d80bb7823</PartitionId><PreviousState/><SerialNumber/><State>INSPECTION_PENDING</State><TakeOwnershipPending>false</TakeOwnershipPending><TotalRawCapacity>20000</TotalRawCapacity><Type>LTO5</Type><VerifyPending/><WriteProtected>false</WriteProtected></Tape></Tapes></PhysicalPlacement></Object></Data>";
1448+
final String responsePayload = "<Data><Object Bucket=\"b1\" Id=\"15ad85a5-aab6-4d85-bf33-831bcba13b8e\" InCache=\"false\" Latest=\"true\" Length=\"10\" Name=\"o1\" Offset=\"0\" Version=\"1\"><PhysicalPlacement><AzureTargets/><Ds3Targets/><Pools/><S3Targets/><Tapes><Tape><AssignedToStorageDomain>false</AssignedToStorageDomain><AvailableRawCapacity>10000</AvailableRawCapacity><BarCode>t1</BarCode><BucketId/><DescriptionForIdentification/><EjectDate/><EjectLabel/><EjectLocation/><EjectPending/><FullOfData>false</FullOfData><Id>5a7bb215-4aff-4806-b217-5fe01ade6a2c</Id><LastAccessed/><LastCheckpoint/><LastModified/><LastVerified/><PartiallyVerifiedEndOfTape/><PartitionId>2e5b25fc-546e-45b0-951e-8f3d80bb7823</PartitionId><PreviousState/><SerialNumber/><State>PENDING_INSPECTION</State><TakeOwnershipPending>false</TakeOwnershipPending><TotalRawCapacity>20000</TotalRawCapacity><Type>LTO5</Type><VerifyPending/><WriteProtected>false</WriteProtected></Tape></Tapes></PhysicalPlacement></Object></Data>";
14491449
final String bucketName = "BucketName";
14501450

14511451
final Map<String, String> queryParams = new HashMap<>();
@@ -1470,7 +1470,7 @@ public void ejectStorageDomainBlobsTest() throws IOException {
14701470
queryParams.put("operation", "eject");
14711471
queryParams.put("blobs", null);
14721472
queryParams.put("bucket_id", bucketId);
1473-
queryParams.put("storage_domain_id", storageDomainId);
1473+
queryParams.put("storage_domain", storageDomainId);
14741474

14751475
MockNetwork
14761476
.expecting(HttpVerb.PUT, "/_rest_/tape", queryParams, SIMPLE_OBJECT_REQUEST_PAYLOAD)
@@ -1535,11 +1535,18 @@ public void getBlobsOnTapeTest() throws IOException {
15351535
final Map<String, String> queryParams = new HashMap<>();
15361536
queryParams.put("operation", "get_physical_placement");
15371537

1538-
MockNetwork
1538+
final Map<String, String> responseHeaders = new HashMap<>();
1539+
responseHeaders.put("page-truncated", "0");
1540+
responseHeaders.put("total-result-count", "2");
1541+
1542+
final GetBlobsOnTapeSpectraS3Response result = MockNetwork
15391543
.expecting(HttpVerb.GET, "/_rest_/tape/" + target, queryParams, null)
1540-
.returning(200, SIMPLE_BULK_OBJECT_LIST_RESPONSE)
1544+
.returning(200, SIMPLE_BULK_OBJECT_LIST_RESPONSE, responseHeaders)
15411545
.asClient()
15421546
.getBlobsOnTapeSpectraS3(new GetBlobsOnTapeSpectraS3Request(target));
1547+
1548+
assertThat(result.getPagingTruncated(), is(0));
1549+
assertThat(result.getPagingTotalResultCount(), is(2));
15431550
}
15441551

15451552
@Test

ds3-sdk/src/test/java/com/spectralogic/ds3client/serializer/XmlOutput_Test.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,10 @@ public void toXmlWithNoSize() {
9292
assertThat(result, is(expectedString));
9393
}
9494

95-
@Test
96-
public void toXmlWithNoVersionId() {
97-
final String expectedString = "<Objects><Object Name=\"file1\" Size=\"12\"/><Object Name=\"file2\" Size=\"5022\"/></Objects>";
98-
final List<Ds3Object> objectList = ImmutableList.of(new Ds3Object("file1", 12, "version1"), new Ds3Object("file2", 5022, "version2")).asList();
99-
final Ds3ObjectList ds3ObjectList = new Ds3ObjectList(objectList);
100-
final String result = XmlOutput.toXml(ds3ObjectList, true);
101-
102-
assertThat(result, is(expectedString));
103-
}
104-
10595
@Test
10696
public void toXmlWithVersionId() {
10797
final String expectedString = "<Objects><Object Name=\"file1\" VersionId=\"version1\"/><Object Name=\"file2\" VersionId=\"version2\"/></Objects>";
108-
final List<Ds3Object> objectList = ImmutableList.of(new Ds3Object("file1", 12, "version1"), new Ds3Object("file2", 5022, "version2")).asList();
98+
final List<Ds3Object> objectList = ImmutableList.of(new Ds3Object("file1", "version1"), new Ds3Object("file2", "version2")).asList();
10999
final Ds3ObjectList ds3ObjectList = new Ds3ObjectList(objectList);
110100
final String result = XmlOutput.toXml(ds3ObjectList, false);
111101

0 commit comments

Comments
 (0)