Search in sources :

Example 51 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class InstanceTrackingInfoTest method testJsonFormat.

@Test
public void testJsonFormat() throws IOException {
    assertTrackingFileContents(null, content -> {
        JsonObject json = Json.parse(content).asObject();
        // since we didn't start with HazelcastMemberStarter
        // the mode will be "embedded"
        assertEquals("embedded", json.getString("mode", ""));
        assertEquals("Hazelcast", json.getString("product", ""));
        assertEquals(0, json.getInt("licensed", -1));
    });
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class InstanceTrackingServerModeTest method testServerMode.

@Test
public void testServerMode() throws Exception {
    File tempFile = tempFolder.newFile();
    System.setProperty("instance_tracking_filename", tempFile.getAbsolutePath());
    HazelcastMemberStarter.main(new String[] {});
    String actualContents = new String(Files.readAllBytes(tempFile.toPath()), StandardCharsets.UTF_8);
    JsonObject json = Json.parse(actualContents).asObject();
    assertEquals("server", json.getString("mode", ""));
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) File(java.io.File) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class RestTest method assertJsonContains.

private JsonObject assertJsonContains(String json, String... attributesAndValues) {
    JsonObject object = Json.parse(json).asObject();
    for (int i = 0; i < attributesAndValues.length; ) {
        String key = attributesAndValues[i++];
        String expectedValue = attributesAndValues[i++];
        assertEquals(expectedValue, object.getString(key, null));
    }
    return object;
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) StringUtil.bytesToString(com.hazelcast.internal.util.StringUtil.bytesToString) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString)

Example 54 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_getMetadataCPGroupByName.

@Test
public void test_getMetadataCPGroupByName() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName(METADATA_CP_GROUP_NAME);
    assertEquals(200, response.responseCode);
    CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
    CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
    boolean cpMember1Found = false;
    boolean cpMember2Found = false;
    boolean cpMember3Found = false;
    JsonObject json = (JsonObject) Json.parse(response.response);
    assertEquals(METADATA_CP_GROUP_NAME, ((JsonObject) json.get("id")).getString("name", ""));
    assertEquals(CPGroupStatus.ACTIVE.name(), json.getString("status", ""));
    for (JsonValue val : (JsonArray) json.get("members")) {
        JsonObject mem = (JsonObject) val;
        cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
    }
    assertTrue(cpMember1Found);
    assertTrue(cpMember2Found);
    assertTrue(cpMember3Found);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) CPMember(com.hazelcast.cp.CPMember) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 55 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_getCustomCPGroupByName.

@Test
public void test_getCustomCPGroupByName() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    instance1.getCPSubsystem().getAtomicLong("long1@custom").set(5);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName("custom");
    assertEquals(200, response.responseCode);
    CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
    CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
    boolean cpMember1Found = false;
    boolean cpMember2Found = false;
    boolean cpMember3Found = false;
    JsonObject json = (JsonObject) Json.parse(response.response);
    assertEquals("custom", ((JsonObject) json.get("id")).getString("name", ""));
    assertEquals(CPGroupStatus.ACTIVE.name(), json.getString("status", ""));
    for (JsonValue val : (JsonArray) json.get("members")) {
        JsonObject mem = (JsonObject) val;
        cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
    }
    assertTrue(cpMember1Found);
    assertTrue(cpMember2Found);
    assertTrue(cpMember3Found);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) CPMember(com.hazelcast.cp.CPMember) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

JsonObject (com.hazelcast.internal.json.JsonObject)151 Test (org.junit.Test)56 JsonArray (com.hazelcast.internal.json.JsonArray)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonValue (com.hazelcast.internal.json.JsonValue)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)10 SlowTest (com.hazelcast.test.annotation.SlowTest)9 HashMap (java.util.HashMap)8 CPMember (com.hazelcast.cp.CPMember)7 ArrayList (java.util.ArrayList)7 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)6 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)5 JsonUtil.toJsonObject (com.hazelcast.internal.util.JsonUtil.toJsonObject)5 Map (java.util.Map)5 ClusterService (com.hazelcast.internal.cluster.ClusterService)4 Address (com.hazelcast.cluster.Address)3