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();
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations