@Override public VersionListing listVersions() { versionListing = client.listVersions(listVersionsRequest); return versionListing; }
VersionListing version_listing = s3.listVersions( new ListVersionsRequest().withBucketName(bucket_name)); while (true) {
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }
@Before public void setUpSharedTests() throws Exception { s3 = mock(AmazonS3.class); versionListing = mock(VersionListing.class); firstSummary = mock(S3VersionSummary.class); secondSummary = mock(S3VersionSummary.class); when(s3.listVersions(any(ListVersionsRequest.class))).thenReturn(versionListing); when(versionListing.getVersionSummaries()).thenReturn(new ArrayList<S3VersionSummary>()); }
@Test public void testSetsNullPrefixOnRequest() throws Exception { s3Versions.iterator().hasNext(); ArgumentCaptor<ListVersionsRequest> listCaptor = ArgumentCaptor .forClass(ListVersionsRequest.class); verify(s3).listVersions(listCaptor.capture()); assertNull(listCaptor.getValue().getPrefix()); }
@Test public void testSetsPrefixOnRequest() throws Exception { s3Versions.iterator().hasNext(); ArgumentCaptor<ListVersionsRequest> listCaptor = ArgumentCaptor .forClass(ListVersionsRequest.class); verify(s3).listVersions(listCaptor.capture()); assertEquals("photos/", listCaptor.getValue().getPrefix()); }
@Test public void testSetsKeyAsPrefixOnRequest() throws Exception { s3Versions.iterator().hasNext(); ArgumentCaptor<ListVersionsRequest> listCaptor = ArgumentCaptor .forClass(ListVersionsRequest.class); verify(s3).listVersions(listCaptor.capture()); assertEquals("the-key", listCaptor.getValue().getPrefix()); }
@Test public void testStopsAtNonMatchingKey() throws Exception { VersionListing listing = mock(VersionListing.class); S3VersionSummary matchingSummary = mock(S3VersionSummary.class); S3VersionSummary nonMatchingSummary = mock(S3VersionSummary.class); when(listing.getVersionSummaries()).thenReturn( Arrays.asList(matchingSummary, nonMatchingSummary, matchingSummary)); when(matchingSummary.getKey()).thenReturn("the-key"); when(nonMatchingSummary.getKey()).thenReturn("the-other-key"); when(s3.listVersions(any(ListVersionsRequest.class))).thenReturn(listing); Iterator<S3VersionSummary> iter = s3Versions.iterator(); assertTrue(iter.hasNext()); assertSame(matchingSummary, iter.next()); assertFalse(iter.hasNext()); }
@Test public void testUsesBatchSizeForMaxResults() throws Exception { s3Versions.withBatchSize(12).iterator().hasNext(); ArgumentCaptor<ListVersionsRequest> listCaptor = ArgumentCaptor .forClass(ListVersionsRequest.class); verify(s3).listVersions(listCaptor.capture()); assertEquals((Integer) 12, listCaptor.getValue().getMaxResults()); }
@Test public void testDoesNotRequestNextPageIfNonMatchingKeyWasFound() throws Exception { VersionListing listing = mock(VersionListing.class); S3VersionSummary matchingSummary = mock(S3VersionSummary.class); S3VersionSummary nonMatchingSummary = mock(S3VersionSummary.class); when(listing.getVersionSummaries()).thenReturn( Arrays.asList(matchingSummary, nonMatchingSummary)); when(listing.isTruncated()).thenReturn(true); when(matchingSummary.getKey()).thenReturn("the-key"); when(nonMatchingSummary.getKey()).thenReturn("the-other-key"); when(s3.listVersions(any(ListVersionsRequest.class))).thenReturn(listing); Iterator<S3VersionSummary> iter = s3Versions.iterator(); assertTrue(iter.hasNext()); assertSame(matchingSummary, iter.next()); assertFalse(iter.hasNext()); verify(s3, never()).listNextBatchOfVersions(listing); }
@Test public void testListsVersions() throws Exception { s3Versions.iterator().hasNext(); ArgumentCaptor<ListVersionsRequest> listCaptor = ArgumentCaptor .forClass(ListVersionsRequest.class); verify(s3).listVersions(listCaptor.capture()); assertEquals(s3Versions.getBucketName(), listCaptor.getValue().getBucketName()); assertNull(listCaptor.getValue().getMaxResults()); }
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }
@Override public VersionListing listVersions(ListVersionsRequest listVersionsRequest, AmazonS3 s3Client) { return s3Client.listVersions(listVersionsRequest); }
@Override public VersionListing listVersions() { versionListing = client.listVersions(listVersionsRequest); return versionListing; }
@Override public VersionListing listVersions(ListVersionsRequest listVersionsRequest, AmazonS3 s3Client) { return s3Client.listVersions(listVersionsRequest); }
@Override public VersionListing listVersions(String bucketName, String prefix, String keyMarker, String versionIdMarker, String delimiter, Integer maxResults) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().listVersions(bucketName, prefix, keyMarker, versionIdMarker, delimiter, maxResults)); }
@Override public VersionListing listVersions(ListVersionsRequest listVersionsRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().listVersions(listVersionsRequest)); }
@Override public VersionListing listVersions(String bucketName, String prefix) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().listVersions(bucketName, prefix)); }
@Override public VersionListing call() { if (fListing == null) { return s3.listVersions(config.getBucketName(), key, null, null, "/", null); } else { return s3.listNextBatchOfVersions(fListing); } } }, OPERATION_LIST_VERSIONS);
@Override public VersionListing call() { ListVersionsRequest request = new ListVersionsRequest().withBucketName(config.getBucketName()); request.setPrefix("".equals(prefix) ? null : prefix); // AWS SDK will always set this anyway.. this is for clarity request.setEncodingType("url"); return s3.listVersions(request); } }, OPERATION_LIST_VERSIONS);