|
@@ -19,14 +19,15 @@
|
|
|
package org.apache.zookeeper.server;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.apache.zookeeper.ZKTestCase;
|
|
|
import org.apache.zookeeper.server.persistence.FileTxnLog;
|
|
|
import org.apache.zookeeper.server.persistence.Util;
|
|
|
+import org.apache.zookeeper.test.ClientBase;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
-import org.junit.Assert;
|
|
|
|
|
|
public class ZooKeeperServerTest extends ZKTestCase {
|
|
|
@Test
|
|
@@ -114,4 +115,23 @@ public class ZooKeeperServerTest extends ZKTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testInvalidSnapshot() {
|
|
|
+ File f = null;
|
|
|
+ File tmpFileDir = null;
|
|
|
+ try {
|
|
|
+ tmpFileDir = ClientBase.createTmpDir();
|
|
|
+ f = new File(tmpFileDir, "snapshot.0");
|
|
|
+ if (!f.exists()) {
|
|
|
+ f.createNewFile();
|
|
|
+ }
|
|
|
+ Assert.assertFalse("Snapshot file size is greater than 9 bytes", Util.isValidSnapshot(f));
|
|
|
+ Assert.assertTrue("Can't delete file", f.delete());
|
|
|
+ } catch (IOException e) {
|
|
|
+ } finally {
|
|
|
+ if (null != tmpFileDir) {
|
|
|
+ ClientBase.recursiveDelete(tmpFileDir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|