S3StorageProvider extends StorageProviderBase { protected String doesContentExistWithExpectedChecksum(String bucketName, String contentId, String expectedChecksum) { int maxAttempts = 20; int waitInSeconds = 2; int attempts = 0; int totalSecondsWaited = 0; String etag = null; for (int i = 0; i < maxAttempts; i++) { try { ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, contentId); if (null != metadata) { if (attempts > 5) { log.info("contentId={} found in bucket={} after waiting for {} seconds...", contentId, bucketName, totalSecondsWaited); } etag = metadata.getETag(); if (expectedChecksum.equals(getETagValue(etag))) { return etag; } } } catch (AmazonClientException e) { } attempts++; int waitNow = waitInSeconds * i; wait(waitNow); totalSecondsWaited += waitNow; } if (etag == null) { log.warn("contentId={} NOT found in bucket={} after waiting for {} seconds...", contentId, bucketName, attempts * waitInSeconds); } else { log.warn("contentId={} in bucket={} does not have the expected checksum after waiting " + "for {} seconds. S3 Checksum={} Expected Checksum={}", contentId, bucketName, attempts * waitInSeconds, getETagValue(etag), expectedChecksum); } return etag; } S3StorageProvider(String accessKey, String secretKey);  S3StorageProvider(String accessKey,
                             String secretKey,
                             Map<String, String> options);  S3StorageProvider(AmazonS3 s3Client,
                             String accessKey,
                             Map<String, String> options); @Override StorageProviderType getStorageProviderType(); Iterator<String> getSpaces(); Iterator<String> getSpaceContents(String spaceId,
                                             String prefix); List<String> getSpaceContentsChunked(String spaceId,
                                                String prefix,
                                                long maxResults,
                                                String marker); void createSpace(String spaceId); String createHiddenSpace(String spaceId, int expirationInDays); void setSpaceLifecycle(String bucketName,
                                  BucketLifecycleConfiguration config); void removeSpace(String spaceId); String addHiddenContent(String spaceId,
                                   String contentId,
                                   String contentMimeType,
                                   InputStream content); String addContent(String spaceId,
                             String contentId,
                             String contentMimeType,
                             Map<String, String> userProperties,
                             long contentSize,
                             String contentChecksum,
                             InputStream content); @Override String copyContent(String sourceSpaceId,
                              String sourceContentId,
                              String destSpaceId,
                              String destContentId); RetrievedContent getContent(String spaceId, String contentId); RetrievedContent getContent(String spaceId, String contentId, String range); void deleteContent(String spaceId, String contentId); void setContentProperties(String spaceId,
                                     String contentId,
                                     Map<String, String> contentProperties); Map<String, String> getContentProperties(String spaceId,
                                                    String contentId); @Override Map<String, String> getSpaceProperties(String spaceId); String getBucketName(String spaceId); static final String HIDDEN_SPACE_PREFIX; }
@Test public void testDoesContentExist() { setupS3Client(); expect(s3Client.getObjectMetadata(EasyMock.isA(String.class), EasyMock.isA(String.class))) .andThrow(new AmazonClientException("message")); ObjectMetadata objectMetadata = new ObjectMetadata(); String etag = "etag"; objectMetadata.setHeader(Headers.ETAG, etag); expect(s3Client.getObjectMetadata(EasyMock.isA(String.class), EasyMock.isA(String.class))) .andReturn(objectMetadata); replay(s3Client); Map<String, String> options = new HashMap<String, String>(); S3StorageProvider provider = new S3StorageProvider(s3Client, accessKey, options); String resultEtag = provider.doesContentExistWithExpectedChecksum("bucketname", "contentId", etag); assertNotNull(resultEtag); assertEquals(etag, resultEtag); }