Search in sources :

Example 1 with JSONObject

use of com.alibaba.fastjson.JSONObject in project pinot by linkedin.

the class BasePinotControllerRestletResource method getErrorMsgInJson.

protected static JSONObject getErrorMsgInJson(String errorMsg) {
    JSONObject errorMsgJson = new JSONObject();
    errorMsgJson.put("ERROR", errorMsg);
    return errorMsgJson;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with JSONObject

use of com.alibaba.fastjson.JSONObject in project pinot by linkedin.

the class BasePinotControllerRestletResource method exceptionToStringRepresentation.

public static StringRepresentation exceptionToStringRepresentation(Exception e) {
    String errorMsg = e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e);
    JSONObject errorMsgInJson = getErrorMsgInJson(errorMsg);
    return new StringRepresentation(errorMsgInJson.toJSONString(), MediaType.APPLICATION_JSON);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation)

Example 3 with JSONObject

use of com.alibaba.fastjson.JSONObject in project pinot by linkedin.

the class LLCSegmentCommitTest method testSegmentCommit.

@Test
public void testSegmentCommit() throws Exception {
    SegmentCompletionManager.create(createMockHelixManager(), null, new ControllerConf(), new ControllerMetrics(new MetricsRegistry()));
    FakeLLCSegmentCommit segmentCommit = new FakeLLCSegmentCommit();
    Representation representation;
    String strResponse;
    JSONObject jsonResponse;
    // If commitStart returns failed, upload should not be called, and the client should get 'failed'
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_FAILED;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.FAILED.toString());
    Assert.assertFalse(segmentCommit._uploadCalled);
    // if commitStart returns continue, and upload fails, then commitEnd should indicate upload failure.
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_COMMIT_CONTINUE;
    segmentCommit._scm.commitEndResponse = SegmentCompletionProtocol.RESP_FAILED;
    segmentCommit._uploadReturnValue = false;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.FAILED.toString());
    Assert.assertTrue(segmentCommit._uploadCalled);
    Assert.assertFalse(segmentCommit._scm.uploadSuccess);
    // If commitstart returns CONINUE and upload succeeds, we should return whatever commitEnd returns.
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_COMMIT_CONTINUE;
    segmentCommit._scm.commitEndResponse = SegmentCompletionProtocol.RESP_COMMIT_SUCCESS;
    segmentCommit._uploadReturnValue = true;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT_SUCCESS.toString());
    Assert.assertTrue(segmentCommit._uploadCalled);
    Assert.assertTrue(segmentCommit._scm.uploadSuccess);
}
Also used : ControllerConf(com.linkedin.pinot.controller.ControllerConf) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) JSONObject(com.alibaba.fastjson.JSONObject) Representation(org.restlet.representation.Representation) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Example 4 with JSONObject

use of com.alibaba.fastjson.JSONObject in project DataX by alibaba.

the class CommunicationJsonifyTest method testJsonGetSnapshot.

@Test
public void testJsonGetSnapshot() {
    Communication communication = new Communication();
    communication.setLongCounter(CommunicationTool.STAGE, 10);
    communication.setLongCounter(CommunicationTool.READ_SUCCEED_RECORDS, 100);
    communication.setLongCounter(CommunicationTool.READ_SUCCEED_BYTES, 102400);
    communication.setLongCounter(CommunicationTool.BYTE_SPEED, 10240);
    communication.setLongCounter(CommunicationTool.RECORD_SPEED, 100);
    communication.setDoubleCounter(CommunicationTool.PERCENTAGE, 0.1);
    communication.setState(State.RUNNING);
    communication.setLongCounter(CommunicationTool.WRITE_RECEIVED_RECORDS, 99);
    communication.setLongCounter(CommunicationTool.WRITE_RECEIVED_BYTES, 102300);
    String jsonString = CommunicationTool.Jsonify.getSnapshot(communication);
    JSONObject metricJson = JSON.parseObject(jsonString);
    Assert.assertEquals(communication.getLongCounter(CommunicationTool.RECORD_SPEED), metricJson.getLong("speedRecords"));
    Assert.assertEquals(communication.getDoubleCounter(CommunicationTool.PERCENTAGE), metricJson.getDouble("percentage"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Test(org.junit.Test)

Example 5 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXComponent method updateStyleByPesudo.

private void updateStyleByPesudo(Map<String, Object> styles) {
    Message message = Message.obtain();
    WXDomTask task = new WXDomTask();
    task.instanceId = getInstanceId();
    task.args = new ArrayList<>();
    JSONObject styleJson = new JSONObject(styles);
    task.args.add(getRef());
    task.args.add(styleJson);
    //flag pesudo
    task.args.add(true);
    message.obj = task;
    message.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE;
    WXSDKManager.getInstance().getWXDomManager().sendMessage(message);
}
Also used : Message(android.os.Message) WXDomTask(com.taobao.weex.dom.WXDomTask) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1841 HashMap (java.util.HashMap)317 JSONArray (com.alibaba.fastjson.JSONArray)301 Test (org.junit.Test)223 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)188 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)168 IOException (java.io.IOException)146 ArrayList (java.util.ArrayList)141 Map (java.util.Map)123 AuthPassport (com.ngtesting.platform.util.AuthPassport)96 Date (java.util.Date)80 List (java.util.List)77 UserVo (com.ngtesting.platform.vo.UserVo)76 File (java.io.File)73 UnitResponse (info.xiancloud.core.message.UnitResponse)61 JSONException (com.alibaba.fastjson.JSONException)47 StringEntity (org.apache.http.entity.StringEntity)45 HttpResponse (org.apache.http.HttpResponse)44 Header (org.apache.http.Header)37 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)30