2020import com .google .common .collect .Iterables ;
2121import com .spectralogic .ds3cli .CommandResponse ;
2222import com .spectralogic .ds3cli .exceptions .*;
23+ import com .spectralogic .ds3cli .helpers .TempStorageIds ;
24+ import com .spectralogic .ds3cli .helpers .TempStorageUtil ;
2325import com .spectralogic .ds3cli .helpers .Util ;
2426import com .spectralogic .ds3client .Ds3Client ;
2527import com .spectralogic .ds3client .Ds3ClientBuilder ;
3032import com .spectralogic .ds3client .models .common .Credentials ;
3133import com .spectralogic .ds3client .networking .FailedRequestException ;
3234import org .apache .commons .io .FileUtils ;
33- import org .junit .AfterClass ;
34- import org .junit .BeforeClass ;
35- import org .junit .FixMethodOrder ;
36- import org .junit .Test ;
35+ import org .junit .*;
3736import org .junit .runners .MethodSorters ;
3837import org .slf4j .Logger ;
3938import org .slf4j .LoggerFactory ;
4544import java .util .*;
4645
4746import static com .spectralogic .ds3cli .certification .CertificationUtil .*;
47+ import static com .spectralogic .ds3cli .helpers .TempStorageUtil .setupDataPolicy ;
4848import static com .spectralogic .ds3cli .helpers .TempStorageUtil .verifyAvailableTapePartition ;
4949import static junit .framework .TestCase .assertFalse ;
5050import static org .hamcrest .CoreMatchers .is ;
5656
5757/**
5858 * Implement tests to automate the BlackPearl Certification process for the JavaCLI.
59- *
59+ * <p>
6060 * For details, refer to
61- * https://developer.spectralogic.com/certification/
62- * https://developer.spectralogic.com/test-plan/
61+ * https://developer.spectralogic.com/certification/
62+ * https://developer.spectralogic.com/test-plan/
6363 */
6464@ FixMethodOrder (MethodSorters .NAME_ASCENDING ) // Order only matters for manually verifying the results
6565
@@ -74,6 +74,7 @@ public class Certification_Test {
7474 private static UUID envDataPolicyId ;
7575
7676 private final static Ds3ExceptionHandlerMapper EXCEPTION_MAPPER = Ds3ExceptionHandlerMapper .getInstance ();
77+
7778 static {
7879 EXCEPTION_MAPPER .addHandler (FailedRequestException .class , new FailedRequestExceptionHandler ());
7980 EXCEPTION_MAPPER .addHandler (RuntimeException .class , new RuntimeExceptionHandler ());
@@ -133,7 +134,7 @@ public void test_7_2_1_invalid_credentials() throws Exception {
133134
134135 try {
135136 Util .command (invalid_client , "--http -c get_service" );
136- } catch (final FailedRequestException e ) {
137+ } catch (final FailedRequestException e ) {
137138 final String formattedException = FailedRequestExceptionHandler .format (e );
138139 OUT .insertPreformat (formattedException );
139140 final String expectedError = "permissions / authorization error" ;
@@ -155,7 +156,7 @@ public void test_7_2_2_invalid_endpoint() throws Exception {
155156 boolean success = false ;
156157 try {
157158 Util .command (invalid_client , "--http -c get_service" );
158- } catch (final UnknownHostException uhe ) {
159+ } catch (final UnknownHostException uhe ) {
159160 final String formattedException = ExceptionFormatter .format (uhe );
160161 final String expectedError = "UnknownHost" ;
161162 assertThat (formattedException , containsString (expectedError ));
@@ -177,7 +178,7 @@ public void test_7_3_1_list_nonexistent_bucket() throws Exception {
177178
178179 try {
179180 Util .command (client , "--http -c get_bucket -b " + bucketName );
180- } catch (final CommandException ce ) {
181+ } catch (final CommandException ce ) {
181182 final String formattedException = ExceptionFormatter .format (ce );
182183 assertThat (formattedException , containsString ("Error: Unknown bucket." ));
183184 OUT .insertLog ("CommandResponse for 7.3.1 failed attempt to list nonexistent bucket:" );
@@ -212,7 +213,7 @@ public void test_7_3_2_access_bucket_wrong_user() throws Exception {
212213 // Attempt to access the bucket with the new user, which should fail
213214 final String listBucketCmd = "--http -c get_bucket -b " + bucketName ;
214215 Util .command (invalid_client , listBucketCmd );
215- } catch (final FailedRequestException e ) {
216+ } catch (final FailedRequestException e ) {
216217 final String formattedException = FailedRequestExceptionHandler .format (e );
217218 final String expectedError = "permissions / authorization error" ;
218219 assertThat (formattedException , containsString (expectedError ));
@@ -250,7 +251,7 @@ public void test_7_4_get_nonexistent_object() throws Exception {
250251 final CommandResponse getNonExtandObjectResponse = Util .command (client , getNonExtantObject );
251252 OUT .insertCommand (getNonExtantObject , getNonExtandObjectResponse .getMessage ());
252253
253- } catch (final FailedRequestException fre ) {
254+ } catch (final FailedRequestException fre ) {
254255 final String formattedException = FailedRequestExceptionHandler .format (fre );
255256 final String expectedError = "not found" ;
256257 assertThat (formattedException , containsString (expectedError ));
@@ -266,6 +267,7 @@ public void test_7_4_get_nonexistent_object() throws Exception {
266267
267268 /**
268269 * 7.5-7: Archive and Restore 3 objects larger than the chunk size to BP simultaneously.
270+ *
269271 * @throws Exception
270272 */
271273 @ Test
@@ -282,6 +284,7 @@ public void test_7_5_and_6_bulk_performance_3x110GB() throws Exception {
282284
283285 /**
284286 * 7.7-8: Archive 250 objects of approximately 1GB size to BP.
287+ *
285288 * @throws Exception
286289 */
287290 @ Test
@@ -323,7 +326,7 @@ private static boolean testBulkPutAndBulkGetPerformance(
323326
324327 OUT .insertLog ("Bulk PUT from bucket " + bucketName );
325328 final long startPutTime = getCurrentTime ();
326- final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
329+ final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
327330 final CommandResponse putBulkResponse = Util .command (client , putBulkCmd );
328331 OUT .insertCommand (putBulkCmd , putBulkResponse .getMessage ());
329332 final long endPutTime = getCurrentTime ();
@@ -368,14 +371,20 @@ public void test_8_1_versioning() throws Exception {
368371 final Long fileSize = 1024L ;
369372 final String bucketName = CertificationUtil .getBucketName (testDescription );
370373 boolean success = false ;
374+ final UUID dataPolicy = setupDataPolicy (testDescription , false , ChecksumType .Type .MD5 , client );
375+ final TempStorageIds tempStorageIds = TempStorageUtil .setup (testDescription , dataPolicy , client );
376+
371377
372378 OUT .startNewTest (testDescription );
373379 try {
380+
374381 OUT .insertLog ("Set data policy to use versioning" );
375- final String enableDataPolicyVersioningCmd = "--http -c modify_data_policy --modify-params versioning:KEEP_LATEST -i " + envDataPolicyId ;
382+ final String enableDataPolicyVersioningCmd = "--http -c modify_data_policy --modify-params versioning:KEEP_LATEST -i " + dataPolicy ;
376383 final CommandResponse modifyDataPolicyResponse = Util .command (client , enableDataPolicyVersioningCmd );
377384 OUT .insertCommand (enableDataPolicyVersioningCmd , modifyDataPolicyResponse .getMessage ());
378385 assertThat (modifyDataPolicyResponse .getReturnCode (), is (0 ));
386+ client .modifyUserSpectraS3 (new ModifyUserSpectraS3Request ("Administrator" )
387+ .withDefaultDataPolicyId (dataPolicy ));
379388
380389 // create and store one file
381390 Path bulkPutLocalTempDir = CertificationUtil .createTempFiles (bucketName , numFiles , fileSize );
@@ -407,11 +416,9 @@ public void test_8_1_versioning() throws Exception {
407416 } catch (final Exception e ) {
408417 LOG .error ("Exception: {}" , e .getMessage (), e );
409418 } finally {
410- Util .deleteBucket (client , bucketName );
411-
412- // undo versioning
413- Util .command (client , "--http -c modify_data_policy --modify-params versioning:NONE -i " + envDataPolicyId );
414-
419+ client .modifyUserSpectraS3 (new ModifyUserSpectraS3Request ("Administrator" )
420+ .withDefaultDataPolicyId (envDataPolicyId ));
421+ TempStorageUtil .teardown (testDescription , tempStorageIds , client );
415422 OUT .finishTest (testDescription , success );
416423 assertTrue (testDescription + " did not complete" , success );
417424 }
@@ -432,7 +439,7 @@ public void test_8_2_partial_restore() throws Exception {
432439 try {
433440 final Path bulkPutLocalTempDir = CertificationUtil .createTempFiles (bucketName , numFiles , fileSize );
434441
435- final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
442+ final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
436443 final CommandResponse putBulkResponse = Util .command (client , putBulkCmd );
437444 OUT .insertCommand (putBulkCmd , putBulkResponse .getMessage ());
438445 assertThat (putBulkResponse .getReturnCode (), is (0 ));
@@ -445,7 +452,7 @@ public void test_8_2_partial_restore() throws Exception {
445452 OUT .insertPreformat (objectName );
446453
447454 // restore first 100 bytes
448- final String getPartialObjectCmd = "--http -c get_object --range-offset 0 --range-length 100 -b " + bucketName + " -o " + objectName + " -d " + bulkPutLocalTempDir .toString ();
455+ final String getPartialObjectCmd = "--http -c get_object --range-offset 0 --range-length 100 -b " + bucketName + " -o " + objectName + " -d " + bulkPutLocalTempDir .toString ();
449456 final CommandResponse getPartialResponse = Util .command (client , getPartialObjectCmd );
450457 OUT .insertCommand (getPartialObjectCmd , getPartialResponse .getMessage ());
451458 assertThat (getPartialResponse .getReturnCode (), is (0 ));
@@ -455,11 +462,11 @@ public void test_8_2_partial_restore() throws Exception {
455462 final com .spectralogic .ds3cli .util .FileUtils .ObjectsToPut objectsToPut = com .spectralogic .ds3cli .util .FileUtils .getObjectsToPut (filesToPut , bulkPutLocalTempDir , "" , true );
456463 final Ds3Object obj = objectsToPut .getDs3Objects ().get (0 );
457464 assertTrue (obj .getSize () < 150 );
458- OUT .insertLog (obj .getName () + " size: " + Long .toString (obj .getSize ()));
465+ OUT .insertLog (obj .getName () + " size: " + Long .toString (obj .getSize ()));
459466 success = true ;
460467
461468 } catch (final Exception e ) {
462- LOG .error ("Exception in " + testDescription , e );
469+ LOG .error ("Exception in " + testDescription , e );
463470 } finally {
464471 OUT .finishTest (testDescription , success );
465472 Util .deleteBucket (client , bucketName );
@@ -501,7 +508,7 @@ public void test_8_4_change_priorities() throws Exception {
501508 success = true ;
502509
503510 } catch (final Exception e ) {
504- LOG .error ("Exception in " + testDescription , e );
511+ LOG .error ("Exception in " + testDescription , e );
505512 } finally {
506513 OUT .finishTest (testDescription , success );
507514 CertificationUtil .deleteJob (client , jobId );
@@ -551,7 +558,7 @@ public boolean apply(@Nullable final Tape tape) {
551558 assertTrue (postEjectResponse .getMessage ().contains (ejectLocation ));
552559 success = true ;
553560 } catch (final Exception e ) {
554- LOG .error ("Exception in " + testDescription , e );
561+ LOG .error ("Exception in " + testDescription , e );
555562 } finally {
556563 CertificationUtil .cancelTapeEject (client , barcode );
557564 OUT .finishTest (testDescription , success );
@@ -587,7 +594,7 @@ public void test_8_6_fully_persisted() throws Exception {
587594 // Create temp files for BULK_PUT
588595 final Path bulkPutLocalTempDir = CertificationUtil .createTempFiles (bucketName , numFiles , fileSize );
589596
590- final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
597+ final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir .toString ();
591598 final CommandResponse putBulkResponse = Util .command (client , putBulkCmd );
592599 assertThat (putBulkResponse .getReturnCode (), is (0 ));
593600
@@ -620,7 +627,7 @@ public void test_8_6_fully_persisted() throws Exception {
620627 final CommandResponse getPhysicalPlacementAfterResponse = Util .command (client , getPhysicalPlacementCmd );
621628 OUT .insertCommand (getPhysicalPlacementCmd , getPhysicalPlacementAfterResponse .getMessage ());
622629 } catch (final Exception e ) {
623- LOG .error ("Exception in " + testDescription , e );
630+ LOG .error ("Exception in " + testDescription , e );
624631 } finally {
625632 OUT .finishTest (testDescription , success );
626633 Util .deleteBucket (client , bucketName );
@@ -642,16 +649,16 @@ public void test_8_7_large_list() throws Exception {
642649 boolean success = false ;
643650 try {
644651 // Put 500 files into bucket
645- final CommandResponse performanceResponse = Util .putPerformanceFiles (client , bucketName , numFiles , fileSize );
652+ final CommandResponse performanceResponse = Util .putPerformanceFiles (client , bucketName , numFiles , fileSize );
646653 assertThat (performanceResponse .getReturnCode (), is (0 ));
647654
648655 final String listBucketArgs = "--http -c get_bucket -b " + bucketName ;
649- final CommandResponse getBucketResponseAfterBulkPut = Util .command (client , listBucketArgs );
656+ final CommandResponse getBucketResponseAfterBulkPut = Util .command (client , listBucketArgs );
650657 OUT .insertCommand (listBucketArgs , getBucketResponseAfterBulkPut .getMessage ());
651658 assertThat (getBucketResponseAfterBulkPut .getReturnCode (), is (0 ));
652659 success = true ;
653660 } catch (final Exception e ) {
654- LOG .error ("Exception in " + testDescription , e );
661+ LOG .error ("Exception in " + testDescription , e );
655662 } finally {
656663 OUT .finishTest (testDescription , success );
657664 Util .deleteBucket (client , bucketName );
0 commit comments