|
22 | 22 | import com.spectralogic.ds3client.commands.spectrads3.GetBulkJobSpectraS3Request; |
23 | 23 | import com.spectralogic.ds3client.commands.spectrads3.StageObjectsJobSpectraS3Request; |
24 | 24 | import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
| 25 | +import com.spectralogic.ds3client.helpers.FileObjectGetter; |
25 | 26 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds; |
26 | 27 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil; |
27 | 28 | import com.spectralogic.ds3client.models.ChecksumType; |
28 | 29 | import com.spectralogic.ds3client.models.VersioningLevel; |
29 | 30 | import com.spectralogic.ds3client.models.bulk.Ds3Object; |
| 31 | +import com.spectralogic.ds3client.utils.ResourceUtils; |
| 32 | +import org.apache.commons.io.FileUtils; |
30 | 33 | import org.junit.AfterClass; |
31 | 34 | import org.junit.BeforeClass; |
32 | 35 | import org.junit.Test; |
33 | 36 | import org.slf4j.Logger; |
34 | 37 | import org.slf4j.LoggerFactory; |
35 | 38 |
|
| 39 | +import java.io.File; |
36 | 40 | import java.io.IOException; |
37 | 41 | import java.net.URISyntaxException; |
| 42 | +import java.nio.file.Files; |
| 43 | +import java.nio.file.Path; |
| 44 | +import java.nio.file.Paths; |
38 | 45 | import java.util.List; |
39 | 46 | import java.util.UUID; |
40 | 47 | import java.util.stream.Collectors; |
41 | 48 |
|
42 | 49 | import static com.spectralogic.ds3client.integration.Util.*; |
43 | 50 | import static org.hamcrest.Matchers.is; |
44 | 51 | import static org.junit.Assert.assertThat; |
| 52 | +import static org.junit.Assert.assertTrue; |
45 | 53 |
|
46 | 54 | public class VersionedObject_Test { |
47 | 55 |
|
@@ -138,4 +146,46 @@ public void stageObjectsWithVersioning() throws IOException, URISyntaxException |
138 | 146 | CLIENT.deleteBucketSpectraS3(new DeleteBucketSpectraS3Request(TEST_ENV_NAME).withForce(true)); |
139 | 147 | } |
140 | 148 | } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void getObjectsWithVersioningUsingHelpers() throws IOException, URISyntaxException, InterruptedException { |
| 152 | + // Create temp directory for files we will retrieve from bp |
| 153 | + final Path tempDirectory = Files.createTempDirectory(Paths.get("."), null); |
| 154 | + |
| 155 | + try { |
| 156 | + HELPERS.ensureBucketExists(TEST_ENV_NAME, envDataPolicyId); |
| 157 | + final String objectName = "object_with_versions"; |
| 158 | + |
| 159 | + // Put different content for object twice |
| 160 | + loadTestBook(CLIENT, BOOKS[0], objectName, TEST_ENV_NAME); // putting beowulf as content |
| 161 | + loadTestBook(CLIENT, BOOKS[1], objectName, TEST_ENV_NAME); // putting sherlock holmes as content |
| 162 | + |
| 163 | + // Get the version of the objects |
| 164 | + final GetBucketRequest getBucketRequest = new GetBucketRequest(TEST_ENV_NAME).withVersions(true); |
| 165 | + final GetBucketResponse getBucketResponse = CLIENT.getBucket(getBucketRequest); |
| 166 | + |
| 167 | + assertThat(getBucketResponse.getListBucketResult().getObjects().size(), is(0)); |
| 168 | + assertThat(getBucketResponse.getListBucketResult().getVersionedObjects().size(), is(2)); |
| 169 | + |
| 170 | + // Create bulk get job with the oldest version of the object |
| 171 | + final List<Ds3Object> objects = getBucketResponse.getListBucketResult().getVersionedObjects().stream() |
| 172 | + .filter(obj -> !obj.getIsLatest()) // filters out the latest version of the object |
| 173 | + .map(obj -> new Ds3Object(obj.getKey(), obj.getVersionId())) |
| 174 | + .collect(Collectors.toList()); |
| 175 | + |
| 176 | + final Ds3ClientHelpers.Job readJob = HELPERS.startReadJob(TEST_ENV_NAME, objects); |
| 177 | + |
| 178 | + readJob.transfer(new FileObjectGetter(tempDirectory)); |
| 179 | + |
| 180 | + // Check content is beowulf, which was the first version of content |
| 181 | + final File originalFile = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + BOOKS[0]).toFile(); |
| 182 | + final File fileCopiedFromBP = Paths.get(tempDirectory.toString(), objectName).toFile(); |
| 183 | + assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP)); |
| 184 | + |
| 185 | + } finally { |
| 186 | + cancelAllJobsForBucket(CLIENT, TEST_ENV_NAME); |
| 187 | + deleteAllContents(CLIENT, TEST_ENV_NAME); |
| 188 | + FileUtils.deleteDirectory(tempDirectory.toFile()); |
| 189 | + } |
| 190 | + } |
141 | 191 | } |
0 commit comments