summaryrefslogtreecommitdiff
path: root/src/test/java/com/keuin/kbackupfabric/operation/backup
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/operation/backup')
-rw-r--r--src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
index c69bd11..1fb3414 100644
--- a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
+++ b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
@@ -1,9 +1,13 @@
package com.keuin.kbackupfabric.operation.backup.method;
+import com.keuin.kbackupfabric.TestUtils;
import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder;
import com.keuin.kbackupfabric.metadata.BackupMetadata;
import com.keuin.kbackupfabric.operation.backup.feedback.IncrementalBackupFeedback;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import java.io.*;
@@ -13,13 +17,14 @@ import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
+import java.util.logging.Logger;
+import java.util.stream.Stream;
import static org.apache.commons.io.FileUtils.forceDelete;
import static org.junit.Assert.*;
public class ConfiguredIncrementalBackupMethodTest {
-
- private final String testTempPath = (new File("R:\\").isDirectory()) ? "R:\\" : ".\\testfile\\ConfiguredIncrementalBackupMethodTest";
+ private String testTempPath;
private final String sourceDirectoryName = "source";
private final String destDirectoryName = "destination";
private final String customBackupName = "index";
@@ -30,6 +35,20 @@ public class ConfiguredIncrementalBackupMethodTest {
private final int maxRandomFileSizeBytes = 1024 * 1024;
private final Function<Integer, Integer> scaleDecayFunc = (x) -> x - 1;
+ private static final Logger logger = Logger.getLogger(ConfiguredIncrementalBackupMethodTest.class.getName());
+
+ @Before
+ public void setUp() throws IOException {
+ // select temporary directory
+ testTempPath = TestUtils.getTempDirectory("kb_temp");
+ logger.info(String.format("Using temp path: %s", testTempPath));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ FileUtils.deleteDirectory(new File(testTempPath));
+ }
+
@Test
public void iterationTest() throws IOException {
int a = 12;
@@ -89,13 +108,15 @@ public class ConfiguredIncrementalBackupMethodTest {
int[] success = new int[1];
if (fake) {
- Files.walk(sourcePath).filter(path -> path.toFile().isFile()).limit(4).forEach(path -> {
- System.out.println("Deleted file `" + path.toFile().getName() + "`.");
- if (!path.toFile().delete())
- fail();
- if (!Objects.equals(path.toFile().getName(), BackupMetadata.metadataFileName))
- success[0]++;
- });
+ try (Stream<Path> walk = Files.walk(sourcePath)) {
+ walk.filter(path -> path.toFile().isFile()).limit(4).forEach(path -> {
+ System.out.println("Deleted file `" + path.toFile().getName() + "`.");
+ if (!path.toFile().delete())
+ fail();
+ if (!Objects.equals(path.toFile().getName(), BackupMetadata.metadataFileName))
+ success[0]++;
+ });
+ }
if (success[0] == 0)
fake = false;
}
@@ -198,12 +219,11 @@ public class ConfiguredIncrementalBackupMethodTest {
Set<String> ignoredFiles) {
File[] fileList = dir.listFiles();
- Arrays.sort(fileList, // Need in reproducible order
- new Comparator<File>() {
- public int compare(File f1, File f2) {
- return f1.getName().compareTo(f2.getName());
- }
- });
+ if (fileList == null) {
+ throw new RuntimeException("Failed to list files in directory " + dir);
+ }
+ // Need in reproducible order
+ Arrays.sort(fileList, Comparator.comparing(File::getName));
for (File f : fileList) {
if (!includeHiddenFiles && f.getName().startsWith(".") ||