/**
 * Copyright 2010 The Apache Software Foundation
 *
 * 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
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Class that tests the multi-cluster in 1 JVM case, useful
 * only for "unit'ish tests".
 */
public class TestMultiClusters {

  private static final byte[] TABLE_NAME = Bytes.toBytes("test");
  private static final byte[] FAM_NAME = Bytes.toBytes("fam");
  private static final byte[] ROW = Bytes.toBytes("row");
  private static final byte[] QUAL_NAME = Bytes.toBytes("qual");
  private static final byte[] VALUE = Bytes.toBytes("value");

  /**
   * Basic sanity test that spins up 2 HDFS and HBase clusters that share the
   * same ZK ensemble. We then create the same table in both and make sure that
   * what we insert in one place doesn't end up in the other.
   * @throws Exception
   */
  @Test (timeout=100000)
  public void twoClusters() throws Exception{
    Configuration conf1 = HBaseConfiguration.create();
    // Different path for different clusters
    conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
    HBaseTestingUtility utility1 = new HBaseTestingUtility(conf1);
    utility1.startMiniZKCluster();

    Configuration conf2 = HBaseConfiguration.create();
    conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
    HBaseTestingUtility utility2 = new HBaseTestingUtility(conf2);
    // They share the same ensemble, but homed differently
    utility2.setZkCluster(utility1.getZkCluster());

    utility1.startMiniCluster();
    utility2.startMiniCluster();

    HTable table1 = utility1.createTable(TABLE_NAME, FAM_NAME);
    HTable table2 = utility2.createTable(TABLE_NAME, FAM_NAME);

    Put put = new Put(ROW);
    put.add(FAM_NAME, QUAL_NAME, VALUE);
    table1.put(put);

    Get get = new Get(ROW);
    get.addColumn(FAM_NAME, QUAL_NAME);
    Result res = table1.get(get);
    assertEquals(1, res.size());

    res = table2.get(get);
    assertEquals(0, res.size());
  }

}

@@ -1353,17 +1353,16 @@
 sters %7B%0A
-%0A
   privat
@@ -2539,24 +2539,36 @@
 luster());%0A%0A
+    try %7B%0A  
     utility1
@@ -2584,24 +2584,26 @@
 iCluster();%0A
+  
     utility2
@@ -2624,24 +2624,26 @@
 ter();%0A%0A    
+  
 HTable table
@@ -2690,24 +2690,26 @@
 _NAME);%0A    
+ 
+ 
 HTable table
@@ -2761,16 +2761,18 @@
 );%0A%0A    
+  
 Put put 
@@ -2783,24 +2783,26 @@
 w Put(ROW);%0A
+  
     put.add(
@@ -2834,16 +2834,18 @@
 E);%0A    
+  
 table1.p
@@ -2850,24 +2850,26 @@
 .put(put);%0A%0A
+  
     Get get 
@@ -2880,24 +2880,26 @@
 w Get(ROW);%0A
+  
     get.addC
@@ -2930,16 +2930,18 @@
 E);%0A    
+  
 Result r
@@ -2958,32 +2958,34 @@
 1.get(get);%0A    
+ 
+ 
 assertEquals(1, 
@@ -3002,16 +3002,18 @@
 );%0A%0A    
+ 
+ 
 res = ta
@@ -3023,24 +3023,26 @@
 2.get(get);%0A
+  
     assertEq
@@ -3064,13 +3064,150 @@
 e());%0A  
+  %7D finally %7B%0A      utility1.shutdownMiniCluster();%0A      utility2.shutdownMiniCluster();%0A      utility1.shutdownMiniZKCluster();%0A    %7D%0A  
 %7D
-%0A
 %0A%7D%0A

Add shutdown of clusters -- not shutting down was causing subsequent TestMergeTool to fail because there was running zk