Search in sources :

Example 61 with JsonObject

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);
}
Also used : SlowOperationInvocationDTO(com.hazelcast.internal.management.dto.SlowOperationInvocationDTO) JsonObject(com.eclipsesource.json.JsonObject) JsonObject(com.eclipsesource.json.JsonObject) SlowOperationDTO(com.hazelcast.internal.management.dto.SlowOperationDTO) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 62 with JsonObject

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());
}
Also used : ClearWanQueuesRequest(com.hazelcast.internal.management.request.ClearWanQueuesRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 63 with JsonObject

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());
}
Also used : Address(com.hazelcast.nio.Address) ExecuteScriptRequest(com.hazelcast.internal.management.request.ExecuteScriptRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with JsonObject

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);
}
Also used : ExecuteScriptRequest(com.hazelcast.internal.management.request.ExecuteScriptRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 65 with JsonObject

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());
}
Also used : ExecuteScriptRequest(com.hazelcast.internal.management.request.ExecuteScriptRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

JsonObject (com.eclipsesource.json.JsonObject)126 Test (org.junit.Test)41 ParallelTest (com.hazelcast.test.annotation.ParallelTest)38 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonArray (com.eclipsesource.json.JsonArray)14 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)12 HashMap (java.util.HashMap)12 Map (java.util.Map)9 JsonValue (com.eclipsesource.json.JsonValue)5 ExecuteScriptRequest (com.hazelcast.internal.management.request.ExecuteScriptRequest)5 BoxSharedLink (com.box.androidsdk.content.models.BoxSharedLink)4 WanPublisherConfig (com.hazelcast.config.WanPublisherConfig)4 ChangeClusterStateRequest (com.hazelcast.internal.management.request.ChangeClusterStateRequest)3 ChangeWanStateRequest (com.hazelcast.internal.management.request.ChangeWanStateRequest)3 ILogger (com.hazelcast.logging.ILogger)3 IOException (java.io.IOException)3 BoxEntity (com.box.androidsdk.content.models.BoxEntity)2 ParseException (com.eclipsesource.json.ParseException)2 ClusterState (com.hazelcast.cluster.ClusterState)2 MapConfig (com.hazelcast.config.MapConfig)2