Package org.apache.zookeeper_voltpatches

Examples of org.apache.zookeeper_voltpatches.ZooKeeper$ExistsWatchRegistration


    }

    @Test
    public void testSPMasterChange() throws Exception
    {
        ZooKeeper zk = getClient(0);
        VoltZK.createPersistentZKNodes(zk);
        LeaderCache spwriter = new LeaderCache(zk, VoltZK.iv2masters);
        HostMessenger hm = mock(HostMessenger.class);
        when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
        Cartographer dut = new Cartographer(hm, 0, false);
View Full Code Here


    }

    @Test
    public void testMPIChange() throws Exception
    {
        ZooKeeper zk = getClient(0);
        VoltZK.createPersistentZKNodes(zk);
        LeaderCache mpwriter = new LeaderCache(zk, VoltZK.iv2mpi);
        HostMessenger hm = mock(HostMessenger.class);
        when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
        Cartographer dut = new Cartographer(hm, 0, false);
View Full Code Here

        }
    }

    public void validateStartAction() {
        try {
            ZooKeeper zk = m_hostMessenger.getZK();
            boolean initCompleted = zk.exists(VoltZK.init_completed, false) != null;
            List<String> children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
            if (!children.isEmpty()) {
                for (String child : children) {
                    byte[] data = zk.getData(VoltZK.start_action + "/" + child, false, null);
                    if (data == null) {
                        VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
                    }
                    String startAction = new String(data);
                    if ((startAction.equals(StartAction.JOIN.toString()) ||
View Full Code Here

                js.object();
                js.key("role").value(m_config.m_replicationRole.ordinal());
                js.key("active").value(m_rvdb.getReplicationActive());
                js.endObject();

                ZooKeeper zk = m_rvdb.getHostMessenger().getZK();
                // rejoining nodes figure out the replication role from other nodes
                if (!m_isRejoin)
                {
                    try {
                        zk.create(
                                VoltZK.replicationconfig,
                                js.toString().getBytes("UTF-8"),
                                Ids.OPEN_ACL_UNSAFE,
                                CreateMode.PERSISTENT);
                    } catch (KeeperException.NodeExistsException e) {}
                    String discoveredReplicationConfig =
                        new String(zk.getData(VoltZK.replicationconfig, false, null), "UTF-8");
                    JSONObject discoveredjsObj = new JSONObject(discoveredReplicationConfig);
                    ReplicationRole discoveredRole = ReplicationRole.get((byte) discoveredjsObj.getLong("role"));
                    if (!discoveredRole.equals(m_config.m_replicationRole)) {
                        VoltDB.crashGlobalVoltDB("Discovered replication role " + discoveredRole +
                                " doesn't match locally specified replication role " + m_config.m_replicationRole,
                                true, null);
                    }

                    // See if we should bring the server up in WAN replication mode
                    m_rvdb.setReplicationRole(discoveredRole);
                } else {
                    String discoveredReplicationConfig =
                            new String(zk.getData(VoltZK.replicationconfig, false, null), "UTF-8");
                    JSONObject discoveredjsObj = new JSONObject(discoveredReplicationConfig);
                    ReplicationRole discoveredRole = ReplicationRole.get((byte) discoveredjsObj.getLong("role"));
                    boolean replicationActive = discoveredjsObj.getBoolean("active");
                    // See if we should bring the server up in WAN replication mode
                    m_rvdb.setReplicationRole(discoveredRole);
View Full Code Here

    }

    @Test
    public void testInitialCache() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache01", zk);

        LeaderCache dut = new  LeaderCache(zk, "/cache01");
        dut.start(true);
        Map<Integer, Long> cache = dut.pointInTimeCache();

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals(12345678L, dut.get(0).longValue());
        assertEquals(87654321L, dut.get(1).longValue());
        assertEquals(11223344L, dut.get(2).longValue());

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testInitialCacheWithCallback() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache01", zk);

        TestCallback cb = new TestCallback();
        LeaderCache dut = new  LeaderCache(zk, "/cache01", cb);
        dut.start(true);

        assertEquals("3 items cached.", 3, cb.m_cache.size());
        assertEquals(12345678, cb.m_cache.get(0).longValue());
        assertEquals(87654321, cb.m_cache.get(1).longValue());
        assertEquals(11223344, cb.m_cache.get(2).longValue());

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testModifyChild() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache03", zk);

        LeaderCache dut = new  LeaderCache(zk, "/cache03");
        dut.start(true);
        Map<Integer, Long> cache = dut.pointInTimeCache();

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals(12345678, dut.get(0).longValue());

        zk.setData("/cache03/0", Long.toString(23456789).getBytes(), -1);
        while(true) {
            if (dut.get(0) == 23456789) {
                break;
            }
        }
        assertEquals("3 items cached.", 3, cache.size());
        assertEquals(23456789L, dut.get(0).longValue());
        assertEquals(87654321L, dut.get(1).longValue());
        assertEquals(11223344L, dut.get(2).longValue());

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testModifyChildWithCallback() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache03", zk);

        TestCallback cb = new TestCallback();
        LeaderCache dut = new  LeaderCache(zk, "/cache03", cb);
        dut.start(true);
        Map<Integer, Long> cache = cb.m_cache;

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals(12345678, cache.get(0).longValue());

        dut.put(0, 23456789);
        while(true) {
            cache = cb.m_cache;
            if (cache.get(0) == 23456789) {
                break;
            }
        }
        cache = cb.m_cache;
        assertEquals("3 items cached.", 3, cache.size());
        assertEquals(23456789, cache.get(0).longValue());
        assertEquals(87654321, cache.get(1).longValue());
        assertEquals(11223344, cache.get(2).longValue());

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testDeleteChild() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache02", zk);

        LeaderCache dut = new LeaderCache(zk, "/cache02");
        dut.start(true);
        Map<Integer, Long> cache = dut.pointInTimeCache();
        assertEquals("3 items cached.", 3, cache.size());

        zk.delete("/cache02/1", -1);
        while(true) {
            cache = dut.pointInTimeCache();
            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();
    }
View Full Code Here

    }

    @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();
    }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper_voltpatches.ZooKeeper$ExistsWatchRegistration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.