[
https://issues.apache.org/jira/browse/GEODE-4106?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16295366#comment-16295366
]
ASF GitHub Bot commented on GEODE-4106:
---------------------------------------
nreich closed pull request #1173: GEODE-4106: Fix relative path destinations
for backups
URL: https://github.com/apache/geode/pull/1173
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestination.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestination.java
index 997ab10323..2955d6e7aa 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestination.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestination.java
@@ -73,9 +73,9 @@ private void backupDiskInitFiles(Map<DiskStore, Path>
diskInitFiles) throws IOEx
for (Map.Entry<DiskStore, Path> entry : diskInitFiles.entrySet()) {
Path destinationDirectory = getOplogBackupDir(entry.getKey(),
((DiskStoreImpl) entry.getKey()).getInforFileDirIndex());
-
Files.createDirectories(destinationDirectory.resolve(destinationDirectory));
- Files.copy(entry.getValue(),
destinationDirectory.resolve(destinationDirectory)
- .resolve(entry.getValue().getFileName()),
StandardCopyOption.COPY_ATTRIBUTES);
+ Files.createDirectories(destinationDirectory);
+ Files.copy(entry.getValue(),
destinationDirectory.resolve(entry.getValue().getFileName()),
+ StandardCopyOption.COPY_ATTRIBUTES);
}
}
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestinationTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestinationTest.java
index 752d88cb41..a969a0542b 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestinationTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/FileSystemBackupDestinationTest.java
@@ -28,12 +28,18 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
import org.apache.geode.internal.cache.DiskStoreImpl;
import org.apache.geode.internal.cache.GemFireCacheImpl;
@@ -42,7 +48,9 @@
import org.apache.geode.test.junit.categories.IntegrationTest;
@Category(IntegrationTest.class)
+@RunWith(JUnitParamsRunner.class)
public class FileSystemBackupDestinationTest {
+ private static final Path RELATIVE_TARGET_DIR = Paths.get("backupTest");
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();
@@ -60,17 +68,26 @@ public void setup() throws IOException {
when(restoreScript.generate(any())).thenReturn(tempDir.newFile());
}
+ @After
+ public void tearDown() throws IOException {
+ // Testing relative paths forces creation of files in working dir instead
of temporary folder
+ if (Files.exists(RELATIVE_TARGET_DIR)) {
+ FileUtils.deleteDirectory(RELATIVE_TARGET_DIR.toFile());
+ }
+ }
+
@Test
- public void userFilesAreBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void userFilesAreBackedUp(boolean useRelativePath) throws Exception {
Path userFile = tempDir.newFile("userFile").toPath();
Path userSubdir = tempDir.newFolder("userSubDir").toPath();
Path userFileInDir = Files.write(userSubdir.resolve("fileInDir"), new
byte[] {});
backupDefinition.addUserFilesToBackup(userFile);
backupDefinition.addUserFilesToBackup(userSubdir);
- executeBackup();
+ executeBackup(useRelativePath);
- Path userDir = targetDir.resolve(USER_FILES_DIRECTORY);
+ Path userDir = getTargetDir(useRelativePath).resolve(USER_FILES_DIRECTORY);
assertThat(userDir.resolve(userFile.getFileName())).exists();
assertThat(userDir.resolve(userSubdir.getFileName())).exists();
assertThat(userDir.resolve(userSubdir.getFileName()).resolve(userFileInDir.getFileName()))
@@ -78,16 +95,17 @@ public void userFilesAreBackedUp() throws Exception {
}
@Test
- public void deployedJarsAreBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void deployedJarsAreBackedUp(boolean useRelativePath) throws
Exception {
Path jarFile = tempDir.newFile("jarFile").toPath();
Path jarSubdir = tempDir.newFolder("jarSubdir").toPath();
Path jarInSubdir = Files.write(jarSubdir.resolve("jarInSubdir"), new
byte[] {});
backupDefinition.addDeployedJarToBackup(jarFile);
backupDefinition.addDeployedJarToBackup(jarSubdir);
- executeBackup();
+ executeBackup(useRelativePath);
- Path userDir = targetDir.resolve(DEPLOYED_JARS_DIRECTORY);
+ Path userDir =
getTargetDir(useRelativePath).resolve(DEPLOYED_JARS_DIRECTORY);
assertThat(userDir.resolve(jarFile.getFileName())).exists();
assertThat(userDir.resolve(jarSubdir.getFileName())).exists();
assertThat(userDir.resolve(jarSubdir.getFileName()).resolve(jarInSubdir.getFileName()))
@@ -95,21 +113,23 @@ public void deployedJarsAreBackedUp() throws Exception {
}
@Test
- public void configFilesAreBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void configFilesAreBackedUp(boolean useRelativePath) throws Exception
{
Path cacheXml = tempDir.newFile("cache.xml").toPath();
Path propertyFile = tempDir.newFile("properties").toPath();
backupDefinition.addConfigFileToBackup(cacheXml);
backupDefinition.addConfigFileToBackup(propertyFile);
- executeBackup();
+ executeBackup(useRelativePath);
- Path configDir = targetDir.resolve(CONFIG_DIRECTORY);
+ Path configDir = getTargetDir(useRelativePath).resolve(CONFIG_DIRECTORY);
assertThat(configDir.resolve(cacheXml.getFileName())).exists();
assertThat(configDir.resolve(propertyFile.getFileName())).exists();
}
@Test
- public void oplogFilesAreBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void oplogFilesAreBackedUp(boolean useRelativePath) throws Exception {
DiskStoreImpl diskStore = mock(DiskStoreImpl.class);
when(diskStore.getDiskStoreID()).thenReturn(new DiskStoreID(1, 2));
Oplog oplog = mock(Oplog.class);
@@ -122,9 +142,9 @@ public void oplogFilesAreBackedUp() throws Exception {
backupDefinition.addOplogFileToBackup(diskStore,
oplog.getDrfFile().toPath());
backupDefinition.addOplogFileToBackup(diskStore,
oplog.getKrfFile().toPath());
- executeBackup();
+ executeBackup(useRelativePath);
- Path diskStoreDir = targetDir.resolve(DATA_STORES_DIRECTORY)
+ Path diskStoreDir =
getTargetDir(useRelativePath).resolve(DATA_STORES_DIRECTORY)
.resolve(GemFireCacheImpl.getDefaultDiskStoreName() + "_1-2");
assertThat(diskStoreDir.resolve("dir1").resolve("crf")).exists();
assertThat(diskStoreDir.resolve("dir1").resolve("drf")).exists();
@@ -132,7 +152,8 @@ public void oplogFilesAreBackedUp() throws Exception {
}
@Test
- public void diskInitFilesAreBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void diskInitFilesAreBackedUp(boolean useRelativePath) throws
Exception {
DiskStoreImpl diskStore1 = mock(DiskStoreImpl.class);
when(diskStore1.getDiskStoreID()).thenReturn(new DiskStoreID(1, 2));
when(diskStore1.getInforFileDirIndex()).thenReturn(1);
@@ -146,54 +167,63 @@ public void diskInitFilesAreBackedUp() throws Exception {
backupDefinition.addDiskInitFile(diskStore1, initFile1);
backupDefinition.addDiskInitFile(diskStore2, initFile2);
- executeBackup();
+ executeBackup(useRelativePath);
- Path diskStoreDir = targetDir.resolve(DATA_STORES_DIRECTORY)
+ Path diskStoreDir =
getTargetDir(useRelativePath).resolve(DATA_STORES_DIRECTORY)
.resolve(GemFireCacheImpl.getDefaultDiskStoreName() + "_1-2");
assertThat(diskStoreDir.resolve("dir1").resolve("initFile1")).exists();
assertThat(diskStoreDir.resolve("dir2").resolve("initFile2")).exists();
}
@Test
- public void restoreScriptIsBackedUp() throws Exception {
+ @Parameters({"true", "false"})
+ public void restoreScriptIsBackedUp(boolean useRelativePath) throws
Exception {
Path restoreScriptPath = tempDir.newFile("restoreScript").toPath();
when(restoreScript.generate(any())).thenReturn(restoreScriptPath.toFile());
backupDefinition.setRestoreScript(restoreScript);
- executeBackup();
+ executeBackup(useRelativePath);
- assertThat(targetDir.resolve("restoreScript")).exists();
+
assertThat(getTargetDir(useRelativePath).resolve("restoreScript")).exists();
}
@Test
- public void backupContainsReadMe() throws IOException {
- executeBackup();
+ @Parameters({"true", "false"})
+ public void backupContainsReadMe(boolean useRelativePath) throws IOException
{
+ executeBackup(useRelativePath);
- assertThat(targetDir.resolve(README_FILE)).exists();
+ assertThat(getTargetDir(useRelativePath).resolve(README_FILE)).exists();
}
@Test
- public void leavesBehindIncompleteFileOnFailure() throws Exception {
+ @Parameters({"true", "false"})
+ public void leavesBehindIncompleteFileOnFailure(boolean useRelativePath)
throws Exception {
Path notCreatedFile =
tempDir.newFolder("dir1").toPath().resolve("notCreated");
backupDefinition.addDeployedJarToBackup(notCreatedFile);
try {
- executeBackup();
+ executeBackup(useRelativePath);
} catch (IOException ignore) {
// expected to occur on missing file
}
- assertThat(targetDir.resolve(INCOMPLETE_BACKUP_FILE)).exists();
+
assertThat(getTargetDir(useRelativePath).resolve(INCOMPLETE_BACKUP_FILE)).exists();
}
@Test
- public void doesNotLeaveBehindIncompleteFileOnSuccess() throws Exception {
- executeBackup();
- assertThat(targetDir.resolve(INCOMPLETE_BACKUP_FILE)).doesNotExist();
+ @Parameters({"true", "false"})
+ public void doesNotLeaveBehindIncompleteFileOnSuccess(boolean
useRelativePath) throws Exception {
+ executeBackup(useRelativePath);
+
assertThat(getTargetDir(useRelativePath).resolve(INCOMPLETE_BACKUP_FILE)).doesNotExist();
}
- private void executeBackup() throws IOException {
- BackupDestination backupDestination = new
FileSystemBackupDestination(targetDir);
+ private void executeBackup(boolean useRelativePath) throws IOException {
+ BackupDestination backupDestination =
+ new FileSystemBackupDestination(getTargetDir(useRelativePath));
backupDestination.backupFiles(backupDefinition);
}
+
+ private Path getTargetDir(boolean useRelativePath) {
+ return useRelativePath ? RELATIVE_TARGET_DIR : targetDir;
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Backup of DiskStoreIF file fails when relative path provided as destination
> ---------------------------------------------------------------------------
>
> Key: GEODE-4106
> URL: https://issues.apache.org/jira/browse/GEODE-4106
> Project: Geode
> Issue Type: Bug
> Components: persistence
> Affects Versions: 1.4.0
> Reporter: Nick Reich
> Assignee: Nick Reich
>
> Backup functions correctly when absolute paths are used and when relative
> paths are used, only the DiskStoreIF file is copied to the incorrect location.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)