Package org.json_voltpatches

Examples of org.json_voltpatches.JSONArray


    }

    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


        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);

        // try to pass a string as a date
        java.sql.Timestamp ts = new java.sql.Timestamp(System.currentTimeMillis());
        ts.setNanos(123456000);
View Full Code Here

    }

    private List<PartitionPair> parseRanges(JSONObject jsObj) throws JSONException
    {
        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")));
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);
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

        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));
            }
            assertTrue(replicasContents.contains(0));
            assertTrue(replicasContents.contains(1));
            assertTrue(replicasContents.contains(2));
View Full Code Here

    public static List<Integer> partitionsForHost(JSONObject topo, int hostId) throws JSONException
    {
        List<Integer> partitions = new ArrayList<Integer>();

        JSONArray parts = topo.getJSONArray("partitions");

        for (int p = 0; p < parts.length(); p++) {
            // have an object in the partitions array
            JSONObject aPartition = parts.getJSONObject(p);
            int pid = aPartition.getInt("partition_id");
            JSONArray replicas = aPartition.getJSONArray("replicas");
            for (int h = 0; h < replicas.length(); h++)
            {
                int replica = replicas.getInt(h);
                if (replica == hostId)
                {
                    partitions.add(pid);
                }
            }
View Full Code Here

     * @throws JSONException
     */
    public static void addPartitions(JSONObject topo, Multimap<Integer, Integer> partToHost)
        throws JSONException
    {
        JSONArray partitions = topo.getJSONArray("partitions");
        for (Map.Entry<Integer, Collection<Integer>> e : partToHost.asMap().entrySet()) {
            int partition = e.getKey();
            Collection<Integer> hosts = e.getValue();

            JSONObject partObj = new JSONObject();
            partObj.put("partition_id", partition);
            partObj.put("replicas", hosts);

            partitions.put(partObj);
        }
    }
View Full Code Here

        InetAddress addr = null;
        int clientPort = VoltDB.DEFAULT_PORT;
        try {
            String localMetadata = VoltDB.instance().getLocalMetadata();
            JSONObject jsObj = new JSONObject(localMetadata);
            JSONArray interfaces = jsObj.getJSONArray("interfaces");
            String iface = interfaces.getString(0);
            addr = InetAddress.getByName(iface);
            clientPort = jsObj.getInt("clientPort");
        } catch (JSONException e) {
            hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
        } catch (UnknownHostException e) {
View Full Code Here

            e1.printStackTrace();
        }
        JSONObject jobj;
        try {
            jobj = new JSONObject( prettyJson );
            JSONArray jarray =  jobj.getJSONArray("PLAN_NODES");
            Database db = s_singleton.getDatabase();
            pnt.loadFromJSONArray(jarray, db);
        } catch (JSONException e) {
            e.printStackTrace();
        }
View Full Code Here

TOP

Related Classes of org.json_voltpatches.JSONArray

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.