diff options
author | tison <wander4096@gmail.com> | 2019-08-17 08:13:15 -0700 |
---|---|---|
committer | Michael Han <hanm@apache.org> | 2019-08-17 08:13:15 -0700 |
commit | fe940cdd8fb23ba09684cefb73233d570f4a20fa (patch) | |
tree | 28de6768b6ef6f233840636cb50a1cd35512e319 /zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java | |
parent | 04cc5cae1e7d4b007490e68109a676b88ce790a3 (diff) | |
download | zookeeper-fe940cdd8fb23ba09684cefb73233d570f4a20fa.tar.gz |
ZOOKEEPER-3475: Enable Checkstyle configuration on zookeeper-server
- [x] org/apache/zookeeper
- [x] org/apache/zookeeper/admin
- [x] org/apache/zookeeper/cli
- [x] org/apache/zookeeper/client
- [x] org/apache/zookeeper/common
- [x] org/apache/zookeeper/jmx
- [x] org/apache/zookeeper/metrics
- [x] org/apache/zookeeper/metrics/impl
- [x] org/apache/zookeeper/server
- [x] org/apache/zookeeper/server/admin
- [x] org/apache/zookeeper/server/auth
- [x] org/apache/zookeeper/server/command
- [x] org/apache/zookeeper/server/metric
- [x] org/apache/zookeeper/server/persistence
- [x] org/apache/zookeeper/server/quorum
- [x] org/apache/zookeeper/server/quorum/auth
- [x] org/apache/zookeeper/server/quorum/flexible
- [x] org/apache/zookeeper/server/util
- [x] org/apache/zookeeper/server/watch
- [x] org/apache/zookeeper/test
- [x] org/apache/zookeeper/util
- [x] org/apache/zookeeper/version/util
Author: tison <wander4096@gmail.com>
Reviewers: Brian Nixon <nixon@fb.com>, Enrico Olivelli <eolivelli@gmail.com>, Michael Han <hanm@apache.org>
Closes #1049 from TisonKun/ZOOKEEPER-3475
Diffstat (limited to 'zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java')
-rw-r--r-- | zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java index 5b2f8a481..571636c60 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,33 +18,32 @@ package org.apache.zookeeper.test; -import java.io.IOException; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.util.List; -import java.util.LinkedList; - import org.apache.log4j.Logger; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.PortAssignment; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.SyncRequestProcessor; import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.persistence.FileTxnSnapLog; -import org.junit.Assert; import org.junit.Test; -/** If snapshots are corrupted to the empty file or deleted, Zookeeper should +/** If snapshots are corrupted to the empty file or deleted, Zookeeper should * not proceed to read its transactiong log files * Test that zxid == -1 in the presence of emptied/deleted snapshots */ -public class EmptiedSnapshotRecoveryTest extends ZKTestCase implements Watcher { +public class EmptiedSnapshotRecoveryTest extends ZKTestCase implements Watcher { + private static final Logger LOG = Logger.getLogger(RestoreCommittedLogTest.class); private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); private static final int CONNECTION_TIMEOUT = 3000; @@ -53,44 +52,41 @@ public class EmptiedSnapshotRecoveryTest extends ZKTestCase implements Watcher public void runTest(boolean leaveEmptyFile) throws Exception { File tmpSnapDir = ClientBase.createTmpDir(); - File tmpLogDir = ClientBase.createTmpDir(); + File tmpLogDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000); SyncRequestProcessor.setSnapCount(SNAP_COUNT); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); - Assert.assertTrue("waiting for server being up ", - ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT)); + assertTrue("waiting for server being up ", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); try { - for (int i = 0; i< N_TRANSACTIONS; i++) { - zk.create("/node-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); + for (int i = 0; i < N_TRANSACTIONS; i++) { + zk.create("/node-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } finally { zk.close(); } f.shutdown(); zks.shutdown(); - Assert.assertTrue("waiting for server to shutdown", - ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + assertTrue("waiting for server to shutdown", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); // start server again with intact database zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000); zks.startdata(); long zxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); LOG.info("After clean restart, zxid = " + zxid); - Assert.assertTrue("zxid > 0", zxid > 0); + assertTrue("zxid > 0", zxid > 0); zks.shutdown(); // Make all snapshots empty FileTxnSnapLog txnLogFactory = zks.getTxnLogFactory(); List<File> snapshots = txnLogFactory.findNRecentSnapshots(10); - Assert.assertTrue("We have a snapshot to corrupt", snapshots.size() > 0); - for (File file: snapshots) { + assertTrue("We have a snapshot to corrupt", snapshots.size() > 0); + for (File file : snapshots) { if (leaveEmptyFile) { - new PrintWriter(file).close (); + new PrintWriter(file).close(); } else { file.delete(); } @@ -101,10 +97,10 @@ public class EmptiedSnapshotRecoveryTest extends ZKTestCase implements Watcher try { zks.startdata(); zxid = zks.getZKDatabase().loadDataBase(); - Assert.fail("Should have gotten exception for corrupted database"); + fail("Should have gotten exception for corrupted database"); } catch (IOException e) { // expected behavior - } + } zks.shutdown(); } |