Search in sources :

Example 46 with ZooKeeper

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

the class TestMapCache method testModifyChild.

@Test
public void testModifyChild() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache03", zk);
    MapCache dut = new MapCache(zk, "/cache03");
    dut.start(true);
    Map<String, JSONObject> cache = dut.pointInTimeCache();
    assertEquals("3 items cached.", 3, cache.size());
    assertEquals("aaval", cache.get("/cache03/aa").get("key"));
    JSONObject aa = new JSONObject("{key:aaval2}");
    zk.setData("/cache03/aa", aa.toString().getBytes(), -1);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.get("/cache03/aa").get("key").equals("aaval2")) {
            break;
        }
    }
    assertEquals("3 items cached.", 3, cache.size());
    assertEquals("aaval2", cache.get("/cache03/aa").get("key"));
    assertEquals("bbval", cache.get("/cache03/bb").get("key"));
    assertEquals("ccval", cache.get("/cache03/cc").get("key"));
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) JSONObject(org.json_voltpatches.JSONObject) Test(org.junit.Test)

Example 47 with ZooKeeper

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

the class TestMapCache method testInitialCacheWithCallback.

@Test
public void testInitialCacheWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache01", zk);
    TestCallback cb = new TestCallback();
    MapCache dut = new MapCache(zk, "/cache01", cb);
    dut.start(true);
    assertEquals("3 items cached.", 3, cb.m_cache.size());
    assertEquals("aaval", cb.m_cache.get("/cache01/aa").get("key"));
    assertEquals("bbval", cb.m_cache.get("/cache01/bb").get("key"));
    assertEquals("ccval", cb.m_cache.get("/cache01/cc").get("key"));
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Test(org.junit.Test)

Example 48 with ZooKeeper

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

the class TestMapCache method testAddChildWithPut.

@Test
public void testAddChildWithPut() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache04", zk);
    MapCache dut = new MapCache(zk, "/cache04");
    dut.start(true);
    Map<String, JSONObject> cache = dut.pointInTimeCache();
    JSONObject dd = new JSONObject("{key:ddval}");
    dut.put("dd", dd);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.size() == 3) {
            Thread.sleep(1);
        } else {
            break;
        }
    }
    assertEquals("Item added", 4, cache.size());
    assertEquals("aaval", cache.get("/cache04/aa").get("key"));
    assertEquals("bbval", cache.get("/cache04/bb").get("key"));
    assertEquals("ccval", cache.get("/cache04/cc").get("key"));
    assertEquals("ddval", cache.get("/cache04/dd").get("key"));
    // modify the new child and make sure it has a watch set.
    JSONObject dd2 = new JSONObject("{key:ddval2}");
    dut.put("dd", dd2);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.get("/cache04/dd").get("key").equals("ddval2")) {
            break;
        }
    }
    assertEquals("Items accounted for.", 4, cache.size());
    assertEquals("ddval2", cache.get("/cache04/dd").get("key"));
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) JSONObject(org.json_voltpatches.JSONObject) Test(org.junit.Test)

Example 49 with ZooKeeper

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

the class TestStateMachine method setUp.

@Before
public void setUp() throws Exception {
    setUpZK(NUM_AGREEMENT_SITES);
    coordinators = IntStream.range(0, NUM_AGREEMENT_SITES).mapToObj(i -> ":" + (i + Constants.DEFAULT_INTERNAL_PORT)).toArray(s -> new String[s]);
    criteria = MeshProber.builder().coordinators(coordinators).startAction(StartAction.PROBE).hostCount(NUM_AGREEMENT_SITES).build();
    ZooKeeper zk = m_messengers.get(0).getZK();
    ZKUtil.addIfMissing(zk, "/test", CreateMode.PERSISTENT, null);
    ZKUtil.addIfMissing(zk, "/test/db", CreateMode.PERSISTENT, null);
    ZKUtil.addIfMissing(zk, stateMachineManagerRoot, CreateMode.PERSISTENT, null);
    for (int ii = 0; ii < NUM_AGREEMENT_SITES; ii++) {
        addStateMachinesFor(ii);
    }
}
Also used : IntStream(java.util.stream.IntStream) MeshProber(org.voltdb.probe.MeshProber) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) ByteBuffer(java.nio.ByteBuffer) Charsets(com.google_voltpatches.common.base.Charsets) List(java.util.List) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) HostMessenger(org.voltcore.messaging.HostMessenger) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) After(org.junit.After) CreateMode(org.apache.zookeeper_voltpatches.CreateMode) Constants(org.voltcore.common.Constants) Assert.fail(org.junit.Assert.fail) StartAction(org.voltdb.StartAction) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) VoltLogger(org.voltcore.logging.VoltLogger) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Before(org.junit.Before)

Example 50 with ZooKeeper

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

the class TestZK method testMassiveNode.

@Test
public void testMassiveNode() throws Exception {
    ZooKeeper zk = getClient(0);
    //        byte bytes[] = new byte[50331648];
    byte[] bytes = new byte[40000000];
    zk.create("/bar", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    zk.create("/foo", bytes, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    zk.getData("/foo", false, null);
}
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