|
| 1 | +/* |
| 2 | + * **************************************************************************** |
| 3 | + * Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved. |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use |
| 5 | + * this file except in compliance with the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * or in the "license" file accompanying this file. |
| 10 | + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 11 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | + * specific language governing permissions and limitations under the License. |
| 13 | + * **************************************************************************** |
| 14 | + */ |
| 15 | + |
| 16 | +package com.spectralogic.ds3client.integration; |
| 17 | + |
| 18 | +import com.google.common.collect.ImmutableList; |
| 19 | +import com.spectralogic.ds3client.Ds3Client; |
| 20 | +import com.spectralogic.ds3client.commands.spectrads3.PutBulkJobSpectraS3Request; |
| 21 | +import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
| 22 | +import com.spectralogic.ds3client.helpers.pagination.GetObjectsFullDetailsLoaderFactory; |
| 23 | +import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds; |
| 24 | +import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil; |
| 25 | +import com.spectralogic.ds3client.models.ChecksumType; |
| 26 | +import com.spectralogic.ds3client.models.DetailedS3Object; |
| 27 | +import com.spectralogic.ds3client.models.bulk.Ds3Object; |
| 28 | +import com.spectralogic.ds3client.utils.collections.LazyIterable; |
| 29 | +import org.junit.AfterClass; |
| 30 | +import org.junit.BeforeClass; |
| 31 | +import org.junit.Test; |
| 32 | +import org.slf4j.Logger; |
| 33 | +import org.slf4j.LoggerFactory; |
| 34 | + |
| 35 | +import java.io.IOException; |
| 36 | +import java.util.HashSet; |
| 37 | +import java.util.List; |
| 38 | +import java.util.Set; |
| 39 | +import java.util.UUID; |
| 40 | + |
| 41 | +import static com.spectralogic.ds3client.integration.Util.deleteAllContents; |
| 42 | +import static com.spectralogic.ds3client.integration.Util.insecureFromEnv; |
| 43 | +import static junit.framework.TestCase.assertFalse; |
| 44 | +import static org.junit.Assert.assertTrue; |
| 45 | + |
| 46 | +public class SpectraS3PaginationLoader_Test { |
| 47 | + |
| 48 | + private static final Logger LOG = LoggerFactory.getLogger(SpectraS3PaginationLoader_Test.class); |
| 49 | + |
| 50 | + private static final Ds3Client CLIENT = Util.fromEnv(); |
| 51 | + private static final Ds3ClientHelpers HELPERS = Ds3ClientHelpers.wrap(CLIENT); |
| 52 | + private static final String TEST_ENV_NAME = "s3_pagination_test"; |
| 53 | + private static final int RETRIES = 5; |
| 54 | + |
| 55 | + private static TempStorageIds envStorageIds; |
| 56 | + private static UUID envDataPolicyId; |
| 57 | + |
| 58 | + @BeforeClass |
| 59 | + public static void startup() throws IOException { |
| 60 | + LOG.info("Starting test Setup..."); |
| 61 | + envDataPolicyId = TempStorageUtil.setupDataPolicy(TEST_ENV_NAME, false, ChecksumType.Type.MD5, CLIENT); |
| 62 | + envStorageIds = TempStorageUtil.setup(TEST_ENV_NAME, envDataPolicyId, CLIENT); |
| 63 | + LOG.info("Finished test Setup..."); |
| 64 | + } |
| 65 | + |
| 66 | + @AfterClass |
| 67 | + public static void teardown() throws IOException { |
| 68 | + LOG.info("Starting test teardown..."); |
| 69 | + TempStorageUtil.teardown(TEST_ENV_NAME, envStorageIds, CLIENT); |
| 70 | + CLIENT.close(); |
| 71 | + LOG.info("Finished test teardown..."); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void basicPagination() throws IOException { |
| 76 | + try { |
| 77 | + // test setup |
| 78 | + HELPERS.ensureBucketExists(TEST_ENV_NAME); |
| 79 | + final int numObjects = 55; |
| 80 | + CLIENT.putBulkJobSpectraS3(new PutBulkJobSpectraS3Request(TEST_ENV_NAME, createTestList(numObjects))); |
| 81 | + |
| 82 | + final GetObjectsFullDetailsLoaderFactory loaderFactory = new GetObjectsFullDetailsLoaderFactory(CLIENT, TEST_ENV_NAME, "", 10, RETRIES, false); |
| 83 | + |
| 84 | + final Set<String> foundItems = new HashSet<>(); |
| 85 | + |
| 86 | + for (final DetailedS3Object detailedS3Object : new LazyIterable<>(loaderFactory)) { |
| 87 | + LOG.info("Testing: {}", detailedS3Object.getName()); |
| 88 | + assertFalse(foundItems.contains(detailedS3Object.getName())); |
| 89 | + foundItems.add(detailedS3Object.getName()); |
| 90 | + } |
| 91 | + |
| 92 | + for (int i = 0; i < numObjects; i++) { |
| 93 | + assertTrue(foundItems.contains("obj." + i)); |
| 94 | + } |
| 95 | + |
| 96 | + } finally { |
| 97 | + deleteAllContents(CLIENT, TEST_ENV_NAME); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + private List<Ds3Object> createTestList(final int numObjects) { |
| 102 | + final ImmutableList.Builder<Ds3Object> builder = ImmutableList.builder(); |
| 103 | + for (int i = 0; i < numObjects; i++) { |
| 104 | + builder.add(new Ds3Object("obj." + i, i+1)); |
| 105 | + } |
| 106 | + |
| 107 | + return builder.build(); |
| 108 | + } |
| 109 | +} |
0 commit comments