private String getZKClusterKey() { return String.format("127.0.0.1:%d:%s", UTIL.getZkCluster().getClientPort(), CONF.get(HConstants.ZOOKEEPER_ZNODE_PARENT)); }
@AfterClass public static void afterClass() throws IOException { UTIL.getZkCluster().shutdown(); }
@Test(timeout = 60000) public void testMasterInitWithSameClientServerZKQuorum() throws Exception { Configuration conf = new Configuration(TESTUTIL.getConfiguration()); conf.set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST); conf.setInt(HConstants.CLIENT_ZOOKEEPER_CLIENT_PORT, TESTUTIL.getZkCluster().getClientPort()); HMaster master = new HMaster(conf); master.start(); // the master will abort due to IllegalArgumentException so we should finish within 60 seconds master.join(); }
private void testZookeeperCanaryWithArgs(String[] args) throws Exception { Integer port = Iterables.getOnlyElement(testingUtility.getZkCluster().getClientPortList(), null); testingUtility.getConfiguration().set(HConstants.ZOOKEEPER_QUORUM, "localhost:" + port + "/hbase"); ExecutorService executor = new ScheduledThreadPoolExecutor(2); Canary.ZookeeperStdOutSink sink = spy(new Canary.ZookeeperStdOutSink()); Canary canary = new Canary(executor, sink); assertEquals(0, ToolRunner.run(testingUtility.getConfiguration(), canary, args)); String baseZnode = testingUtility.getConfiguration() .get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); verify(sink, atLeastOnce()) .publishReadTiming(eq(baseZnode), eq("localhost:" + port), anyLong()); } }
@SuppressWarnings("resource") private void startMiniClusters(int numClusters) throws Exception { Random random = new Random(); utilities = new HBaseTestingUtility[numClusters]; configurations = new Configuration[numClusters]; for (int i = 0; i < numClusters; i++) { Configuration conf = new Configuration(baseConfiguration); conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/" + i + random.nextInt()); HBaseTestingUtility utility = new HBaseTestingUtility(conf); if (i == 0) { utility.startMiniZKCluster(); miniZK = utility.getZkCluster(); } else { utility.setZkCluster(miniZK); } utility.startMiniCluster(); utilities[i] = utility; configurations[i] = conf; new ZKWatcher(conf, "cluster" + i, null, true); } }
MiniZooKeeperCluster miniZK = utility1.getZkCluster(); utility1.setZkCluster(miniZK); new ZKWatcher(conf1, "cluster1", null, true);
/** * Start up a mini cluster of hbase, optionally dfs and zookeeper if needed. * It modifies Configuration. It homes the cluster data directory under a random * subdirectory in a directory under System property test.build.data, to be cleaned up on exit. * @see #shutdownMiniDFSCluster() */ public MiniHBaseCluster startMiniCluster(StartMiniClusterOption option) throws Exception { LOG.info("Starting up minicluster with option: {}", option); // If we already put up a cluster, fail. if (miniClusterRunning) { throw new IllegalStateException("A mini-cluster is already running"); } miniClusterRunning = true; setupClusterTestDir(); System.setProperty(TEST_DIRECTORY_KEY, this.clusterTestDir.getPath()); // Bring up mini dfs cluster. This spews a bunch of warnings about missing // scheme. Complaints are 'Scheme is undefined for build/test/data/dfs/name1'. if (dfsCluster == null) { LOG.info("STARTING DFS"); dfsCluster = startMiniDFSCluster(option.getNumDataNodes(), option.getDataNodeHosts()); } else { LOG.info("NOT STARTING DFS"); } // Start up a zk cluster. if (getZkCluster() == null) { startMiniZKCluster(option.getNumZkServers()); } // Start the MiniHBaseCluster return startMiniHBaseCluster(option); }
@Test(timeout = 60000) public void testMasterInitWithObserverModeClientZKQuorum() throws Exception { Configuration conf = new Configuration(TESTUTIL.getConfiguration()); Assert.assertFalse(Boolean.getBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE)); // set client ZK to some non-existing address and make sure server won't access client ZK // (server start should not be affected) conf.set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST); conf.setInt(HConstants.CLIENT_ZOOKEEPER_CLIENT_PORT, TESTUTIL.getZkCluster().getClientPort() + 1); // settings to allow us not to start additional RS conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); conf.setBoolean(LoadBalancer.TABLES_ON_MASTER, true); // main setting for this test case conf.setBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE, true); HMaster master = new HMaster(conf); master.start(); while (!master.isInitialized()) { Threads.sleep(200); } Assert.assertNull(master.metaLocationSyncer); Assert.assertNull(master.masterAddressSyncer); master.stopMaster(); master.join(); } }
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); TEST_UTIL2 = new HBaseTestingUtility(conf2); TEST_UTIL2.setZkCluster(TEST_UTIL.getZkCluster()); TEST_UTIL2.startMiniDFSCluster(3); String root2 = TEST_UTIL2.getConfiguration().get("fs.defaultFS");
addPeerAndWait(peerId2, ReplicationPeerConfig.newBuilder() .setClusterKey("localhost:" + utility.getZkCluster().getClientPort() + ":/hbase").build(), true); try {
@BeforeClass public static void setUpBeforeClass() throws Exception { conf1 = HBaseConfiguration.create(); conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1"); conf1.setLong("replication.source.sleepforretries", 100); // Each WAL is about 120 bytes conf1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, REPLICATION_SOURCE_QUOTA); conf1.setLong("replication.source.per.peer.node.bandwidth", 100L); utility1 = new HBaseTestingUtility(conf1); utility1.startMiniZKCluster(); MiniZooKeeperCluster miniZK = utility1.getZkCluster(); new ZKWatcher(conf1, "cluster1", null, true); conf2 = new Configuration(conf1); conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); utility2 = new HBaseTestingUtility(conf2); utility2.setZkCluster(miniZK); new ZKWatcher(conf2, "cluster2", null, true); ReplicationAdmin admin1 = new ReplicationAdmin(conf1); ReplicationPeerConfig rpc = new ReplicationPeerConfig(); rpc.setClusterKey(utility2.getClusterKey()); utility1.startMiniCluster(); utility2.startMiniCluster(); admin1.addPeer("peer1", rpc, null); admin1.addPeer("peer2", rpc, null); admin1.addPeer("peer3", rpc, null); numOfPeer = admin1.getPeersCount(); }
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
htu2.getConfiguration().set(HConstants.ZOOKEEPER_CLIENT_PORT, htu1.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT, "-1")); htu2.setZkCluster(htu1.getZkCluster()); htu3.getConfiguration().set(HConstants.ZOOKEEPER_CLIENT_PORT, htu1.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT, "-1")); htu3.setZkCluster(htu1.getZkCluster());
final String peerId = "FakePeer"; final ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder() .setClusterKey("localhost:" + utility.getZkCluster().getClientPort() + ":/hbase").build(); try { DummyServer server = new DummyServer();
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(3); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(ZooKeeperScanPolicyObserver.class.getName()) .setValue(ZooKeeperScanPolicyObserver.ZK_ENSEMBLE_KEY, "localhost:" + UTIL.getZkCluster().getClientPort()) .setValue(ZooKeeperScanPolicyObserver.ZK_SESSION_TIMEOUT_KEY, "2000") .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build()).build()); TABLE = UTIL.getConnection().getTable(NAME); }
conf2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1)); conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); MiniZooKeeperCluster miniZK = HTU.getZkCluster();
private void doTest() throws IOException { Admin admin = UTIL.getAdmin(); String peerId = "1"; ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder() .setClusterKey("localhost:" + UTIL.getZkCluster().getClientPort() + ":/hbase2").build(); admin.addReplicationPeer(peerId, peerConfig, true); assertEquals(peerConfig.getClusterKey(), admin.getReplicationPeerConfig(peerId).getClusterKey()); ReplicationPeerConfig newPeerConfig = ReplicationPeerConfig.newBuilder(peerConfig).setBandwidth(123456).build(); admin.updateReplicationPeerConfig(peerId, newPeerConfig); assertEquals(newPeerConfig.getBandwidth(), admin.getReplicationPeerConfig(peerId).getBandwidth()); admin.disableReplicationPeer(peerId); assertFalse(admin.listReplicationPeers().get(0).isEnabled()); admin.enableReplicationPeer(peerId); assertTrue(admin.listReplicationPeers().get(0).isEnabled()); admin.removeReplicationPeer(peerId); assertTrue(admin.listReplicationPeers().isEmpty()); // make sure that we have run into the mocked method MockHMaster master = (MockHMaster) UTIL.getHBaseCluster().getMaster(); assertTrue(master.addPeerCalled); assertTrue(master.removePeerCalled); assertTrue(master.updatePeerConfigCalled); assertTrue(master.enablePeerCalled); assertTrue(master.disablePeerCalled); }
assertEquals(zkServers.split(",").length, TEST_UTIL.getZkCluster().getZooKeeperServerNum());
final String peerId = "DummyPeer"; final ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder() .setClusterKey("localhost:" + utility.getZkCluster().getClientPort() + ":/hbase").build(); try { MetricsReplicationSourceSource globalSource = getGlobalSource();