1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.zookeeper;
21
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.hbase.*;
30 import org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 @Category(MediumTests.class)
37 public class TestZKTableReadOnly {
38 private static final Log LOG = LogFactory.getLog(TestZooKeeperNodeTracker.class);
39 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
40
41 @BeforeClass
42 public static void setUpBeforeClass() throws Exception {
43 TEST_UTIL.startMiniZKCluster();
44 }
45
46 @AfterClass
47 public static void tearDownAfterClass() throws Exception {
48 TEST_UTIL.shutdownMiniZKCluster();
49 }
50
51 Abortable abortable = new Abortable() {
52 @Override
53 public void abort(String why, Throwable e) {
54 LOG.info(why, e);
55 }
56
57 @Override
58 public boolean isAborted() {
59 return false;
60 }
61 };
62
63 private boolean enableAndCheckEnabled(ZooKeeperWatcher zkw, String tableName) throws Exception {
64
65
66 ZKTable zkt = new ZKTable(zkw);
67 zkt.setEnabledTable(tableName);
68 return ZKTableReadOnly.isEnabledTable(zkw, tableName);
69 }
70
71 private void runClientCompatiblityWith92ZNodeTest(String tableName, Configuration conf)
72 throws Exception {
73 ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf,
74 tableName, abortable, true);
75 assertTrue(enableAndCheckEnabled(zkw, tableName));
76 }
77
78
79
80 @Test
81 public void testClientCompatibilityWith92ZNode() throws Exception {
82
83 String tableName = "testClientCompatibilityWith92ZNode";
84
85 Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
86 String znode92 = conf.get("zookeeper.znode.masterTableEnableDisable92", "table92");
87 conf.set("zookeeper.znode.clientTableEnableDisable", znode92);
88 runClientCompatiblityWith92ZNodeTest(tableName, conf);
89
90
91 tableName = "testClientCompatibilityWith92ZNodeUseMulti";
92 conf.setBoolean(HConstants.ZOOKEEPER_USEMULTI, true);
93 runClientCompatiblityWith92ZNodeTest(tableName, conf);
94 }
95
96 private void runClientCompatibilityWith94ZNodeTest(String tableName, Configuration conf)
97 throws Exception {
98 ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
99 tableName, abortable, true);
100 assertTrue(enableAndCheckEnabled(zkw, tableName));
101 }
102
103
104
105
106 @Test
107 public void testClientCompatibilityWith94ZNode() throws Exception {
108 String tableName = "testClientCompatibilityWith94ZNode";
109
110
111 runClientCompatibilityWith94ZNodeTest(tableName, TEST_UTIL.getConfiguration());
112
113
114 tableName = "testClientCompatiblityWith94ZNodeUseMulti";
115 Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
116 conf.setBoolean(HConstants.ZOOKEEPER_USEMULTI, true);
117 runClientCompatibilityWith94ZNodeTest(tableName, conf);
118 }
119
120 @org.junit.Rule
121 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
122 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
123 }