@Test void noBytesDeletedMetricWhenFileDeletionFails() { S3Client mockS3Client = mock(S3Client.class); s3PathCleaner = new S3PathCleaner(mockS3Client, s3SentinelFilesCleaner, bytesDeletedReporter); when(mockS3Client.doesObjectExist(bucket, key1)).thenReturn(true); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(10); when(mockS3Client.getObjectMetadata(bucket, key1)).thenReturn(objectMetadata); doThrow(AmazonServiceException.class).when(mockS3Client).deleteObject(bucket, key1); housekeepingPath.setPath(absolutePath + "/file1"); assertThatExceptionOfType(AmazonServiceException.class) .isThrownBy(() -> s3PathCleaner.cleanupPath(housekeepingPath)); verifyNoInteractions(bytesDeletedReporter); }
@Override @TimedTaggable("s3-paths-deleted") public void cleanupPath(HousekeepingEntity housekeepingEntity) { S3SchemeURI s3SchemeURI = new S3SchemeURI(housekeepingEntity.getPath()); String key = s3SchemeURI.getKey(); String bucket = s3SchemeURI.getBucket(); S3BytesDeletedCalculator bytesDeletedCalculator = new S3BytesDeletedCalculator(s3Client); boolean isFile = s3Client.doesObjectExist(bucket, key); try { if (isFile) { deleteFile(bucket, key, bytesDeletedCalculator); } else { deleteFilesInDirectory(bucket, key, bytesDeletedCalculator); deleteSentinelFiles(s3SchemeURI, key, bucket, housekeepingEntity.getTableName()); } } finally { long bytesDeleted = bytesDeletedCalculator.getBytesDeleted(); if (bytesDeleted > 0) { bytesDeletedReporter.reportTaggable(bytesDeleted, housekeepingEntity, FileSystemType.S3); } } }
S3PathCleaner implements PathCleaner { @Override @TimedTaggable("s3-paths-deleted") public void cleanupPath(HousekeepingEntity housekeepingEntity) { S3SchemeURI s3SchemeURI = new S3SchemeURI(housekeepingEntity.getPath()); String key = s3SchemeURI.getKey(); String bucket = s3SchemeURI.getBucket(); S3BytesDeletedCalculator bytesDeletedCalculator = new S3BytesDeletedCalculator(s3Client); boolean isFile = s3Client.doesObjectExist(bucket, key); try { if (isFile) { deleteFile(bucket, key, bytesDeletedCalculator); } else { deleteFilesInDirectory(bucket, key, bytesDeletedCalculator); deleteSentinelFiles(s3SchemeURI, key, bucket, housekeepingEntity.getTableName()); } } finally { long bytesDeleted = bytesDeletedCalculator.getBytesDeleted(); if (bytesDeleted > 0) { bytesDeletedReporter.reportTaggable(bytesDeleted, housekeepingEntity, FileSystemType.S3); } } } }
S3PathCleaner implements PathCleaner { @Override @TimedTaggable("s3-paths-deleted") public void cleanupPath(HousekeepingEntity housekeepingEntity) { S3SchemeURI s3SchemeURI = new S3SchemeURI(housekeepingEntity.getPath()); String key = s3SchemeURI.getKey(); String bucket = s3SchemeURI.getBucket(); S3BytesDeletedCalculator bytesDeletedCalculator = new S3BytesDeletedCalculator(s3Client); boolean isFile = s3Client.doesObjectExist(bucket, key); try { if (isFile) { deleteFile(bucket, key, bytesDeletedCalculator); } else { deleteFilesInDirectory(bucket, key, bytesDeletedCalculator); deleteSentinelFiles(s3SchemeURI, key, bucket, housekeepingEntity.getTableName()); } } finally { long bytesDeleted = bytesDeletedCalculator.getBytesDeleted(); if (bytesDeleted > 0) { bytesDeletedReporter.reportTaggable(bytesDeleted, housekeepingEntity, FileSystemType.S3); } } } S3PathCleaner(S3Client s3Client, SentinelFilesCleaner sentinelFilesCleaner,
      BytesDeletedReporter bytesDeletedReporter); }
S3PathCleaner implements PathCleaner { @Override @TimedTaggable("s3-paths-deleted") public void cleanupPath(HousekeepingEntity housekeepingEntity) { S3SchemeURI s3SchemeURI = new S3SchemeURI(housekeepingEntity.getPath()); String key = s3SchemeURI.getKey(); String bucket = s3SchemeURI.getBucket(); S3BytesDeletedCalculator bytesDeletedCalculator = new S3BytesDeletedCalculator(s3Client); boolean isFile = s3Client.doesObjectExist(bucket, key); try { if (isFile) { deleteFile(bucket, key, bytesDeletedCalculator); } else { deleteFilesInDirectory(bucket, key, bytesDeletedCalculator); deleteSentinelFiles(s3SchemeURI, key, bucket, housekeepingEntity.getTableName()); } } finally { long bytesDeleted = bytesDeletedCalculator.getBytesDeleted(); if (bytesDeleted > 0) { bytesDeletedReporter.reportTaggable(bytesDeleted, housekeepingEntity, FileSystemType.S3); } } } S3PathCleaner(S3Client s3Client, SentinelFilesCleaner sentinelFilesCleaner,
      BytesDeletedReporter bytesDeletedReporter); @Override @TimedTaggable("s3-paths-deleted") void cleanupPath(HousekeepingEntity housekeepingEntity); }
S3PathCleaner implements PathCleaner { @Override @TimedTaggable("s3-paths-deleted") public void cleanupPath(HousekeepingEntity housekeepingEntity) { S3SchemeURI s3SchemeURI = new S3SchemeURI(housekeepingEntity.getPath()); String key = s3SchemeURI.getKey(); String bucket = s3SchemeURI.getBucket(); S3BytesDeletedCalculator bytesDeletedCalculator = new S3BytesDeletedCalculator(s3Client); boolean isFile = s3Client.doesObjectExist(bucket, key); try { if (isFile) { deleteFile(bucket, key, bytesDeletedCalculator); } else { deleteFilesInDirectory(bucket, key, bytesDeletedCalculator); deleteSentinelFiles(s3SchemeURI, key, bucket, housekeepingEntity.getTableName()); } } finally { long bytesDeleted = bytesDeletedCalculator.getBytesDeleted(); if (bytesDeleted > 0) { bytesDeletedReporter.reportTaggable(bytesDeleted, housekeepingEntity, FileSystemType.S3); } } } S3PathCleaner(S3Client s3Client, SentinelFilesCleaner sentinelFilesCleaner,
      BytesDeletedReporter bytesDeletedReporter); @Override @TimedTaggable("s3-paths-deleted") void cleanupPath(HousekeepingEntity housekeepingEntity);  }