Search in sources :

Example 16 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo in project nacos by alibaba.

the class ClientBeatUpdateTask method run.

@Override
public void run() {
    long currentTime = System.currentTimeMillis();
    for (InstancePublishInfo each : client.getAllInstancePublishInfo()) {
        ((HealthCheckInstancePublishInfo) each).setLastHeartBeatTime(currentTime);
    }
    client.setLastUpdatedTime();
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 17 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo in project nacos by alibaba.

the class HealthCheckTaskInterceptWrapperTest method testRunHealthyInstanceWithTimeoutFromMetadata.

@Test
public void testRunHealthyInstanceWithTimeoutFromMetadata() throws InterruptedException {
    InstancePublishInfo instance = injectInstance(true, System.currentTimeMillis());
    Service service = Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME);
    InstanceMetadata metadata = new InstanceMetadata();
    metadata.getExtendData().put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, 1000L);
    when(namingMetadataManager.getInstanceMetadata(service, instance.getMetadataId())).thenReturn(Optional.of(metadata));
    when(globalConfig.isExpireInstance()).thenReturn(true);
    TimeUnit.SECONDS.sleep(1);
    taskWrapper.run();
    assertFalse(client.getAllInstancePublishInfo().isEmpty());
    assertFalse(client.getInstancePublishInfo(Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME)).isHealthy());
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 18 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo in project nacos by alibaba.

the class PersistentHealthStatusSynchronizerTest method testInstanceHealthStatusChange.

@Test
public void testInstanceHealthStatusChange() {
    Service service = Service.newService("public", "DEFAULT", "nacos", true);
    InstancePublishInfo instancePublishInfo = new InstancePublishInfo("127.0.0.1", 8080);
    PersistentHealthStatusSynchronizer persistentHealthStatusSynchronizer = new PersistentHealthStatusSynchronizer(persistentClientOperationService);
    persistentHealthStatusSynchronizer.instanceHealthStatusChange(true, client, service, instancePublishInfo);
    Instance updateInstance = InstanceUtil.parseToApiInstance(service, instancePublishInfo);
    updateInstance.setHealthy(true);
    verify(client).getClientId();
    verify(persistentClientOperationService).registerInstance(service, updateInstance, client.getClientId());
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 19 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo in project nacos by alibaba.

the class InstanceUtilTest method init.

@Before
public void init() {
    service = Service.newService("namespace", "group", "serviceName");
    instancePublishInfo = new InstancePublishInfo("1.1.1.1", 8080);
}
Also used : InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Before(org.junit.Before)

Example 20 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo in project nacos by alibaba.

the class InstanceUtilTest method testUpdateInstanceMetadata.

@Test
public void testUpdateInstanceMetadata() {
    InstanceMetadata metaData = new InstanceMetadata();
    Map<String, Object> extendData = new ConcurrentHashMap<>(1);
    extendData.put("k1", "v1");
    extendData.put("k2", "v2");
    metaData.setExtendData(extendData);
    metaData.setEnabled(true);
    metaData.setWeight(1);
    Instance instance = InstanceUtil.parseToApiInstance(service, instancePublishInfo);
    InstanceUtil.updateInstanceMetadata(instance, metaData);
    assertNotNull(instance.getMetadata());
    assertEquals(metaData.getExtendData().size(), 2);
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Aggregations

InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)17 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)9 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 Client (com.alibaba.nacos.naming.core.v2.client.Client)5 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)5 Test (org.junit.Test)5 ClientOperationEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent)4 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)4 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)4 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)3 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)3 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)3 MetadataEvent (com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 NacosRuntimeException (com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)1 ClientAttributes (com.alibaba.nacos.naming.core.v2.client.ClientAttributes)1 ConnectionBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1