|
24 | 24 | import com.spectralogic.ds3client.commands.spectrads3.*; |
25 | 25 | import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
26 | 26 | import com.spectralogic.ds3client.helpers.JobRecoveryException; |
| 27 | +import com.spectralogic.ds3client.helpers.JobRecoveryNotActiveException; |
27 | 28 | import com.spectralogic.ds3client.helpers.ObjectCompletedListener; |
28 | 29 | import com.spectralogic.ds3client.helpers.options.WriteJobOptions; |
29 | 30 | import com.spectralogic.ds3client.integration.test.helpers.JobStatusHelper; |
@@ -484,6 +485,47 @@ public void testRecoverWriteJob() throws IOException, JobRecoveryException, URIS |
484 | 485 | } |
485 | 486 | } |
486 | 487 |
|
| 488 | + @Test (expected = JobRecoveryNotActiveException.class) |
| 489 | + public void testRecoverWriteJobCanceledJob() throws IOException, URISyntaxException, JobRecoveryException { |
| 490 | + final String bucketName = "test_canceled_recover_write_job_bucket"; |
| 491 | + final String book1 = "beowulf.txt"; |
| 492 | + final String book2 = "ulysses.txt"; |
| 493 | + |
| 494 | + try { |
| 495 | + HELPERS.ensureBucketExists(bucketName, envDataPolicyId); |
| 496 | + |
| 497 | + final Path objPath1 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book1); |
| 498 | + final Path objPath2 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book2); |
| 499 | + final Ds3Object obj1 = new Ds3Object(book1, Files.size(objPath1)); |
| 500 | + final Ds3Object obj2 = new Ds3Object(book2, Files.size(objPath2)); |
| 501 | + |
| 502 | + final Ds3ClientHelpers.Job job = Ds3ClientHelpers.wrap(client).startWriteJob(bucketName, Lists.newArrayList(obj1, obj2)); |
| 503 | + |
| 504 | + final PutObjectResponse putResponse1 = client.putObject(new PutObjectRequest( |
| 505 | + job.getBucketName(), |
| 506 | + book1, |
| 507 | + new ResourceObjectPutter(RESOURCE_BASE_NAME).buildChannel(book1), |
| 508 | + job.getJobId().toString(), |
| 509 | + 0, |
| 510 | + Files.size(objPath1))); |
| 511 | + assertThat(putResponse1, is(notNullValue())); |
| 512 | + |
| 513 | + // Cancel write job and attempt recovery |
| 514 | + client.cancelActiveJobSpectraS3(new CancelActiveJobSpectraS3Request(job.getJobId())); |
| 515 | + |
| 516 | + // Attempt recovery of canceled job |
| 517 | + HELPERS.recoverWriteJob(job.getJobId()); |
| 518 | + assert false; |
| 519 | + } finally { |
| 520 | + deleteAllContents(client, bucketName); |
| 521 | + } |
| 522 | + } |
| 523 | + |
| 524 | + @Test (expected = JobRecoveryNotActiveException.class) |
| 525 | + public void testRecoverWriteJobDoesNotExist() throws IOException, JobRecoveryException { |
| 526 | + HELPERS.recoverWriteJob(UUID.randomUUID()); |
| 527 | + } |
| 528 | + |
487 | 529 | @Test |
488 | 530 | public void verifySendCrc32cChecksum() throws IOException, URISyntaxException { |
489 | 531 | final String bucketName = "crc_32_bucket"; |
@@ -659,13 +701,73 @@ public void testRecoverReadJob() throws IOException, JobRecoveryException, URISy |
659 | 701 |
|
660 | 702 | } finally { |
661 | 703 | deleteAllContents(client, bucketName); |
662 | | - for( final Path tempFile : Files.newDirectoryStream(dirPath) ){ |
| 704 | + for (final Path tempFile : Files.newDirectoryStream(dirPath) ){ |
663 | 705 | Files.delete(tempFile); |
664 | 706 | } |
665 | 707 | Files.delete(dirPath); |
666 | 708 | } |
667 | 709 | } |
668 | 710 |
|
| 711 | + @Test (expected = JobRecoveryNotActiveException.class) |
| 712 | + public void testRecoverReadJobCanceledJob() throws IOException, JobRecoveryException, URISyntaxException { |
| 713 | + final String bucketName = "test_canceled_recover_read_job_bucket"; |
| 714 | + final String book1 = "beowulf.txt"; |
| 715 | + final String book2 = "ulysses.txt"; |
| 716 | + final Path objPath1 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book1); |
| 717 | + final Path objPath2 = ResourceUtils.loadFileResource(RESOURCE_BASE_NAME + book2); |
| 718 | + final Ds3Object obj1 = new Ds3Object(book1, Files.size(objPath1)); |
| 719 | + final Ds3Object obj2 = new Ds3Object(book2, Files.size(objPath2)); |
| 720 | + |
| 721 | + final Path dirPath = FileSystems.getDefault().getPath("output_canceled_job"); |
| 722 | + if (!Files.exists(dirPath)) { |
| 723 | + Files.createDirectory(dirPath); |
| 724 | + } |
| 725 | + |
| 726 | + try { |
| 727 | + HELPERS.ensureBucketExists(bucketName, envDataPolicyId); |
| 728 | + |
| 729 | + final Ds3ClientHelpers.Job putJob = HELPERS.startWriteJob(bucketName, Lists.newArrayList(obj1, obj2)); |
| 730 | + putJob.transfer(new ResourceObjectPutter(RESOURCE_BASE_NAME)); |
| 731 | + |
| 732 | + final FileChannel channel1 = FileChannel.open( |
| 733 | + dirPath.resolve(book1), |
| 734 | + StandardOpenOption.WRITE, |
| 735 | + StandardOpenOption.CREATE, |
| 736 | + StandardOpenOption.TRUNCATE_EXISTING |
| 737 | + ); |
| 738 | + |
| 739 | + final Ds3ClientHelpers.Job readJob = HELPERS.startReadJob(bucketName, Lists.newArrayList(obj1, obj2)); |
| 740 | + final GetObjectResponse readResponse1 = client.getObject( |
| 741 | + new GetObjectRequest( |
| 742 | + bucketName, |
| 743 | + book1, |
| 744 | + channel1, |
| 745 | + readJob.getJobId().toString(), |
| 746 | + 0)); |
| 747 | + |
| 748 | + assertThat(readResponse1, is(notNullValue())); |
| 749 | + assertThat(readResponse1.getObjectSize(), is(notNullValue())); |
| 750 | + |
| 751 | + // Cancel active job |
| 752 | + client.cancelActiveJobSpectraS3(new CancelActiveJobSpectraS3Request(readJob.getJobId())); |
| 753 | + |
| 754 | + // Attempt recovery of canceled job |
| 755 | + HELPERS.recoverReadJob(readJob.getJobId()); |
| 756 | + assert false; |
| 757 | + } finally { |
| 758 | + deleteAllContents(client, bucketName); |
| 759 | + for (final Path tempFile : Files.newDirectoryStream(dirPath) ){ |
| 760 | + Files.delete(tempFile); |
| 761 | + } |
| 762 | + Files.delete(dirPath); |
| 763 | + } |
| 764 | + } |
| 765 | + |
| 766 | + @Test (expected = JobRecoveryNotActiveException.class) |
| 767 | + public void testRecoverReadJobDoesNotExist() throws IOException, JobRecoveryException { |
| 768 | + HELPERS.recoverReadJob(UUID.randomUUID()); |
| 769 | + } |
| 770 | + |
669 | 771 | @Test |
670 | 772 | public void putDirectory() throws IOException { |
671 | 773 | assumeVersion1_2(client); |
|
0 commit comments