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;
}
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);
}
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);
}
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"));
}
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);
}
Aggregations