package edu.mayo.hadoop.commons.examples;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.github.sakserv.minicluster.config.ConfigVars;
import com.github.sakserv.minicluster.impl.ZookeeperLocalCluster;

import edu.mayo.hadoop.commons.minicluster.MiniClusterUtil;

/**
 * Created by m102417 on 2/12/16. checks that Zookeeper is up and running and
 * correctly responds to queries on localhost
 */
public class ZookeeperITCase {

    private static Properties prop;

    @Before
    public void setup() throws Exception {
        try (InputStream stream = HBaseITCase.class.getResourceAsStream("/zookeeper.properties")) {
            prop = MiniClusterUtil.loadPropertiesStream(stream);
        }
        MiniClusterUtil.startZookeeper(prop);
    }

    @After
    public void teardown() throws Exception {
        MiniClusterUtil.stopZookeeper();
    }

    /**
     * tests that zookeeper is up and running
     */
    @Test
    public void running() {
        ZookeeperLocalCluster zookeeperLocalCluster = MiniClusterUtil.getZookeeperLocalCluster();
        assertEquals(prop.getProperty(ConfigVars.ZOOKEEPER_CONNECTION_STRING_KEY), zookeeperLocalCluster.getZookeeperConnectionString());
    }
}

@@ -73,22 +73,20 @@
 t.assert
-Equals
+True
 ;%0A%0Aimpor
@@ -91,281 +91,356 @@
 ort 
-java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Properties;%0A%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport com.github.sakserv.minicluster.config.ConfigVars;%0Aimport com.github.sakserv.minicluster.impl.ZookeeperLocalCluster
+org.apache.zookeeper.WatchedEvent;%0Aimport org.apache.zookeeper.Watcher;%0Aimport org.apache.zookeeper.Watcher.Event.KeeperState;%0Aimport org.apache.zookeeper.ZooKeeper;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.Properties;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit
 ;%0A%0Ai
@@ -473,35 +473,27 @@
 ons.
-minicluster.MiniClusterUtil
+hbase.AutoConfigure
 ;%0A%0A/
@@ -572,19 +572,16 @@
 ning and
-%0A *
  correct
@@ -756,218 +756,111 @@
     
-try (InputStream stream = HBaseITCase.class.getResourceAsStream(%22/zookeeper.properties%22)) %7B%0A            prop = MiniClusterUtil.loadPropertiesStream(stream);%0A        %7D%0A        MiniClusterUtil.startZookeeper(prop
+// Get a config, just to have AutoConfigure startup the cluster%0A        AutoConfigure.getConfiguration(
 );%0A 
@@ -934,37 +934,26 @@
     
-MiniClusterUtil.stopZookeeper
+AutoConfigure.stop
 ();%0A
@@ -1023,145 +1023,353 @@
    *
-/%0A    @Test%0A    public void running() %7B%0A        ZookeeperLocalCluster zookeeperLocalCluster = MiniClusterUtil.getZook
+ %0A     * @see https://ihong5.wordpress.com/2014/05/27/maven-how-to-connect-to-a-zookeeper-in-java/%0A     * %0A     * @throws Exception%0A     */%0A    @Test%0A    public void running() throws Exception %7B%0A        CountDownLatch connectedSignal = new CountDownLatch(1);%0A%0A        ZooKeeper zookeeper = new ZooK
 eeper
-LocalClust
+(%22127.0.0.1:22010%22, 5000, new Watch
 er()
-;
+ %7B%0A
 %0A   
@@ -1377,117 +1377,279 @@
     
-assertEquals(prop.getProperty(ConfigVars.ZOOKEEPER_CONNECTION_STRING_KEY), zookeeperLocalCluster.getZ
+    @Override%0A            public void process(WatchedEvent event) %7B%0A                if (event.getState() == KeeperState.SyncConnected) %7B%0A                    connectedSignal.countDown();%0A                %7D%0A%0A            %7D%0A        %7D);%0A        assertTrue(%22Connect to z
 ookeeper
 Conn
@@ -1648,25 +1648,53 @@
 eper
-C
+%22, c
 onnect
-ionString(
+edSignal.await(10, TimeUnit.SECONDS
 ));%0A

Connect Zookeeper test to local Zookeeper