|
18 | 18 | import com.google.common.collect.Iterables; |
19 | 19 | import com.google.common.collect.Lists; |
20 | 20 | import com.spectralogic.ds3client.Ds3Client; |
21 | | -import com.spectralogic.ds3client.commands.spectrads3.CancelJobSpectraS3Request; |
22 | | -import com.spectralogic.ds3client.commands.spectrads3.CancelJobSpectraS3Response; |
23 | | -import com.spectralogic.ds3client.commands.spectrads3.GetJobChunksReadyForClientProcessingSpectraS3Request; |
| 21 | +import com.spectralogic.ds3client.commands.PutObjectRequest; |
| 22 | +import com.spectralogic.ds3client.commands.PutObjectResponse; |
| 23 | +import com.spectralogic.ds3client.commands.spectrads3.*; |
24 | 24 | import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
| 25 | +import com.spectralogic.ds3client.helpers.JobRecoveryException; |
25 | 26 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds; |
26 | 27 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil; |
| 28 | +import com.spectralogic.ds3client.models.BulkObject; |
27 | 29 | import com.spectralogic.ds3client.models.ChecksumType; |
28 | 30 | import com.spectralogic.ds3client.models.Contents; |
| 31 | +import com.spectralogic.ds3client.models.Objects; |
29 | 32 | import com.spectralogic.ds3client.models.bulk.Ds3Object; |
30 | 33 | import com.spectralogic.ds3client.networking.FailedRequestException; |
| 34 | +import com.spectralogic.ds3client.utils.ResourceUtils; |
31 | 35 | import org.junit.AfterClass; |
32 | 36 | import org.junit.BeforeClass; |
33 | 37 | import org.junit.Test; |
34 | 38 | import org.slf4j.Logger; |
35 | 39 | import org.slf4j.LoggerFactory; |
36 | 40 |
|
37 | 41 | import java.io.IOException; |
| 42 | +import java.net.URISyntaxException; |
38 | 43 | import java.nio.channels.SeekableByteChannel; |
| 44 | +import java.nio.file.Files; |
| 45 | +import java.nio.file.Path; |
| 46 | +import java.nio.file.StandardOpenOption; |
39 | 47 | import java.util.Collections; |
40 | 48 | import java.util.List; |
41 | 49 | import java.util.UUID; |
42 | 50 |
|
43 | | -import static org.hamcrest.CoreMatchers.is; |
44 | | -import static org.hamcrest.CoreMatchers.notNullValue; |
| 51 | +import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME; |
| 52 | +import static com.spectralogic.ds3client.integration.Util.deleteAllContents; |
| 53 | +import static org.hamcrest.CoreMatchers.*; |
45 | 54 | import static org.junit.Assert.*; |
46 | 55 |
|
47 | 56 | public class Regression_Test { |
@@ -95,7 +104,7 @@ public void testMarkerWithSpaces() throws IOException { |
95 | 104 | .cancelJobSpectraS3(new CancelJobSpectraS3Request(putJob.getJobId().toString())); |
96 | 105 | assertEquals(204, cancelJobResponse.getStatusCode()); |
97 | 106 | } finally { |
98 | | - Util.deleteAllContents(client, bucketName); |
| 107 | + deleteAllContents(client, bucketName); |
99 | 108 | } |
100 | 109 | } |
101 | 110 |
|
@@ -131,7 +140,7 @@ public void testPrefixWithSpaces() throws IOException { |
131 | 140 | .cancelJobSpectraS3(new CancelJobSpectraS3Request(putJob.getJobId().toString())); |
132 | 141 | assertEquals(204, cancelJobResponse.getStatusCode()); |
133 | 142 | } finally { |
134 | | - Util.deleteAllContents(client, bucketName); |
| 143 | + deleteAllContents(client, bucketName); |
135 | 144 | } |
136 | 145 | } |
137 | 146 |
|
@@ -180,7 +189,7 @@ public void testPrefixForDirectoriesWithSpaces() throws IOException { |
180 | 189 | .cancelJobSpectraS3(new CancelJobSpectraS3Request(putJob.getJobId().toString())); |
181 | 190 | assertEquals(204, cancelJobResponse.getStatusCode()); |
182 | 191 | } finally { |
183 | | - Util.deleteAllContents(client, bucketName); |
| 192 | + deleteAllContents(client, bucketName); |
184 | 193 | } |
185 | 194 | } |
186 | 195 |
|
@@ -228,7 +237,7 @@ public void testPrefixForNestedDirectories() throws IOException { |
228 | 237 | .cancelJobSpectraS3(new CancelJobSpectraS3Request(putJob.getJobId().toString())); |
229 | 238 | assertEquals(204, cancelJobResponse.getStatusCode()); |
230 | 239 | } finally { |
231 | | - Util.deleteAllContents(client, bucketName); |
| 240 | + deleteAllContents(client, bucketName); |
232 | 241 | } |
233 | 242 | } |
234 | 243 |
|
@@ -261,8 +270,56 @@ public SeekableByteChannel buildChannel(final String key) throws IOException { |
261 | 270 | } |
262 | 271 | }); |
263 | 272 | } finally { |
264 | | - Util.deleteAllContents(client, bucketName); |
| 273 | + deleteAllContents(client, bucketName); |
265 | 274 | } |
| 275 | + } |
| 276 | + |
| 277 | + @Test |
| 278 | + public void testRecoverWriteJobWithHelper() throws IOException, JobRecoveryException, URISyntaxException { |
| 279 | + final String bucketName = "test_recover_write_job_bucket"; |
| 280 | + final String book1 = "beowulf.txt"; |
| 281 | + final String book2 = "ulysses.txt"; |
| 282 | + |
| 283 | + try { |
| 284 | + HELPERS.ensureBucketExists(bucketName, envDataPolicyId); |
266 | 285 |
|
| 286 | + final Path objPath1 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book1); |
| 287 | + final Path objPath2 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book2); |
| 288 | + final Ds3Object obj1 = new Ds3Object(book1, Files.size(objPath1)); |
| 289 | + final Ds3Object obj2 = new Ds3Object(book2, Files.size(objPath2)); |
| 290 | + |
| 291 | + final Ds3ClientHelpers.Job job = Ds3ClientHelpers.wrap(client).startWriteJob(bucketName, Lists.newArrayList(obj1, obj2)); |
| 292 | + |
| 293 | + final PutObjectResponse putResponse1 = client.putObject(new PutObjectRequest( |
| 294 | + job.getBucketName(), |
| 295 | + book1, |
| 296 | + new ResourceObjectPutter(RESOURCE_BASE_NAME).buildChannel(book1), |
| 297 | + job.getJobId().toString(), |
| 298 | + 0, |
| 299 | + Files.size(objPath1))); |
| 300 | + assertThat(putResponse1, is(notNullValue())); |
| 301 | + assertThat(putResponse1.getStatusCode(), is(equalTo(200))); |
| 302 | + |
| 303 | + // Interuption... |
| 304 | + final Ds3ClientHelpers.Job recoverJob = HELPERS.recoverWriteJob(job.getJobId()); |
| 305 | + |
| 306 | + recoverJob.transfer(new Ds3ClientHelpers.ObjectChannelBuilder() { |
| 307 | + @Override |
| 308 | + public SeekableByteChannel buildChannel(final String key) throws IOException { |
| 309 | + return Files.newByteChannel(objPath2, StandardOpenOption.READ); |
| 310 | + } |
| 311 | + }); |
| 312 | + |
| 313 | + final GetJobSpectraS3Response finishedJob = client.getJobSpectraS3(new GetJobSpectraS3Request(job.getJobId())); |
| 314 | + |
| 315 | + for (final Objects objects : finishedJob.getMasterObjectListResult().getObjects()) { |
| 316 | + for (final BulkObject bulkObject : objects.getObjects()) { |
| 317 | + assertTrue(bulkObject.getInCache()); |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + } finally { |
| 322 | + deleteAllContents(client, bucketName); |
| 323 | + } |
267 | 324 | } |
268 | 325 | } |
0 commit comments