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();
}
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());
}
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());
}
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);
}
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);
}
Aggregations