You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by hz...@apache.org on 2023/01/02 12:37:06 UTC
[rocketmq] 06/08: Add some bad case tests in StatemachineSnapshotFileGeneratorTest
This is an automated email from the ASF dual-hosted git repository.
hzh0425 pushed a commit to branch dledger-controller-snapshot
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
commit 8207a8c4d312b7a5c1a7c83982d3b9e9a18d51aa
Author: hzh0425 <64...@qq.com>
AuthorDate: Mon Jan 2 19:42:46 2023 +0800
Add some bad case tests in StatemachineSnapshotFileGeneratorTest
---
.../StatemachineSnapshotFileGeneratorTest.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/controller/src/test/java/org/apache/rocketmq/controller/impl/controller/impl/statemachine/StatemachineSnapshotFileGeneratorTest.java b/controller/src/test/java/org/apache/rocketmq/controller/impl/controller/impl/statemachine/StatemachineSnapshotFileGeneratorTest.java
index 1c4d7e478..9a092ebc1 100644
--- a/controller/src/test/java/org/apache/rocketmq/controller/impl/controller/impl/statemachine/StatemachineSnapshotFileGeneratorTest.java
+++ b/controller/src/test/java/org/apache/rocketmq/controller/impl/controller/impl/statemachine/StatemachineSnapshotFileGeneratorTest.java
@@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.HashSet;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class StatemachineSnapshotFileGeneratorTest {
@@ -71,13 +72,21 @@ public class StatemachineSnapshotFileGeneratorTest {
parentFile.mkdirs();
}
this.replicasInfoManager = new ReplicasInfoManager(null);
- mockMetadata();
this.snapshotGenerator = new StatemachineSnapshotFileGenerator(Collections.singletonList(this.replicasInfoManager));
}
+ @Test
+ public void testGenerateAndLoadEmptySnapshot() throws IOException {
+ ReplicasInfoManager emptyManager = new ReplicasInfoManager(null);
+ StatemachineSnapshotFileGenerator generator1 = new StatemachineSnapshotFileGenerator(Collections.singletonList(emptyManager));
+ generator1.generateSnapshot(this.snapshotPath);
+
+ assertTrue(generator1.loadSnapshot(this.snapshotPath));
+ }
@Test
public void testGenerateAndLoadSnapshot() throws IOException {
+ mockMetadata();
this.snapshotGenerator.generateSnapshot(this.snapshotPath);
ReplicasInfoManager emptyManager = new ReplicasInfoManager(null);
@@ -86,4 +95,10 @@ public class StatemachineSnapshotFileGeneratorTest {
assertArrayEquals(emptyManager.encodeMetadata(), this.replicasInfoManager.encodeMetadata());
}
+
+ @Test
+ public void testLoadSnapshotFromNoneExistFile() throws IOException {
+ String path = Paths.get(File.separator + "tmp", "ControllerSnapshotTmp").toString();
+ assertFalse(this.snapshotGenerator.loadSnapshot(path));
+ }
}
\ No newline at end of file