Search in sources :

Example 1 with HotRestartState

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());
}
Also used : BackupTaskStatus(com.hazelcast.persistence.BackupTaskStatus) HotRestartState(com.hazelcast.internal.monitor.HotRestartState) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with HotRestartState

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));
}
Also used : NodeState(com.hazelcast.internal.monitor.NodeState) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) UUID(java.util.UUID) ClusterHotRestartStatusDTO(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO) TimedMemberState(com.hazelcast.internal.management.TimedMemberState) ClusterState(com.hazelcast.cluster.ClusterState) TimedMemberStateFactory(com.hazelcast.internal.management.TimedMemberStateFactory) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) CacheStatisticsImpl(com.hazelcast.cache.impl.CacheStatisticsImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BackupTaskStatus(com.hazelcast.persistence.BackupTaskStatus) HotRestartState(com.hazelcast.internal.monitor.HotRestartState) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HotRestartState (com.hazelcast.internal.monitor.HotRestartState)2 BackupTaskStatus (com.hazelcast.persistence.BackupTaskStatus)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 CacheStatisticsImpl (com.hazelcast.cache.impl.CacheStatisticsImpl)1 Address (com.hazelcast.cluster.Address)1 ClusterState (com.hazelcast.cluster.ClusterState)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 TimedMemberState (com.hazelcast.internal.management.TimedMemberState)1 TimedMemberStateFactory (com.hazelcast.internal.management.TimedMemberStateFactory)1 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)1 ClusterHotRestartStatusDTO (com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO)1 NodeState (com.hazelcast.internal.monitor.NodeState)1 MemberVersion (com.hazelcast.version.MemberVersion)1 Version (com.hazelcast.version.Version)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1