title: Creating HBaseAdmin which connects to HBaseTestingUtility
body: <p>I'm writing a code which manipulates data stored in HBase. I want to write also a test for this code. I want to use HBaseTestingUtility in my test, hence, in my @BeforeClass I create new instance of HBaseTestingUtility and I start the mini cluster:</p>
  
  <pre><code>    @BeforeClass
  public static void setUpClass() throws Exception {
      utility = new HBaseTestingUtility();
      utility.startMiniCluster();
  }
  </code></pre>
  
  <p>It works good. However, I cannot connect to this embedded cluster in my code which is being tested. In the code I have:</p>
  
  <pre><code>Configuration config = HBaseConfiguration.create();
  
  try (HBaseAdmin admin = new HBaseAdmin(config))
  {
     //code which manipulates the data
  }
  </code></pre>
  
  <p>Unfortunately when new HBaseAdmin is created I'm getting a ConnectionError exception:</p>
  
  <blockquote>
    <p>2013-11-21 11:20:35,778 WARN  [main-SendThread(0:0:0:0:0:0:0:1:2181)] zookeeper.ClientCnxn (ClientCnxn.java:run(1089)) - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
    java.net.ConnectException: Connection refused: no further information
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:692)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)</p>
  </blockquote>
  
  <p>When I try another apporach to create HBaseAdmin:</p>
  
  <pre><code>try (HBaseAdmin admin = new HBaseAdmin(HBaseCacheTest.utility.getConfiguration()))
  {
     //code which manipulates the data
  }
  </code></pre>
  
  <p>it works (note that here I'm accessing the instance of HBaseTestingUtility via HBaseCacheTest.utility). 
  Obviously this is not a good approach as I don't want to have a production code which depends on the testing code. </p>
  
  <p>One approach I see to work here is to make it possible in my production class to set the Configuration and use this setter method in my tests. 
  However, I believe that there should be another way to connect to the embeded mini cluster created with HBaseTestingUtility.</p>
  
  <p>Any ideas?</p>