use of com.eclipsesource.json.JsonObject in project hazelcast by hazelcast.
the class SlowOperationDetector_JsonTest method testJSON.
@Test
public void testJSON() throws InterruptedException {
final String operationDetails = "FakeOperation(id=255, partitionId=2)";
Object operation = new Object() {
@Override
public String toString() {
return operationDetails;
}
};
String stackTrace = "stackTrace";
int id = 5;
int durationMs = 4444;
long nowMillis = System.currentTimeMillis();
long nowNanos = System.nanoTime();
long durationNanos = TimeUnit.MILLISECONDS.toNanos(durationMs);
SlowOperationLog log = new SlowOperationLog(stackTrace, operation);
log.totalInvocations.incrementAndGet();
log.getOrCreate(id, operationDetails, durationNanos, nowNanos, nowMillis);
JsonObject json = log.createDTO().toJson();
logger.finest(json.toString());
SlowOperationDTO slowOperationDTO = new SlowOperationDTO();
slowOperationDTO.fromJson(json);
assertTrue(format("Expected operation '%s' to contain inner class", slowOperationDTO.operation), slowOperationDTO.operation.contains("SlowOperationDetector_JsonTest$1"));
assertEqualsStringFormat("Expected stack trace '%s', but was '%s'", stackTrace, slowOperationDTO.stackTrace);
assertEqualsStringFormat("Expected totalInvocations '%d', but was '%d'", 1, slowOperationDTO.totalInvocations);
assertEqualsStringFormat("Expected invocations.size() '%d', but was '%d'", 1, slowOperationDTO.invocations.size());
SlowOperationInvocationDTO invocationDTO = slowOperationDTO.invocations.get(0);
assertEqualsStringFormat("Expected id '%d', but was '%d'", id, invocationDTO.id);
assertEqualsStringFormat("Expected details '%s', but was '%s'", operationDetails, invocationDTO.operationDetails);
assertEqualsStringFormat("Expected startedAt '%d', but was '%d'", nowMillis - durationMs, invocationDTO.startedAt);
assertEqualsStringFormat("Expected durationMs '%d', but was '%d'", durationMs, invocationDTO.durationMs);
}
use of com.eclipsesource.json.JsonObject in project hazelcast by hazelcast.
the class ClearWanQueuesTest method testSerialization.
@Test
public void testSerialization() {
ClearWanQueuesRequest clearWanQueuesRequest1 = new ClearWanQueuesRequest("schema", "publisher");
JsonObject jsonObject = clearWanQueuesRequest1.toJson();
ClearWanQueuesRequest clearWanQueuesRequest2 = new ClearWanQueuesRequest();
clearWanQueuesRequest2.fromJson(jsonObject);
assertEquals(clearWanQueuesRequest1.getPublisherName(), clearWanQueuesRequest2.getPublisherName());
assertEquals(clearWanQueuesRequest1.getSchemeName(), clearWanQueuesRequest2.getSchemeName());
}
use of com.eclipsesource.json.JsonObject in project hazelcast by hazelcast.
the class ExecuteScriptRequestTest method testExecuteScriptRequest_whenTargetAllMembers_withTarget.
@Test
public void testExecuteScriptRequest_whenTargetAllMembers_withTarget() throws Exception {
Address address = cluster.getLocalMember().getAddress();
Set<String> targets = Collections.singleton(address.getHost() + ":" + address.getPort());
ExecuteScriptRequest request = new ExecuteScriptRequest("print('test');", "JavaScript", targets, bindings);
JsonObject jsonObject = new JsonObject();
request.writeResponse(managementCenterService, jsonObject);
JsonObject result = (JsonObject) jsonObject.get("result");
String response = (String) request.readResponse(result);
assertEquals("error", response.trim());
}
use of com.eclipsesource.json.JsonObject in project hazelcast by hazelcast.
the class ExecuteScriptRequestTest method testExecuteScriptRequest_whenTargetAllMembers.
@Test
public void testExecuteScriptRequest_whenTargetAllMembers() throws Exception {
ExecuteScriptRequest request = new ExecuteScriptRequest("print('test');", "JavaScript", true, null);
JsonObject jsonObject = new JsonObject();
request.writeResponse(managementCenterService, jsonObject);
JsonObject result = (JsonObject) jsonObject.get("result");
String response = (String) request.readResponse(result);
assertEquals("error\nerror\n", response);
}
use of com.eclipsesource.json.JsonObject in project hazelcast by hazelcast.
the class ExecuteScriptRequestTest method testExecuteScriptRequest.
@Test
public void testExecuteScriptRequest() throws Exception {
ExecuteScriptRequest request = new ExecuteScriptRequest("print('test');", "JavaScript", false, bindings);
JsonObject jsonObject = new JsonObject();
request.writeResponse(managementCenterService, jsonObject);
JsonObject result = (JsonObject) jsonObject.get("result");
String response = (String) request.readResponse(result);
assertEquals("", response.trim());
}
Aggregations