Search in sources :

Example 1 with JsonSerializable

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

the class LocalWanStatsImplTest method testSerialization.

@Test
public void testSerialization() {
    LocalWanPublisherStatsImpl tokyo = new LocalWanPublisherStatsImpl();
    tokyo.setConnected(true);
    tokyo.incrementPublishedEventCount(10);
    tokyo.setOutboundQueueSize(100);
    tokyo.setState(WanPublisherState.REPLICATING);
    LocalWanPublisherStatsImpl singapore = new LocalWanPublisherStatsImpl();
    singapore.setConnected(true);
    singapore.setOutboundQueueSize(200);
    singapore.incrementPublishedEventCount(20);
    singapore.setState(WanPublisherState.REPLICATING);
    LocalWanStatsImpl localWanStats = new LocalWanStatsImpl();
    Map<String, LocalWanPublisherStats> localWanPublisherStatsMap = new HashMap<String, LocalWanPublisherStats>();
    localWanPublisherStatsMap.put("tokyo", tokyo);
    localWanPublisherStatsMap.put("singapore", singapore);
    localWanStats.setLocalPublisherStatsMap(localWanPublisherStatsMap);
    JsonObject serialized = localWanStats.toJson();
    LocalWanStats deserialized = new LocalWanStatsImpl();
    ((JsonSerializable) deserialized).fromJson(serialized);
    LocalWanPublisherStats deserializedTokyo = deserialized.getLocalWanPublisherStats().get("tokyo");
    LocalWanPublisherStats deserializedSingapore = deserialized.getLocalWanPublisherStats().get("singapore");
    assertEquals(tokyo.isConnected(), deserializedTokyo.isConnected());
    assertEquals(tokyo.getPublisherState(), deserializedTokyo.getPublisherState());
    assertEquals(singapore.isConnected(), deserializedSingapore.isConnected());
    assertEquals(singapore.getPublisherState(), deserializedSingapore.getPublisherState());
}
Also used : LocalWanPublisherStats(com.hazelcast.internal.monitor.LocalWanPublisherStats) HashMap(java.util.HashMap) LocalWanStats(com.hazelcast.internal.monitor.LocalWanStats) JsonSerializable(com.hazelcast.json.internal.JsonSerializable) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with JsonSerializable

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

the class SlowOperationDetectorAbstractTest method getOperationStats.

static JsonObject getOperationStats(HazelcastInstance instance) {
    TimedMemberStateFactory timedMemberStateFactory = new TimedMemberStateFactory(getHazelcastInstanceImpl(instance));
    LocalOperationStats operationStats = timedMemberStateFactory.createTimedMemberState().getMemberState().getOperationStats();
    return ((JsonSerializable) operationStats).toJson();
}
Also used : TimedMemberStateFactory(com.hazelcast.internal.management.TimedMemberStateFactory) LocalOperationStats(com.hazelcast.internal.monitor.LocalOperationStats) JsonSerializable(com.hazelcast.json.internal.JsonSerializable)

Aggregations

JsonSerializable (com.hazelcast.json.internal.JsonSerializable)2 JsonObject (com.hazelcast.internal.json.JsonObject)1 TimedMemberStateFactory (com.hazelcast.internal.management.TimedMemberStateFactory)1 LocalOperationStats (com.hazelcast.internal.monitor.LocalOperationStats)1 LocalWanPublisherStats (com.hazelcast.internal.monitor.LocalWanPublisherStats)1 LocalWanStats (com.hazelcast.internal.monitor.LocalWanStats)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1