Search in sources :

Example 16 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class HTTPBenchmark method responseFromJSON.

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);
        System.out.println(response.results[i].toString());
    }
    if (jsonObj.isNull("status") == false) {
        response.status = (byte) jsonObj.getInt("status");
    }
    if (jsonObj.isNull("appstatus") == false) {
        response.appStatus = (byte) jsonObj.getInt("appstatus");
    }
    if (jsonObj.isNull("statusstring") == false) {
        response.statusString = jsonObj.getString("statusstring");
    }
    if (jsonObj.isNull("appstatusstring") == false) {
        response.appStatusString = jsonObj.getString("appstatusstring");
    }
    if (jsonObj.isNull("exception") == false) {
        response.exception = jsonObj.getString("exception");
    }
    return response;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

Example 17 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class TestCollector method getWorkingDir.

private String getWorkingDir(String voltDbRootPath) throws Exception {
    File configLogDir = new File(voltDbRootPath, Constants.CONFIG_DIR);
    File configInfo = new File(configLogDir, "config.json");
    JSONObject jsonObject = Collector.parseJSONFile(configInfo.getCanonicalPath());
    String workingDir = jsonObject.getString("workingDir");
    return workingDir;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 18 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class TestCollector method getLogPaths.

private List<String> getLogPaths(String voltDbRootPath) throws Exception {
    File configLogDir = new File(voltDbRootPath, Constants.CONFIG_DIR);
    File configInfo = new File(configLogDir, "config.json");
    JSONObject jsonObject = Collector.parseJSONFile(configInfo.getCanonicalPath());
    List<String> logPaths = new ArrayList<String>();
    JSONArray jsonArray = jsonObject.getJSONArray("log4jDst");
    for (int i = 0; i < jsonArray.length(); i++) {
        String path = jsonArray.getJSONObject(i).getString("path");
        logPaths.add(path);
    }
    return logPaths;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json_voltpatches.JSONArray) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 19 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class TestSpSchedulerSpHandle method createObjs.

public void createObjs() throws JSONException {
    mbox = mock(Mailbox.class);
    when(mbox.getHSId()).thenReturn(dut_hsid);
    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));
    final CommandLog cl = mock(CommandLog.class);
    doReturn(CoreUtils.COMPLETED_FUTURE).when(cl).log(any(Iv2InitiateTaskMessage.class), anyLong(), any(int[].class), any(CommandLog.DurabilityListener.class), any(TransactionTask.class));
    dut = new SpScheduler(0, getSiteTaskerQueue(), snapMonitor);
    dut.setMailbox(mbox);
    dut.setCommandLog(cl);
    dut.setLock(mbox);
}
Also used : Mailbox(org.voltcore.messaging.Mailbox) SnapshotCompletionMonitor(org.voltdb.SnapshotCompletionMonitor) JSONObject(org.json_voltpatches.JSONObject) MapCache(org.voltcore.zk.MapCache) HashMap(java.util.HashMap) CommandLog(org.voltdb.CommandLog) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

Example 20 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class TestSpSchedulerDedupe method createObjs.

public void createObjs() throws JSONException {
    mbox = mock(Mailbox.class);
    when(mbox.getHSId()).thenReturn(dut_hsid);
    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));
    final CommandLog cl = mock(CommandLog.class);
    doReturn(CoreUtils.COMPLETED_FUTURE).when(cl).log(any(Iv2InitiateTaskMessage.class), anyLong(), any(int[].class), any(CommandLog.DurabilityListener.class), any(TransactionTask.class));
    dut = new SpScheduler(0, getSiteTaskerQueue(), snapMonitor);
    dut.setMailbox(mbox);
    dut.setCommandLog(cl);
    dut.setLock(mbox);
    ((SpScheduler) dut).setConsistentReadLevelForTestOnly(m_readLevel);
}
Also used : Mailbox(org.voltcore.messaging.Mailbox) SnapshotCompletionMonitor(org.voltdb.SnapshotCompletionMonitor) JSONObject(org.json_voltpatches.JSONObject) MapCache(org.voltcore.zk.MapCache) HashMap(java.util.HashMap) CommandLog(org.voltdb.CommandLog) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

Aggregations

JSONObject (org.json_voltpatches.JSONObject)123 JSONException (org.json_voltpatches.JSONException)45 JSONArray (org.json_voltpatches.JSONArray)30 IOException (java.io.IOException)20 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)18 HashMap (java.util.HashMap)17 File (java.io.File)14 Map (java.util.Map)14 ByteBuffer (java.nio.ByteBuffer)13 ExecutionException (java.util.concurrent.ExecutionException)12 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 TreeSet (java.util.TreeSet)6 JSONStringer (org.json_voltpatches.JSONStringer)6 HashSet (java.util.HashSet)5 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)5 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)4 InetAddress (java.net.InetAddress)4