Search in sources :

Example 6 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class ZKTestBase method setUpZK.

protected void setUpZK(int sites) throws Exception {
    m_siteIdToZKPort = new TreeMap<Integer, Integer>();
    m_clients = new ArrayList<ZooKeeper>();
    m_messengers = new ArrayList<HostMessenger>();
    String[] coordinators = IntStream.range(0, sites).mapToObj(i -> ":" + (i + Constants.DEFAULT_INTERNAL_PORT)).toArray(s -> new String[s]);
    for (int ii = 0; ii < sites; ii++) {
        HostMessenger.Config config = new HostMessenger.Config();
        config.internalPort += ii;
        config.acceptor = MeshProber.builder().coordinators(coordinators).startAction(StartAction.PROBE).hostCount(sites).build();
        int externalPort = m_ports.next();
        config.zkInterface = "127.0.0.1:" + externalPort;
        m_siteIdToZKPort.put(ii, externalPort);
        config.networkThreads = 1;
        HostMessenger hm = new HostMessenger(config, null);
        hm.start();
        m_messengers.add(hm);
    }
    for (HostMessenger hm : m_messengers) {
        MeshProber.prober(hm).waitForDetermination();
    }
}
Also used : IntStream(java.util.stream.IntStream) WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) MeshProber(org.voltdb.probe.MeshProber) Semaphore(java.util.concurrent.Semaphore) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Sets(com.google_voltpatches.common.collect.Sets) KeeperState(org.apache.zookeeper_voltpatches.Watcher.Event.KeeperState) ArrayList(java.util.ArrayList) Watcher(org.apache.zookeeper_voltpatches.Watcher) HostMessenger(org.voltcore.messaging.HostMessenger) HostAndPort(com.google_voltpatches.common.net.HostAndPort) TreeMap(java.util.TreeMap) Map(java.util.Map) Constants(org.voltcore.common.Constants) StartAction(org.voltdb.StartAction) PortGenerator(org.voltcore.utils.PortGenerator) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Example 7 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class ZKTestBase method tearDownZK.

protected void tearDownZK() throws Exception {
    for (ZooKeeper keeper : m_clients) {
        keeper.close();
    }
    m_clients.clear();
    for (HostMessenger hm : m_messengers) {
        if (hm != null) {
            hm.shutdown();
        }
    }
    m_messengers.clear();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Example 8 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class TestLeaderCache method testAddChildWithPut.

@Test
public void testAddChildWithPut() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache04", zk);
    LeaderCache dut = new LeaderCache(zk, "/cache04");
    dut.start(true);
    Map<Integer, Long> cache = dut.pointInTimeCache();
    dut.put(3, 88776655);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.size() == 3) {
            Thread.sleep(1);
        } else {
            break;
        }
    }
    assertEquals("Item added", 4, cache.size());
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(87654321, cache.get(1).longValue());
    assertEquals(11223344, cache.get(2).longValue());
    assertEquals(88776655, cache.get(3).longValue());
    // modify the new child and make sure it has a watch set.
    dut.put(3, 99887766);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.get(3) == 99887766) {
            break;
        }
    }
    assertEquals("Items accounted for.", 4, cache.size());
    assertEquals(99887766L, cache.get(3).longValue());
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Test(org.junit.Test)

Example 9 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class TestLeaderCache method testDeleteChildWithCallback.

@Test
public void testDeleteChildWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache02", zk);
    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache02", cb);
    dut.start(true);
    Map<Integer, Long> cache = cb.m_cache;
    assertEquals("3 items cached.", 3, cache.size());
    zk.delete("/cache02/1", -1);
    while (true) {
        cache = cb.m_cache;
        if (cache.size() == 3) {
            Thread.sleep(1);
        } else {
            break;
        }
    }
    assertEquals("Item removed", 2, cache.size());
    assertEquals(null, cache.get(1));
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(11223344, cache.get(2).longValue());
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Test(org.junit.Test)

Example 10 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class TestLeaderCache method testAddChildWithPutWithCallback.

@Test
public void testAddChildWithPutWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache04", zk);
    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache04", cb);
    dut.start(true);
    Map<Integer, Long> cache = cb.m_cache;
    dut.put(3, 88776655);
    while (true) {
        cache = cb.m_cache;
        if (cache.size() == 3) {
            Thread.sleep(1);
        } else {
            break;
        }
    }
    assertEquals("Item added", 4, cache.size());
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(87654321, cache.get(1).longValue());
    assertEquals(11223344, cache.get(2).longValue());
    assertEquals(88776655, cache.get(3).longValue());
    // modify the new child and make sure it has a watch set.
    dut.put(3, 99887766);
    while (true) {
        cache = cb.m_cache;
        if (cache.get(3) == 99887766) {
            break;
        }
    }
    assertEquals("Items accounted for.", 4, cache.size());
    assertEquals(99887766, cache.get(3).longValue());
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Test(org.junit.Test)

Aggregations

ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)62 Test (org.junit.Test)38 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)14 JSONObject (org.json_voltpatches.JSONObject)14 Semaphore (java.util.concurrent.Semaphore)11 Stat (org.apache.zookeeper_voltpatches.data.Stat)10 ExecutionException (java.util.concurrent.ExecutionException)8 HostMessenger (org.voltcore.messaging.HostMessenger)8 IOException (java.io.IOException)7 JSONException (org.json_voltpatches.JSONException)7 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)5 Watcher (org.apache.zookeeper_voltpatches.Watcher)5 VoltTable (org.voltdb.VoltTable)5 SettingsException (org.voltdb.settings.SettingsException)5 List (java.util.List)4 Map (java.util.Map)4 HostAndPort (com.google_voltpatches.common.net.HostAndPort)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SocketException (java.net.SocketException)3 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)2