Package org.json_voltpatches

Examples of org.json_voltpatches.JSONObject$Null


        return js.toString();
    }

    static Object paramFromPossibleJSON(Object value) throws JSONException, IOException {
        if (value instanceof JSONObject) {
            JSONObject jsonObj = (JSONObject) value;
            return VoltTable.fromJSONObject(jsonObj);
        }
        if (value instanceof JSONArray) {
            JSONArray array = (JSONArray) value;
            Object[] retval = new Object[array.length()];
View Full Code Here


        return callProcOverJSONRaw(varString, expectedCode);
    }

    public static Response responseFromJSON(String jsonStr) throws JSONException, IOException {
        Response response = new Response();
        JSONObject jsonObj = new JSONObject(jsonStr);
        JSONArray resultsJson = jsonObj.getJSONArray("results");
        response.results = new VoltTable[resultsJson.length()];
        for (int i = 0; i < response.results.length; i++) {
            JSONObject tableJson = resultsJson.getJSONObject(i);
            response.results[i] =  VoltTable.fromJSONObject(tableJson);
        }
        if (jsonObj.isNull("status") == false)
            response.status = (byte) jsonObj.getInt("status");
        if (jsonObj.isNull("appstatus") == false)
View Full Code Here

        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertEquals(ClientResponse.SUCCESS, response.status);

        // check the JSON itself makes sense
        JSONObject jsonObj = new JSONObject(responseJSON);
        JSONArray results = jsonObj.getJSONArray("results");
        assertEquals(4, response.results.length);
        JSONObject table = results.getJSONObject(0);
        JSONArray data = table.getJSONArray("data");
        assertEquals(1, data.length());
        JSONArray row = data.getJSONArray(0);
        assertEquals(1, row.length());
        long value = row.getLong(0);
        assertEquals(1, value);
View Full Code Here

        iv2masters = mock(MapCache.class);
        snapMonitor = mock(SnapshotCompletionMonitor.class);

        // make fake MapCache of iv2masters
        HashMap<String,JSONObject> fakecache = new HashMap<String, JSONObject>();
        fakecache.put("0", new JSONObject("{hsid:0}"));
        when(iv2masters.pointInTimeCache()).thenReturn(ImmutableMap.copyOf(fakecache));

        dut = new SpScheduler(0, getSiteTaskerQueue(), snapMonitor);
        dut.setMailbox(mbox);
        dut.setCommandLog(mock(CommandLog.class));
View Full Code Here

    {
        ImmutableList.Builder<PartitionPair> builder = ImmutableList.builder();
        JSONArray pairsArray = jsObj.getJSONArray("partitionPairs");

        for (int i = 0; i < pairsArray.length(); i++) {
            JSONObject pairObj = pairsArray.getJSONObject(i);

            builder.add(new PartitionPair(pairObj.getInt("srcPartition"),
                                          pairObj.getInt("destPartition"),
                                          pairObj.getInt("rangeStart"),
                                          pairObj.getInt("rangeEnd")));
        }

        return builder.build();
    }
View Full Code Here

    }

    public MockVoltDB(int clientPort, int adminPort, int httpPort, int drPort)
    {
        try {
            JSONObject obj = new JSONObject();
            JSONArray jsonArray = new JSONArray();
            jsonArray.put("127.0.0.1");
            obj.put("interfaces", jsonArray);
            obj.put("clientPort", clientPort);
            obj.put("adminPort", adminPort);
            obj.put("httpPort", httpPort);
            obj.put("drPort", drPort);
            obj.put("drInterface", "127.0.0.1");

            m_localMetadata = obj.toString(4);

            m_catalog = new Catalog();
            m_catalog.execute("add / clusters " + m_clusterName);
            m_catalog.execute("add " + m_catalog.getClusters().get(m_clusterName).getPath() + " databases " +
                    m_databaseName);
View Full Code Here

    @Override
    protected void collectStatsImpl(Connection c, long clientHandle, OpsSelector selector,
            ParameterSet params) throws Exception
            {
        JSONObject obj = new JSONObject();
        obj.put("selector", "STATISTICS");
        // parseParamsForStatistics has a clumsy contract, see definition
        String err = null;
        if (selector == OpsSelector.STATISTICS) {
            err = parseParamsForStatistics(params, obj);
        }
        else {
            err = "StatsAgent received non-STATISTICS selector: " + selector.name();
        }
        if (err != null) {
            sendErrorResponse(c, ClientResponse.GRACEFUL_FAILURE, err, clientHandle);
            return;
        }
        String subselector = obj.getString("subselector");

        // Some selectors can provide a single answer based on global data.
        // Intercept them and respond before doing the distributed stuff.
        if (subselector.equalsIgnoreCase("TOPO")) {
            PendingOpsRequest psr = new PendingOpsRequest(
View Full Code Here

    public void testLoadQueryPlanTree(String sql) throws JSONException {
        AbstractPlanNode pn = compile(sql);
        PlanNodeTree pnt = new PlanNodeTree(pn);
        String str = pnt.toJSONString();
        System.out.println(str);
        JSONArray jarray = new JSONObject(str)
                .getJSONArray(PlanNodeTree.Members.PLAN_NODES.name());
        PlanNodeTree pnt1 = new PlanNodeTree();
        pnt1.loadFromJSONArray(jarray, getDatabase());
        String str1 = pnt1.toJSONString();
        assertTrue(str.equals(str1));
View Full Code Here

                                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);
                    m_rvdb.setReplicationActive(replicationActive);
                }
            } catch (Exception e) {
View Full Code Here

{
    public void testNonZeroReplicationFactor() throws Exception
    {
        ClusterConfig config = new ClusterConfig(3, 1, 2);
        List<Integer> topology = Arrays.asList(new Integer[] { 0, 1, 2 });
        JSONObject obj = config.getTopology(topology);
        config.validate();
        System.out.println(obj.toString(4));
        JSONArray partitions = obj.getJSONArray("partitions");

        // despite 3 hosts, should only have 1 partition with k-safety of 2
        assertEquals(1, partitions.length());

        // All the execution sites should have the same relative index
        for (int ii = 0; ii < partitions.length(); ii++) {
            JSONObject partition = partitions.getJSONObject(ii);
            assertEquals(0, partition.getInt("partition_id"));
            JSONArray replicas = partition.getJSONArray("replicas");
            assertEquals(3, replicas.length());
            HashSet<Integer> replicasContents = new HashSet<Integer>();
            for (int zz = 0; zz < replicas.length(); zz++) {
                replicasContents.add(replicas.getInt(zz));
            }
View Full Code Here

TOP

Related Classes of org.json_voltpatches.JSONObject$Null

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.