This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 1eb0275 GEODE-5398: Add BackupOperationTest and BackupStatusImplTest
1eb0275 is described below
commit 1eb027597291a39acfce4ab68a02c941b71d33a5
Author: Kirk Lund <[email protected]>
AuthorDate: Fri Jul 6 13:29:08 2018 -0700
GEODE-5398: Add BackupOperationTest and BackupStatusImplTest
Refactor BackupOperation to make it easier to unit test.
---
.../admin/internal/AdminDistributedSystemImpl.java | 3 +-
.../org/apache/geode/internal/SystemAdmin.java | 3 +-
.../internal/cache/backup/AbortBackupFactory.java | 6 +
.../internal/cache/backup/BackupOperation.java | 108 ++++++++++-------
.../internal/cache/backup/FinishBackupFactory.java | 6 +
.../internal/cache/backup/FlushToDiskFactory.java | 6 +
.../cache/backup/PrepareBackupFactory.java | 7 ++
.../management/internal/BackupStatusImpl.java | 14 ++-
.../internal/beans/DistributedSystemBridge.java | 2 +-
.../cli/commands/BackupDiskStoreCommand.java | 5 +-
.../cache/backup/BackupDistributedTest.java | 5 +-
.../internal/cache/backup/BackupOperationTest.java | 130 +++++++++++++++++++++
.../backup/IncrementalBackupDistributedTest.java | 20 ++--
.../PersistentPartitionedRegionTestBase.java | 5 +-
.../management/internal/BackupStatusImplTest.java | 69 +++++++++++
15 files changed, 327 insertions(+), 62 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/admin/internal/AdminDistributedSystemImpl.java
b/geode-core/src/main/java/org/apache/geode/admin/internal/AdminDistributedSystemImpl.java
index d6320c8..5c665ae 100755
---
a/geode-core/src/main/java/org/apache/geode/admin/internal/AdminDistributedSystemImpl.java
+++
b/geode-core/src/main/java/org/apache/geode/admin/internal/AdminDistributedSystemImpl.java
@@ -2322,7 +2322,8 @@ public class AdminDistributedSystemImpl implements
org.apache.geode.admin.AdminD
public static BackupStatus backupAllMembers(DistributionManager dm, File
targetDir,
File baselineDir) throws AdminException {
String baselineDirectory = baselineDir == null ? null :
baselineDir.toString();
- return new BackupOperation().backupAllMembers(dm, targetDir.toString(),
baselineDirectory);
+ return new BackupOperation(dm,
dm.getCache()).backupAllMembers(targetDir.toString(),
+ baselineDirectory);
}
public Map<DistributedMember, Set<PersistentID>> compactAllDiskStores()
throws AdminException {
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java
b/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java
index 9ebd211..c6d3738 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java
@@ -619,7 +619,8 @@ public class SystemAdmin {
// Baseline directory should be null if it was not provided on the command
line
BackupStatus status =
- new BackupOperation().backupAllMembers(ads.getDistributionManager(),
targetDir,
+ new BackupOperation(ads.getDistributionManager(),
ads.getCache()).backupAllMembers(
+ targetDir,
SystemAdmin.baselineDir);
boolean incomplete = !status.getOfflineDiskStores().isEmpty();
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/AbortBackupFactory.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/AbortBackupFactory.java
index ee3336e..b9cbd28 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/AbortBackupFactory.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/AbortBackupFactory.java
@@ -42,4 +42,10 @@ class AbortBackupFactory {
HashSet<PersistentID> persistentIds) {
return new BackupResponse(sender, persistentIds);
}
+
+ AbortBackupStep createAbortBackupStep(DistributionManager dm,
InternalDistributedMember member,
+ InternalCache cache, Set<InternalDistributedMember> recipients,
+ AbortBackupFactory abortBackupFactory) {
+ return new AbortBackupStep(dm, member, cache, recipients,
abortBackupFactory);
+ }
}
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupOperation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupOperation.java
index aa666c6..643b23d 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupOperation.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupOperation.java
@@ -20,99 +20,129 @@ import java.util.Properties;
import java.util.Set;
import org.apache.geode.admin.internal.AdminDistributedSystemImpl;
+import org.apache.geode.annotations.TestingOnly;
import org.apache.geode.cache.persistence.PersistentID;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.internal.DistributionManager;
import
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.management.BackupStatus;
import org.apache.geode.management.ManagementException;
import org.apache.geode.management.internal.BackupStatusImpl;
+/**
+ * Performs backup of all members.
+ */
public class BackupOperation {
private final FlushToDiskFactory flushToDiskFactory;
private final PrepareBackupFactory prepareBackupFactory;
private final AbortBackupFactory abortBackupFactory;
private final FinishBackupFactory finishBackupFactory;
+ private final DistributionManager dm;
+ private final InternalCache cache;
+ private final BackupLockService backupLockService;
+ private final MissingPersistentMembersProvider
missingPersistentMembersProvider;
- public BackupOperation() {
+ public BackupOperation(DistributionManager dm, InternalCache cache) {
this(new FlushToDiskFactory(), new PrepareBackupFactory(), new
AbortBackupFactory(),
- new FinishBackupFactory());
+ new FinishBackupFactory(), dm, cache, new BackupLockService(),
+ new DefaultMissingPersistentMembersProvider());
}
+ @TestingOnly
BackupOperation(FlushToDiskFactory flushToDiskFactory, PrepareBackupFactory
prepareBackupFactory,
- AbortBackupFactory abortBackupFactory, FinishBackupFactory
finishBackupFactory) {
+ AbortBackupFactory abortBackupFactory, FinishBackupFactory
finishBackupFactory,
+ DistributionManager dm, InternalCache cache, BackupLockService
backupLockService,
+ MissingPersistentMembersProvider missingPersistentMembersProvider) {
this.flushToDiskFactory = flushToDiskFactory;
this.prepareBackupFactory = prepareBackupFactory;
this.abortBackupFactory = abortBackupFactory;
this.finishBackupFactory = finishBackupFactory;
+ this.dm = dm;
+ this.cache = cache;
+ this.backupLockService = backupLockService;
+ this.missingPersistentMembersProvider = missingPersistentMembersProvider;
}
- public BackupStatus backupAllMembers(DistributionManager dm, String
targetDirPath,
- String baselineDirPath) {
+ public BackupStatus backupAllMembers(String targetDirPath, String
baselineDirPath) {
Properties properties = new
BackupConfigFactory().withTargetDirPath(targetDirPath)
.withBaselineDirPath(baselineDirPath).createBackupProperties();
- return performBackup(dm, properties);
+ return performBackup(properties);
}
- private BackupStatus performBackup(DistributionManager dm, Properties
properties)
- throws ManagementException {
- BackupLockService backupLockService = new BackupLockService();
- BackupStatus status;
+ private BackupStatus performBackup(Properties properties) throws
ManagementException {
if (backupLockService.obtainLock(dm)) {
try {
- Set<PersistentID> missingMembers =
- AdminDistributedSystemImpl.getMissingPersistentMembers(dm);
- Set<InternalDistributedMember> recipients =
dm.getOtherDistributionManagerIds();
-
- BackupDataStoreResult result = performBackupSteps(dm, recipients,
properties);
-
- // It's possible that when calling getMissingPersistentMembers, some
members are
- // still creating/recovering regions, and at FinishBackupRequest.send,
the
- // regions at the members are ready. Logically, since the members in
successfulMembers
- // should override the previous missingMembers
- for (Set<PersistentID> onlineMembersIds :
result.getSuccessfulMembers().values()) {
- missingMembers.removeAll(onlineMembersIds);
- }
-
-
result.getExistingDataStores().keySet().removeAll(result.getSuccessfulMembers().keySet());
- for (Set<PersistentID> lostMembersIds :
result.getExistingDataStores().values()) {
- missingMembers.addAll(lostMembersIds);
- }
- status = new BackupStatusImpl(result.getSuccessfulMembers(),
missingMembers);
+ return performBackupUnderLock(properties);
} finally {
backupLockService.releaseLock(dm);
}
-
} else {
throw new ManagementException(
LocalizedStrings.DistributedSystem_BACKUP_ALREADY_IN_PROGRESS.toLocalizedString());
}
- return status;
}
- private BackupDataStoreResult performBackupSteps(DistributionManager dm, Set
recipients,
- Properties properties) {
- new FlushToDiskStep(dm, dm.getId(), dm.getCache(), recipients,
flushToDiskFactory).send();
+ private BackupStatus performBackupUnderLock(Properties properties) {
+ Set<PersistentID> missingMembers =
+ missingPersistentMembersProvider.getMissingPersistentMembers(dm);
+ Set<InternalDistributedMember> recipients =
dm.getOtherDistributionManagerIds();
+
+ BackupDataStoreResult result = performBackupSteps(dm.getId(), recipients,
properties);
+
+ // It's possible that when calling getMissingPersistentMembers, some
members are
+ // still creating/recovering regions, and at FinishBackupRequest.send, the
+ // regions at the members are ready. Logically, since the members in
successfulMembers
+ // should override the previous missingMembers
+ for (Set<PersistentID> onlineMembersIds :
result.getSuccessfulMembers().values()) {
+ missingMembers.removeAll(onlineMembersIds);
+ }
+
+
result.getExistingDataStores().keySet().removeAll(result.getSuccessfulMembers().keySet());
+ for (Set<PersistentID> lostMembersIds :
result.getExistingDataStores().values()) {
+ missingMembers.addAll(lostMembersIds);
+ }
+ return new BackupStatusImpl(result.getSuccessfulMembers(), missingMembers);
+ }
+
+ private BackupDataStoreResult performBackupSteps(InternalDistributedMember
member,
+ Set<InternalDistributedMember> recipients, Properties properties) {
+ flushToDiskFactory.createFlushToDiskStep(dm, member, cache, recipients,
flushToDiskFactory)
+ .send();
boolean abort = true;
Map<DistributedMember, Set<PersistentID>> successfulMembers;
Map<DistributedMember, Set<PersistentID>> existingDataStores;
try {
- existingDataStores = new PrepareBackupStep(dm, dm.getId(),
dm.getCache(), recipients,
- prepareBackupFactory, properties).send();
+ PrepareBackupStep prepareBackupStep =
+ prepareBackupFactory.createPrepareBackupStep(dm, member, cache,
recipients,
+ prepareBackupFactory, properties);
+ existingDataStores = prepareBackupStep.send();
abort = false;
} finally {
if (abort) {
- new AbortBackupStep(dm, dm.getId(), dm.getCache(), recipients,
abortBackupFactory)
+ abortBackupFactory.createAbortBackupStep(dm, member, cache,
recipients, abortBackupFactory)
.send();
successfulMembers = Collections.emptyMap();
} else {
- successfulMembers = new FinishBackupStep(dm, dm.getId(),
dm.getCache(), recipients,
- finishBackupFactory).send();
+ successfulMembers =
+ finishBackupFactory.createFinishBackupStep(dm, member, cache,
recipients,
+ finishBackupFactory).send();
}
}
return new BackupDataStoreResult(existingDataStores, successfulMembers);
}
+
+ interface MissingPersistentMembersProvider {
+ Set<PersistentID> getMissingPersistentMembers(DistributionManager dm);
+ }
+
+ private static class DefaultMissingPersistentMembersProvider
+ implements MissingPersistentMembersProvider {
+ public Set<PersistentID> getMissingPersistentMembers(DistributionManager
dm) {
+ return AdminDistributedSystemImpl.getMissingPersistentMembers(dm);
+ }
+ }
}
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FinishBackupFactory.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FinishBackupFactory.java
index e7fa1e5..b2d7c6d 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FinishBackupFactory.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FinishBackupFactory.java
@@ -42,4 +42,10 @@ class FinishBackupFactory {
HashSet<PersistentID> persistentIds) {
return new BackupResponse(sender, persistentIds);
}
+
+ FinishBackupStep createFinishBackupStep(DistributionManager dm,
InternalDistributedMember member,
+ InternalCache cache, Set<InternalDistributedMember> recipients,
+ FinishBackupFactory finishBackupFactory) {
+ return new FinishBackupStep(dm, member, cache, recipients,
finishBackupFactory);
+ }
}
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FlushToDiskFactory.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FlushToDiskFactory.java
index abb0eb4..453a37b 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FlushToDiskFactory.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FlushToDiskFactory.java
@@ -40,4 +40,10 @@ class FlushToDiskFactory {
return new FlushToDiskResponse(sender);
}
+ FlushToDiskStep createFlushToDiskStep(DistributionManager dm,
InternalDistributedMember member,
+ InternalCache cache, Set<InternalDistributedMember> recipients,
+ FlushToDiskFactory flushToDiskFactory) {
+ return new FlushToDiskStep(dm, member, cache, recipients,
flushToDiskFactory);
+ }
+
}
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackupFactory.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackupFactory.java
index 4a85db1..757aebc 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackupFactory.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackupFactory.java
@@ -50,6 +50,13 @@ class PrepareBackupFactory {
return new BackupResponse(sender, persistentIds);
}
+ PrepareBackupStep createPrepareBackupStep(DistributionManager dm,
+ InternalDistributedMember member,
+ InternalCache cache, Set<InternalDistributedMember> recipients,
+ PrepareBackupFactory prepareBackupFactory, Properties properties) {
+ return new PrepareBackupStep(dm, member, cache, recipients,
prepareBackupFactory, properties);
+ }
+
private String cleanSpecialCharacters(String string) {
return string.replaceAll("[^\\w]+", "_");
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/BackupStatusImpl.java
b/geode-core/src/main/java/org/apache/geode/management/internal/BackupStatusImpl.java
index 42a45d5..e2321e1 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/BackupStatusImpl.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/BackupStatusImpl.java
@@ -24,8 +24,6 @@ import org.apache.geode.management.BackupStatus;
/**
* Holds the result of a backup operation.
- *
- *
*/
public class BackupStatusImpl implements BackupStatus, Serializable {
private static final long serialVersionUID = 3704172840296221840L;
@@ -35,15 +33,22 @@ public class BackupStatusImpl implements BackupStatus,
Serializable {
public BackupStatusImpl(Map<DistributedMember, Set<PersistentID>>
backedUpDiskStores,
Set<PersistentID> offlineDiskStores) {
- super();
+ if (backedUpDiskStores == null) {
+ throw new IllegalArgumentException("backedUpDiskStores must not be
null");
+ }
+ if (offlineDiskStores == null) {
+ throw new IllegalArgumentException("offlineDiskStores must not be null");
+ }
this.backedUpDiskStores = backedUpDiskStores;
this.offlineDiskStores = offlineDiskStores;
}
+ @Override
public Map<DistributedMember, Set<PersistentID>> getBackedUpDiskStores() {
return backedUpDiskStores;
}
+ @Override
public Set<PersistentID> getOfflineDiskStores() {
return offlineDiskStores;
}
@@ -53,7 +58,4 @@ public class BackupStatusImpl implements BackupStatus,
Serializable {
return "BackupStatus[backedUpDiskStores=" + backedUpDiskStores + ",
offlineDiskStores="
+ offlineDiskStores + "]";
}
-
-
-
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java
b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java
index 037ffc4..2097726 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java
@@ -477,7 +477,7 @@ public class DistributedSystemBridge {
*/
public DiskBackupStatus backupAllMembers(String targetDirPath, String
baselineDirPath) {
BackupStatus result =
- new BackupOperation().backupAllMembers(dm, targetDirPath,
baselineDirPath);
+ new BackupOperation(dm, dm.getCache()).backupAllMembers(targetDirPath,
baselineDirPath);
DiskBackupStatusImpl diskBackupStatus = new DiskBackupStatusImpl();
diskBackupStatus.generateBackedUpDiskStores(result.getBackedUpDiskStores());
diskBackupStatus.generateOfflineDiskStores(result.getOfflineDiskStores());
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java
index b4fb469..366d187 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java
@@ -60,9 +60,10 @@ public class BackupDiskStoreCommand extends
InternalGfshCommand {
BackupStatus backupStatus;
if (baselineDir != null && !baselineDir.isEmpty()) {
- backupStatus = new BackupOperation().backupAllMembers(dm, targetDir,
baselineDir);
+ backupStatus =
+ new BackupOperation(dm, dm.getCache()).backupAllMembers(targetDir,
baselineDir);
} else {
- backupStatus = new BackupOperation().backupAllMembers(dm, targetDir,
null);
+ backupStatus = new BackupOperation(dm,
dm.getCache()).backupAllMembers(targetDir, null);
}
Map<DistributedMember, Set<PersistentID>> backedupMemberDiskstoreMap =
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupDistributedTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupDistributedTest.java
index a0a3653..ebc4372 100755
---
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupDistributedTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupDistributedTest.java
@@ -700,8 +700,9 @@ public class BackupDistributedTest extends
PersistentPartitionedRegionTestBase {
private BackupStatus backupMember(final VM vm) {
return vm.invoke("backup", () -> {
try {
- return new
BackupOperation().backupAllMembers(getCache().getDistributionManager(),
- backupBaseDir.toString(), null);
+ return new BackupOperation(getCache().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ backupBaseDir.toString(), null);
} catch (ManagementException e) {
throw new RuntimeException(e);
}
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupOperationTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupOperationTest.java
new file mode 100644
index 0000000..6adb998
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/BackupOperationTest.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.backup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.InOrder;
+
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.internal.cache.InternalCache;
+import
org.apache.geode.internal.cache.backup.BackupOperation.MissingPersistentMembersProvider;
+import org.apache.geode.management.BackupStatus;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class BackupOperationTest {
+
+ private FlushToDiskFactory flushToDiskFactory;
+ private PrepareBackupFactory prepareBackupFactory;
+ private AbortBackupFactory abortBackupFactory;
+ private FinishBackupFactory finishBackupFactory;
+ private DistributionManager dm;
+ private InternalCache cache;
+ private BackupLockService backupLockService;
+ private MissingPersistentMembersProvider missingPersistentMembersProvider;
+
+ private String targetDirPath;
+ private String baselineDirPath;
+
+ private BackupOperation backupOperation;
+
+ @Before
+ public void setUp() {
+ flushToDiskFactory = mock(FlushToDiskFactory.class, RETURNS_DEEP_STUBS);
+ prepareBackupFactory = mock(PrepareBackupFactory.class,
RETURNS_DEEP_STUBS);
+ abortBackupFactory = mock(AbortBackupFactory.class, RETURNS_DEEP_STUBS);
+ finishBackupFactory = mock(FinishBackupFactory.class, RETURNS_DEEP_STUBS);
+ dm = mock(DistributionManager.class);
+ cache = mock(InternalCache.class);
+ backupLockService = mock(BackupLockService.class);
+ missingPersistentMembersProvider =
mock(MissingPersistentMembersProvider.class);
+
+ when(backupLockService.obtainLock(dm)).thenReturn(true);
+
+ targetDirPath = "targetDirPath";
+ baselineDirPath = "baselineDirPath";
+
+ backupOperation = new BackupOperation(flushToDiskFactory,
prepareBackupFactory,
+ abortBackupFactory, finishBackupFactory, dm, cache, backupLockService,
+ missingPersistentMembersProvider);
+ }
+
+ @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());
+
+ verifyZeroInteractions(finishBackupFactory);
+ }
+
+ @Test
+ public void failedToAcquireLockThrows() {
+ when(backupLockService.obtainLock(dm)).thenReturn(false);
+
+ assertThatThrownBy(() -> backupOperation.backupAllMembers(targetDirPath,
baselineDirPath))
+ .isInstanceOf(ManagementException.class);
+
+ verifyZeroInteractions(flushToDiskFactory, prepareBackupFactory,
abortBackupFactory,
+ finishBackupFactory);
+ }
+}
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
index 49bc528..d1316f7 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
@@ -209,8 +209,9 @@ public class IncrementalBackupDistributedTest extends
JUnit4CacheTestCase {
private BackupStatus baseline(VM vm) {
return vm.invoke(() -> {
try {
- return new
BackupOperation().backupAllMembers(getSystem().getDistributionManager(),
- getBaselineDir().toString(), null);
+ return new BackupOperation(getSystem().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ getBaselineDir().toString(), null);
} catch (ManagementException e) {
throw new RuntimeException(e);
}
@@ -220,8 +221,9 @@ public class IncrementalBackupDistributedTest extends
JUnit4CacheTestCase {
private BackupStatus incremental(VM vm) {
return vm.invoke(() -> {
try {
- return new
BackupOperation().backupAllMembers(getSystem().getDistributionManager(),
- getIncrementalDir().toString(), getBaselineBackupDir().toString());
+ return new BackupOperation(getSystem().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ getIncrementalDir().toString(),
getBaselineBackupDir().toString());
} catch (ManagementException e) {
throw new RuntimeException(e);
}
@@ -231,8 +233,9 @@ public class IncrementalBackupDistributedTest extends
JUnit4CacheTestCase {
private BackupStatus incremental2(VM vm) {
return vm.invoke(() -> {
try {
- return new
BackupOperation().backupAllMembers(getSystem().getDistributionManager(),
- getIncremental2Dir().toString(),
getIncrementalBackupDir().toString());
+ return new BackupOperation(getSystem().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ getIncremental2Dir().toString(),
getIncrementalBackupDir().toString());
} catch (ManagementException e) {
throw new RuntimeException(e);
}
@@ -940,8 +943,9 @@ public class IncrementalBackupDistributedTest extends
JUnit4CacheTestCase {
@Override
public Object call() {
try {
- return new
BackupOperation().backupAllMembers(getSystem().getDistributionManager(),
- getIncrementalDir().toString(), this.baselineDir.toString());
+ return new BackupOperation(getSystem().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ getIncrementalDir().toString(), this.baselineDir.toString());
} catch (ManagementException e) {
throw new RuntimeException(e);
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionTestBase.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionTestBase.java
index 8bb0644..58e5fc7 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionTestBase.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionTestBase.java
@@ -313,8 +313,9 @@ public abstract class PersistentPartitionedRegionTestBase
extends JUnit4CacheTes
protected BackupStatus backup(final VM vm) {
return vm.invoke("backup", () -> {
try {
- return new
BackupOperation().backupAllMembers(getSystem().getDistributionManager(),
- getBackupDir().toString(), null);
+ return new BackupOperation(getSystem().getDistributionManager(),
getCache())
+ .backupAllMembers(
+ getBackupDir().toString(), null);
} catch (ManagementException e) {
throw new RuntimeException(e);
}
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/BackupStatusImplTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/BackupStatusImplTest.java
new file mode 100644
index 0000000..0f165ec
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/BackupStatusImplTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.persistence.PersistentID;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.management.BackupStatus;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class BackupStatusImplTest {
+
+ private Map<DistributedMember, Set<PersistentID>> backedUpDiskStores;
+ private Set<PersistentID> offlineDiskStores;
+
+ @Before
+ public void setUp() {
+ backedUpDiskStores = new HashMap<>();
+ offlineDiskStores = new HashSet<>();
+ }
+
+ @Test
+ public void getBackedUpDiskStores() {
+ BackupStatus backupStatus = new BackupStatusImpl(backedUpDiskStores,
offlineDiskStores);
+
assertThat(backupStatus.getBackedUpDiskStores()).isEqualTo(backedUpDiskStores);
+ }
+
+ @Test
+ public void backedUpDiskStoresIsRequired() {
+ assertThatThrownBy(() -> new BackupStatusImpl(null, offlineDiskStores))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void getOfflineDiskStores() {
+ BackupStatus backupStatus = new BackupStatusImpl(backedUpDiskStores,
offlineDiskStores);
+
assertThat(backupStatus.getOfflineDiskStores()).isEqualTo(offlineDiskStores);
+ }
+
+ @Test
+ public void offlineDiskStoresIsRequired() {
+ assertThatThrownBy(() -> new BackupStatusImpl(backedUpDiskStores, null))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+}