1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.replication;
19
20 import junit.framework.Assert;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
28 import org.apache.zookeeper.KeeperException.SessionExpiredException;
29 import org.junit.*;
30
31 public class TestReplicationPeer {
32
33 private static final Log LOG = LogFactory.getLog(TestReplicationPeer.class);
34 private static HBaseTestingUtility utility;
35 private static Configuration conf;
36 private static ReplicationPeer rp;
37
38 @BeforeClass
39 public static void setUpBeforeClass() throws Exception {
40 conf = HBaseConfiguration.create();
41 utility = new HBaseTestingUtility(conf);
42 conf = utility.getConfiguration();
43 utility.startMiniZKCluster();
44
45 rp = new ReplicationPeer(conf, "clusterKey", "clusterId");
46 }
47
48 @Test(timeout=300000)
49 public void testResetZooKeeperSession() throws Exception {
50 ZooKeeperWatcher zkw = rp.getZkw();
51 zkw.getRecoverableZooKeeper().exists("/1/2", false);
52
53 LOG.info("Expiring ReplicationPeer ZooKeeper session.");
54 utility.expireSession(zkw, null, false);
55
56 try {
57 LOG.info("Attempting to use expired ReplicationPeer ZooKeeper session.");
58
59 zkw.getRecoverableZooKeeper().exists("/1/2", false);
60 } catch (SessionExpiredException k) {
61 rp.reloadZkWatcher();
62
63 zkw = rp.getZkw();
64
65
66 LOG.info("Attempting to use refreshed "
67 + "ReplicationPeer ZooKeeper session.");
68 zkw.getRecoverableZooKeeper().exists("/1/2", false);
69
70 return;
71 }
72
73 Assert.fail("ReplicationPeer ZooKeeper session was not properly expired.");
74 }
75
76 }