BackupOperation { public BackupStatus backupAllMembers(String targetDirPath, String baselineDirPath) { Properties properties = new BackupConfigFactory().withTargetDirPath(targetDirPath) .withBaselineDirPath(baselineDirPath).createBackupProperties(); return performBackup(properties); } BackupOperation(DistributionManager dm, InternalCache cache); @VisibleForTesting  BackupOperation(FlushToDiskFactory flushToDiskFactory, PrepareBackupFactory prepareBackupFactory,
      AbortBackupFactory abortBackupFactory, FinishBackupFactory finishBackupFactory,
      DistributionManager dm, InternalCache cache, BackupLockService backupLockService,
      MissingPersistentMembersProvider missingPersistentMembersProvider); BackupStatus backupAllMembers(String targetDirPath, String baselineDirPath);  }
@Test public void hasNoBackedUpDiskStoresIfNoMembers() { BackupStatus backupStatus = backupOperation.backupAllMembers(targetDirPath, baselineDirPath); assertThat(backupStatus.getBackedUpDiskStores()).hasSize(0); }
@Test public void hasNoOfflineDiskStoresIfNoMembers() { BackupStatus backupStatus = backupOperation.backupAllMembers(targetDirPath, baselineDirPath); assertThat(backupStatus.getOfflineDiskStores()).hasSize(0); }
@Test public void flushPrepareFinishOrdering() { backupOperation.backupAllMembers(targetDirPath, baselineDirPath); InOrder inOrder = inOrder(flushToDiskFactory, prepareBackupFactory, finishBackupFactory); inOrder.verify(flushToDiskFactory).createFlushToDiskStep(any(), any(), any(), any(), any()); inOrder.verify(prepareBackupFactory).createPrepareBackupStep(any(), any(), any(), any(), any(), any()); inOrder.verify(finishBackupFactory).createFinishBackupStep(any(), any(), any(), any(), any()); }
@Test public void abortIfPrepareFails() { PrepareBackupStep prepareBackupStep = mock(PrepareBackupStep.class); RuntimeException thrownBySend = new RuntimeException("thrownBySend"); when(prepareBackupFactory.createPrepareBackupStep(any(), any(), any(), any(), any(), any())) .thenReturn(prepareBackupStep); when(prepareBackupStep.send()).thenThrow(thrownBySend); assertThatThrownBy(() -> backupOperation.backupAllMembers(targetDirPath, baselineDirPath)) .isSameAs(thrownBySend); InOrder inOrder = inOrder(flushToDiskFactory, prepareBackupFactory, abortBackupFactory); inOrder.verify(flushToDiskFactory).createFlushToDiskStep(any(), any(), any(), any(), any()); inOrder.verify(prepareBackupFactory).createPrepareBackupStep(any(), any(), any(), any(), any(), any()); inOrder.verify(abortBackupFactory).createAbortBackupStep(any(), any(), any(), any(), any()); verifyNoMoreInteractions(finishBackupFactory); }
@Test public void failedToAcquireLockThrows() { when(backupLockService.obtainLock(dm)).thenReturn(false); assertThatThrownBy(() -> backupOperation.backupAllMembers(targetDirPath, baselineDirPath)) .isInstanceOf(ManagementException.class); verifyNoMoreInteractions(flushToDiskFactory, prepareBackupFactory, abortBackupFactory, finishBackupFactory); }