Search in sources :

Example 26 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class ClientBeatCheckTaskTest method testHeartBeatTimeout.

@Test
public void testHeartBeatTimeout() {
    Instance instance = new Instance();
    instance.setLastBeat(System.currentTimeMillis() - 1000);
    instance.setMarked(false);
    instance.setHealthy(true);
    Map<String, String> metadata = new HashMap<>();
    metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "10");
    instance.setMetadata(metadata);
    List<Instance> instances = new ArrayList<>();
    instances.add(instance);
    Mockito.doReturn("test").when(serviceSpy).getName();
    Mockito.doReturn(true).when(distroMapperSpy).responsible(Mockito.anyString());
    Mockito.doReturn(true).when(switchDomain).isHealthCheckEnabled();
    when(serviceSpy.allIPs(true)).thenReturn(instances);
    clientBeatCheckTask.run();
    Assert.assertFalse(instance.isHealthy());
}
Also used : Instance(com.alibaba.nacos.naming.core.Instance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Instance (com.alibaba.nacos.naming.core.Instance)26 Test (org.junit.Test)13 Instances (com.alibaba.nacos.naming.core.Instances)6 HashMap (java.util.HashMap)6 BaseTest (com.alibaba.nacos.naming.BaseTest)5 Cluster (com.alibaba.nacos.naming.core.Cluster)5 Service (com.alibaba.nacos.naming.core.Service)5 ArrayList (java.util.ArrayList)5 Datum (com.alibaba.nacos.naming.consistency.Datum)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 LinkedList (java.util.LinkedList)3 InstanceOperationInfo (com.alibaba.nacos.naming.pojo.InstanceOperationInfo)2 Function (java.util.function.Function)2 Before (org.junit.Before)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 AbstractHealthChecker (com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker)1 Http (com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http)1