示例#1
0
  /**
   * Tests {@link S3#listBucket(S3Client, String, ListBucketOptions)} where retrieving all results
   * requires multiple requests.
   *
   * @throws Exception if anything goes wrong
   */
  @Test
  public void testMultiPageResult() throws Exception {
    String nextMarker = "FOO";
    S3Client api = createMock(S3Client.class);
    ListBucketOptions options = new ListBucketOptions();
    ListBucketResponse response2 = new ListBucketHandlerTest().expected();
    ListBucketResponse response1 =
        new ListBucketResponseImpl(
            response2.getName(),
            response2,
            response2.getPrefix(),
            null,
            nextMarker,
            response2.getMaxKeys(),
            response2.getDelimiter(),
            false,
            response2.getCommonPrefixes());

    expect(api.listBucket("bucket", options)).andReturn(response1).once();
    expect(api.listBucket("bucket", options.afterMarker(nextMarker))).andReturn(response2).once();

    EasyMock.replay(api);

    PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options);

    // number of objects
    assertEquals(result.concat().size(), 20);
  }
示例#2
0
  /**
   * Tests {@link S3#listBucket(S3Client, String, ListBucketOptions)} where a single response
   * returns all results.
   *
   * @throws Exception if anything goes wrong
   */
  @Test
  public void testSinglePageResult() throws Exception {
    S3Client api = createMock(S3Client.class);
    ListBucketOptions options = new ListBucketOptions();
    ListBucketResponse response = new ListBucketHandlerTest().expected();

    expect(api.listBucket("bucket", options)).andReturn(response).once();

    EasyMock.replay(api);

    PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options);

    // number of pages
    assertEquals(result.size(), 1);
    // number of objects
    assertEquals(result.get(0).size(), 10);
  }
 private S3Object getConfigObject() throws Exception {
   try {
     S3Object object = s3Client.getObject(arguments.getBucket(), arguments.getKey());
     if (object.getObjectMetadata().getContentLength() > 0) {
       return object;
     }
   } catch (AmazonS3Exception e) {
     if (!isNotFoundError(e)) {
       throw e;
     }
   }
   return null;
 }
 private ObjectMetadata getConfigMetadata() throws Exception {
   try {
     ObjectMetadata metadata =
         s3Client.getObjectMetadata(arguments.getBucket(), arguments.getKey());
     if (metadata.getContentLength() > 0) {
       return metadata;
     }
   } catch (AmazonS3Exception e) {
     if (!isNotFoundError(e)) {
       throw e;
     }
   }
   return null;
 }
 @Override
 public void close() throws IOException {
   s3Client.close();
 }