S3BinaryStore extends AbstractBinaryStore { @Override public void removeValuesUnusedLongerThan(long minimumAge, TimeUnit timeUnit) throws BinaryStoreException { try { updateBucketLifecycle(); if (deleteUnusedNatively) { return; } Date deadline = new Date(System.currentTimeMillis() - timeUnit.toMillis(minimumAge)); supplyObjects().get().map(S3ObjectSummary::getKey).filter(k -> s3Client.getObjectTagging(new GetObjectTaggingRequest(bucketName, k)).getTagSet().stream().anyMatch( t -> UNUSED_TAG_KEY.equals(t.getKey()) && Boolean.parseBoolean(t.getValue())) && s3Client.getObjectMetadata(bucketName, k).getLastModified().before(deadline)).forEach(k -> { try { s3Client.deleteObject(bucketName, k); } catch (AmazonClientException e) { Logger.getLogger(getClass()).warn(e, JcrI18n.unableToDeleteTemporaryFile, e.getMessage()); } }); } catch (AmazonClientException e) { throw new BinaryStoreException(e); } } S3BinaryStore(String accessKey, String secretKey, String bucketName);  S3BinaryStore(String accessKey, String secretKey, String bucketName, String endPoint);  S3BinaryStore( String accessKey,
                          String secretKey,
                          String bucketName,
                          String endPoint,
                          Boolean deleteUnusedNatively ); protected  S3BinaryStore(String bucketName, AmazonS3 s3Client, boolean deleteUnusedNatively); @Override void storeExtractedText(BinaryValue binaryValue, String extractedText); @Override String getExtractedText(BinaryValue binaryValue); @Override BinaryValue storeValue(InputStream stream, boolean markAsUnused); @Override InputStream getInputStream(BinaryKey key); @Override void markAsUsed(Iterable<BinaryKey> keys); @Override void markAsUnused(Iterable<BinaryKey> keys); @Override void removeValuesUnusedLongerThan(long minimumAge, TimeUnit timeUnit); @Override Iterable<BinaryKey> getAllBinaryKeys(); void migrateUnusedMetadataToTags();  }
@Test public void testRemoveUnusedValues() throws BinaryStoreException { expect(s3Client.getBucketLifecycleConfiguration(BUCKET)).andReturn(bucketLifecycleConfiguration); if (deleteUnusedNatively) { if (!getUnusedRule(bucketLifecycleConfiguration).filter(isEnabled()).isPresent()) { s3Client.setBucketLifecycleConfiguration(eq(BUCKET), S3BinaryStoreTest.customMatcher(description, blc -> getUnusedRule(blc).filter(isEnabled()).isPresent())); EasyMock.expectLastCall(); } } else { if (getUnusedRule(bucketLifecycleConfiguration).filter(isEnabled()).isPresent()) { s3Client.setBucketLifecycleConfiguration(eq(BUCKET), S3BinaryStoreTest.customMatcher(description, blc -> getUnusedRule(blc).filter(isDisabled()).isPresent())); EasyMock.expectLastCall(); } expect(s3Client.listObjects(isA(ListObjectsRequest.class))).andReturn(objectListing); expect(objectListing.getObjectSummaries()).andReturn(Collections.emptyList()); expect(objectListing.isTruncated()).andReturn(false); expect(objectListing.isTruncated()).andReturn(false); expect(s3Client.listObjects(isA(ListObjectsRequest.class))).andReturn(objectListing); expect(objectListing.getObjectSummaries()).andReturn(Collections.emptyList()); expect(objectListing.isTruncated()).andReturn(false); expect(objectListing.isTruncated()).andReturn(false); } replayAll(); s3BinaryStore.removeValuesUnusedLongerThan(1, TimeUnit.HOURS); s3BinaryStore.removeValuesUnusedLongerThan(1, TimeUnit.HOURS); verifyAll(); }