@Test public void dontDropPathWhenPartitionDoesntExist() { when(hiveClientFactory.newInstance()).thenReturn(hiveClient); when(housekeepingMetadata.getDatabaseName()).thenReturn(DATABASE); when(housekeepingMetadata.getTableName()).thenReturn(TABLE_NAME); when(housekeepingMetadata.getPartitionName()).thenReturn(PARTITION_NAME); when(hiveMetadataCleaner.dropPartition(Mockito.any(), Mockito.any())).thenReturn(false); when(hiveMetadataCleaner.tableExists(hiveClient, DATABASE, TABLE_NAME)).thenReturn(true); expiredMetadataHandler.cleanupMetadata(housekeepingMetadata, CLEANUP_INSTANCE, false); verify(s3PathCleaner, never()).cleanupPath(housekeepingMetadata); verify(hiveMetadataCleaner, never()).dropTable(housekeepingMetadata, hiveClient); verify(housekeepingMetadata).setCleanupAttempts(1); verify(housekeepingMetadata).setHousekeepingStatus(DELETED); verify(housekeepingMetadataRepository).save(housekeepingMetadata); }
@Override public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled) { try (CleanerClient client = cleanerClientFactory.newInstance()) { boolean deleted = cleanup(client, housekeepingMetadata, instant, dryRunEnabled); if (deleted && !dryRunEnabled) { updateAttemptsAndStatus(housekeepingMetadata, DELETED); } } catch (Exception e) { updateAttemptsAndStatus(housekeepingMetadata, FAILED); log.warn("Unexpected exception when deleting metadata for table \"{}.{}\"", housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e); } }
ExpiredMetadataHandler implements MetadataHandler { @Override public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled) { try (CleanerClient client = cleanerClientFactory.newInstance()) { boolean deleted = cleanup(client, housekeepingMetadata, instant, dryRunEnabled); if (deleted && !dryRunEnabled) { updateAttemptsAndStatus(housekeepingMetadata, DELETED); } } catch (Exception e) { updateAttemptsAndStatus(housekeepingMetadata, FAILED); log.warn("Unexpected exception when deleting metadata for table \"{}.{}\"", housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e); } } }
ExpiredMetadataHandler implements MetadataHandler { @Override public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled) { try (CleanerClient client = cleanerClientFactory.newInstance()) { boolean deleted = cleanup(client, housekeepingMetadata, instant, dryRunEnabled); if (deleted && !dryRunEnabled) { updateAttemptsAndStatus(housekeepingMetadata, DELETED); } } catch (Exception e) { updateAttemptsAndStatus(housekeepingMetadata, FAILED); log.warn("Unexpected exception when deleting metadata for table \"{}.{}\"", housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e); } } ExpiredMetadataHandler(CleanerClientFactory cleanerClientFactory,
      HousekeepingMetadataRepository housekeepingMetadataRepository,
      MetadataCleaner metadataCleaner, PathCleaner pathCleaner); }
ExpiredMetadataHandler implements MetadataHandler { @Override public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled) { try (CleanerClient client = cleanerClientFactory.newInstance()) { boolean deleted = cleanup(client, housekeepingMetadata, instant, dryRunEnabled); if (deleted && !dryRunEnabled) { updateAttemptsAndStatus(housekeepingMetadata, DELETED); } } catch (Exception e) { updateAttemptsAndStatus(housekeepingMetadata, FAILED); log.warn("Unexpected exception when deleting metadata for table \"{}.{}\"", housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e); } } ExpiredMetadataHandler(CleanerClientFactory cleanerClientFactory,
      HousekeepingMetadataRepository housekeepingMetadataRepository,
      MetadataCleaner metadataCleaner, PathCleaner pathCleaner); @Override Page<HousekeepingMetadata> findRecordsToClean(LocalDateTime instant, Pageable pageable); @Override void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled); }
ExpiredMetadataHandler implements MetadataHandler { @Override public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled) { try (CleanerClient client = cleanerClientFactory.newInstance()) { boolean deleted = cleanup(client, housekeepingMetadata, instant, dryRunEnabled); if (deleted && !dryRunEnabled) { updateAttemptsAndStatus(housekeepingMetadata, DELETED); } } catch (Exception e) { updateAttemptsAndStatus(housekeepingMetadata, FAILED); log.warn("Unexpected exception when deleting metadata for table \"{}.{}\"", housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e); } } ExpiredMetadataHandler(CleanerClientFactory cleanerClientFactory,
      HousekeepingMetadataRepository housekeepingMetadataRepository,
      MetadataCleaner metadataCleaner, PathCleaner pathCleaner); @Override Page<HousekeepingMetadata> findRecordsToClean(LocalDateTime instant, Pageable pageable); @Override void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDateTime instant, boolean dryRunEnabled);  }