From 4a1d885afa7217b47d6183488c3dc6537cef05b6 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 23 Jan 2021 14:10:32 +0800 Subject: Version 1.4.6 (preview): added metadata for incremental backup (need integrated test and display implementation) --- .../incremental/ObjectCollectionFactoryTest.java | 6 +- .../ObjectCollectionSerializerTest.java | 69 -------------------- .../serializer/IncBackupInfoSerializerTest.java | 73 ++++++++++++++++++++++ .../IncBakupBackwardCompatibilityTest.java | 45 +++++++++++++ .../ConfiguredIncrementalBackupMethodTest.java | 5 +- 5 files changed, 125 insertions(+), 73 deletions(-) delete mode 100644 src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializerTest.java create mode 100644 src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializerTest.java create mode 100644 src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java (limited to 'src/test') diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactoryTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactoryTest.java index 5052a82..e686e30 100644 --- a/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactoryTest.java +++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactoryTest.java @@ -11,10 +11,10 @@ import static org.junit.Assert.*; public class ObjectCollectionFactoryTest { - private void validate(ObjectCollection collection, List subCollections, Map subElements) { + private void validate(ObjectCollection2 collection, List subCollections, Map subElements) { assertEquals(subCollections.size(), collection.getSubCollectionMap().size()); assertEquals(subElements.size(), collection.getElementSet().size()); - for (Map.Entry c : collection.getSubCollectionMap().entrySet()) { + for (Map.Entry c : collection.getSubCollectionMap().entrySet()) { assertEquals(c.getKey(), c.getValue().getName()); assertTrue(subCollections.contains(c.getKey())); } @@ -68,7 +68,7 @@ public class ObjectCollectionFactoryTest { try { ObjectCollectionFactory factory = new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), threads, multiThreadThreshold); - ObjectCollection collection = + ObjectCollection2 collection = factory.fromDirectory(new File("./testfile/ObjectCollectionFactoryTest")); assertEquals("ObjectCollectionFactoryTest", collection.getName()); diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializerTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializerTest.java deleted file mode 100644 index d21e5b3..0000000 --- a/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializerTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.keuin.kbackupfabric.backup.incremental; - -import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; - -import static org.junit.Assert.assertEquals; - -public class ObjectCollectionSerializerTest { - - @Test - public void testSerializationConsistency1() throws IOException { - testSerializationConsistency(1, 0); - } - - @Test - public void testSerializationConsistency2() throws IOException { - testSerializationConsistency(2, 0); - } - - @Test - public void testSerializationConsistency4() throws IOException { - testSerializationConsistency(4, 0); - } - - @Test - public void testSerializationConsistency8() throws IOException { - testSerializationConsistency(8, 0); - } - - @Test - public void testSerializationConsistency1A() throws IOException { - testSerializationConsistency(1, 1000); - } - - @Test - public void testSerializationConsistency2A() throws IOException { - testSerializationConsistency(2, 1000); - } - - @Test - public void testSerializationConsistency4A() throws IOException { - testSerializationConsistency(4, 1000); - } - - @Test - public void testSerializationConsistency8A() throws IOException { - testSerializationConsistency(8, 1000); - } - - public void testSerializationConsistency(int threads, int multiThreadThreshold) throws IOException { - ObjectCollectionFactory factory = - new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), threads, multiThreadThreshold); - ObjectCollection collection = - factory.fromDirectory(new File("./testfile/ObjectCollectionFactoryTest")); - File file = new File("./testfile/serialized"); - if (file.exists()) { - Files.delete(file.toPath()); - } - ObjectCollectionSerializer.toFile(collection, file); - ObjectCollection collection2 = ObjectCollectionSerializer.fromFile(file); - Files.delete(file.toPath()); - assertEquals(collection, collection2); - } - -} \ No newline at end of file diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializerTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializerTest.java new file mode 100644 index 0000000..e7f56b0 --- /dev/null +++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializerTest.java @@ -0,0 +1,73 @@ +package com.keuin.kbackupfabric.backup.incremental.serializer; + +import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2; +import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionFactory; +import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.time.ZonedDateTime; + +import static org.junit.Assert.assertEquals; + +public class IncBackupInfoSerializerTest { + + @Test + public void testSerializationConsistency1() throws IOException { + testSerializationConsistency(1, 0); + } + + @Test + public void testSerializationConsistency2() throws IOException { + testSerializationConsistency(2, 0); + } + + @Test + public void testSerializationConsistency4() throws IOException { + testSerializationConsistency(4, 0); + } + + @Test + public void testSerializationConsistency8() throws IOException { + testSerializationConsistency(8, 0); + } + + @Test + public void testSerializationConsistency1A() throws IOException { + testSerializationConsistency(1, 1000); + } + + @Test + public void testSerializationConsistency2A() throws IOException { + testSerializationConsistency(2, 1000); + } + + @Test + public void testSerializationConsistency4A() throws IOException { + testSerializationConsistency(4, 1000); + } + + @Test + public void testSerializationConsistency8A() throws IOException { + testSerializationConsistency(8, 1000); + } + + public void testSerializationConsistency(int threads, int multiThreadThreshold) throws IOException { + ObjectCollectionFactory factory = + new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), threads, multiThreadThreshold); + ObjectCollection2 collection = + factory.fromDirectory(new File("./testfile/ObjectCollectionFactoryTest")); + File file = new File("./testfile/serialized"); + if (file.exists()) { + Files.delete(file.toPath()); + } + SavedIncrementalBackup backup = SavedIncrementalBackup.newLatest(collection, ":name:", ZonedDateTime.now(), 10000, 2000, 10, 20); + IncBackupInfoSerializer.toFile(file, backup); + SavedIncrementalBackup info = IncBackupInfoSerializer.fromFile(file); + Files.delete(file.toPath()); + assertEquals(backup, info); + } + +} \ No newline at end of file diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java new file mode 100644 index 0000000..d50b264 --- /dev/null +++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java @@ -0,0 +1,45 @@ +package com.keuin.kbackupfabric.backup.incremental.serializer; + +import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2; +import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionFactory; +import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionSerializer; +import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier; +import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.ZoneOffset; + +import static org.junit.Assert.*; + +public class IncBakupBackwardCompatibilityTest { + + private final String customName = "test_backup"; + private final LocalDateTime backupTime = LocalDateTime.of(2000, 1, 1, 1, 1, 1, 1); + + private final Path testRoot = Paths.get(".\\testfile\\IncBackupBackwardCompatibilityTest"); + private final File indexFile = new File(testRoot.toString(), new IncrementalBackupFileNameEncoder().encode(customName, backupTime)); + + @Test + public void testBackwardCompatibility() throws IOException { + + if (!testRoot.toFile().isDirectory()) { + if (!testRoot.toFile().mkdirs()) + fail("Cannot initialize test environment: cannot create path."); + } + + // now we make an old-style backup index file + ObjectCollectionFactory factory = + new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), 1, 0); + ObjectCollection2 collection = factory.fromDirectory(testRoot.toFile()); + ObjectCollectionSerializer.toFile(collection, indexFile); + SavedIncrementalBackup info = IncBackupInfoSerializer.fromFile(indexFile); + assertEquals(collection, info.getObjectCollection()); + assertEquals(customName, info.getBackupName()); + assertTrue(backupTime.toEpochSecond(ZoneOffset.UTC) - info.getBackupTime().toLocalDateTime().toEpochSecond(ZoneOffset.UTC) <= 2); + } +} 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 badc744..80c643d 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,5 +1,6 @@ package com.keuin.kbackupfabric.operation.backup.method; +import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder; import com.keuin.kbackupfabric.operation.backup.feedback.IncrementalBackupFeedback; import org.apache.commons.codec.digest.DigestUtils; import org.junit.Test; @@ -8,6 +9,7 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.LocalDateTime; import java.util.*; import java.util.function.Function; @@ -19,7 +21,8 @@ public class ConfiguredIncrementalBackupMethodTest { private final String testTempPath = (new File("R:\\").isDirectory()) ? "R:\\" : ".\\testfile\\ConfiguredIncrementalBackupMethodTest"; private final String sourceDirectoryName = "source"; private final String destDirectoryName = "destination"; - private final String indexFileName = "index"; + private final String customBackupName = "index"; + private final String indexFileName = new IncrementalBackupFileNameEncoder().encode(customBackupName, LocalDateTime.now()); private final double directoryFactor = 0.05; private final double fileFactor = 0.1; -- cgit v1.2.3