use of com.hazelcast.internal.monitor.HotRestartState in project hazelcast by hazelcast.
the class HotRestartStateImplTest method testSerializationAndDeserizalization.
@Test
public void testSerializationAndDeserizalization() {
final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
final String backupDirectory = "/some/dir";
final HotRestartState state = new HotRestartStateImpl(backupTaskStatus, true, backupDirectory);
final HotRestartStateImpl deserialized = new HotRestartStateImpl();
deserialized.fromJson(state.toJson());
assertEquals(backupTaskStatus, deserialized.getBackupTaskStatus());
assertTrue(deserialized.isHotBackupEnabled());
assertEquals(backupDirectory, deserialized.getBackupDirectory());
}
use of com.hazelcast.internal.monitor.HotRestartState in project hazelcast by hazelcast.
the class MemberStateImplTest method testSerialization.
@Test
public void testSerialization() throws UnknownHostException {
HazelcastInstance hazelcastInstance = createHazelcastInstance();
LocalReplicatedMapStatsImpl replicatedMapStats = new LocalReplicatedMapStatsImpl();
replicatedMapStats.incrementPutsNanos(30);
CacheStatisticsImpl cacheStatistics = new CacheStatisticsImpl(Clock.currentTimeMillis());
cacheStatistics.increaseCacheHits(5);
UUID clientUuid = UUID.randomUUID();
Collection<ClientEndPointDTO> clients = new ArrayList<>();
ClientEndPointDTO client = new ClientEndPointDTO();
client.uuid = clientUuid;
client.address = "localhost";
client.clientType = "undefined";
client.name = "aClient";
client.labels = new HashSet<>(Collections.singletonList("label"));
client.ipAddress = "10.176.167.34";
client.canonicalHostName = "ip-10-176-167-34.ec2.internal";
clients.add(client);
ClusterState clusterState = ClusterState.ACTIVE;
com.hazelcast.instance.impl.NodeState nodeState = com.hazelcast.instance.impl.NodeState.PASSIVE;
Version clusterVersion = Version.of("3.9.0");
MemberVersion memberVersion = MemberVersion.of("3.8.0");
NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
final String backupDirectory = "/hot/backup/dir";
final HotRestartStateImpl hotRestartState = new HotRestartStateImpl(backupTaskStatus, true, backupDirectory);
Map<UUID, String> clientStats = new HashMap<>();
clientStats.put(clientUuid, "someStats");
Map<EndpointQualifier, Address> endpoints = new HashMap<>();
endpoints.put(EndpointQualifier.MEMBER, new Address("127.0.0.1", 5701));
endpoints.put(EndpointQualifier.resolve(ProtocolType.WAN, "MyWAN"), new Address("127.0.0.1", 5901));
TimedMemberStateFactory factory = new TimedMemberStateFactory(getHazelcastInstanceImpl(hazelcastInstance));
TimedMemberState timedMemberState = factory.createTimedMemberState();
MemberStateImpl memberState = timedMemberState.getMemberState();
memberState.setAddress("memberStateAddress:Port");
UUID uuid = UUID.randomUUID();
memberState.setUuid(uuid);
UUID cpMemberUuid = UUID.randomUUID();
memberState.setCpMemberUuid(cpMemberUuid);
memberState.setEndpoints(endpoints);
memberState.setMapsWithStats(singleton("map-1"));
memberState.setMultiMapsWithStats(singleton("multiMap-1"));
memberState.setReplicatedMapsWithStats(singleton("replicatedMap-1"));
memberState.setQueuesWithStats(singleton("queue-1"));
memberState.setTopicsWithStats(singleton("topic-1"));
memberState.setReliableTopicsWithStats(singleton("reliableTopic-1"));
memberState.setPNCountersWithStats(singleton("pnCounter-1"));
memberState.setExecutorsWithStats(singleton("executor-1"));
memberState.setCachesWithStats(singleton("cache-1"));
memberState.setFlakeIdGeneratorsWithStats(singleton("flakeIdGenerator-1"));
memberState.setOperationStats(new LocalOperationStatsImpl());
memberState.setClients(clients);
memberState.setNodeState(state);
memberState.setHotRestartState(hotRestartState);
memberState.setClientStats(clientStats);
MemberStateImpl deserialized = new MemberStateImpl();
deserialized.fromJson(memberState.toJson());
assertEquals("memberStateAddress:Port", deserialized.getAddress());
assertEquals(uuid, deserialized.getUuid());
assertEquals(cpMemberUuid, deserialized.getCpMemberUuid());
assertEquals(endpoints, deserialized.getEndpoints());
assertNotNull(deserialized.getName());
assertEquals(deserialized.getName(), memberState.getName());
assertEquals(singleton("map-1"), deserialized.getMapsWithStats());
assertEquals(singleton("multiMap-1"), deserialized.getMultiMapsWithStats());
assertEquals(singleton("replicatedMap-1"), deserialized.getReplicatedMapsWithStats());
assertEquals(singleton("queue-1"), deserialized.getQueuesWithStats());
assertEquals(singleton("topic-1"), deserialized.getTopicsWithStats());
assertEquals(singleton("reliableTopic-1"), deserialized.getReliableTopicsWithStats());
assertEquals(singleton("pnCounter-1"), deserialized.getPNCountersWithStats());
assertEquals(singleton("executor-1"), deserialized.getExecutorsWithStats());
assertEquals(singleton("cache-1"), deserialized.getCachesWithStats());
assertEquals(singleton("flakeIdGenerator-1"), deserialized.getFlakeIdGeneratorsWithStats());
assertNotNull(deserialized.getOperationStats());
client = deserialized.getClients().iterator().next();
assertEquals(clientUuid, client.uuid);
assertEquals("localhost", client.address);
assertEquals("undefined", client.clientType);
assertEquals("aClient", client.name);
assertContains(client.labels, "label");
assertEquals("10.176.167.34", client.ipAddress);
assertEquals("ip-10-176-167-34.ec2.internal", client.canonicalHostName);
NodeState deserializedState = deserialized.getNodeState();
assertEquals(clusterState, deserializedState.getClusterState());
assertEquals(nodeState, deserializedState.getNodeState());
assertEquals(clusterVersion, deserializedState.getClusterVersion());
assertEquals(memberVersion, deserializedState.getMemberVersion());
final HotRestartState deserializedHotRestartState = deserialized.getHotRestartState();
assertTrue(deserializedHotRestartState.isHotBackupEnabled());
assertEquals(backupTaskStatus, deserializedHotRestartState.getBackupTaskStatus());
assertEquals(backupDirectory, deserializedHotRestartState.getBackupDirectory());
ClusterHotRestartStatusDTO clusterHotRestartStatus = deserialized.getClusterHotRestartStatus();
assertEquals(FULL_RECOVERY_ONLY, clusterHotRestartStatus.getDataRecoveryPolicy());
assertEquals(ClusterHotRestartStatusDTO.ClusterHotRestartStatus.UNKNOWN, clusterHotRestartStatus.getHotRestartStatus());
assertEquals(-1, clusterHotRestartStatus.getRemainingValidationTimeMillis());
assertEquals(-1, clusterHotRestartStatus.getRemainingDataLoadTimeMillis());
assertTrue(clusterHotRestartStatus.getMemberHotRestartStatusMap().isEmpty());
Map<UUID, String> deserializedClientStats = deserialized.getClientStats();
assertEquals("someStats", deserializedClientStats.get(clientUuid));
}
Aggregations