buf fix ip count metrics (#9355)

* buf fix ip count metrics

* run ci

* run ci
This commit is contained in:
陈浩 Nineteen 2022-10-21 09:26:20 +08:00 committed by GitHub
parent 0bd589cb6d
commit 83855da734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

@ -187,7 +187,7 @@ public abstract class AbstractClient implements Client {
MetricsMonitor.getIpCountMonitor().decrementAndGet(); MetricsMonitor.getIpCountMonitor().decrementAndGet();
} }
} }
MetricsMonitor.getIpCountMonitor().addAndGet(-1 * subscribers.size()); MetricsMonitor.getSubscriberCount().addAndGet(-1 * subscribers.size());
} }
@Override @Override

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.core.v2.client;
import com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo; import com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo;
import com.alibaba.nacos.naming.core.v2.pojo.Service; import com.alibaba.nacos.naming.core.v2.pojo.Service;
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
import com.alibaba.nacos.naming.pojo.Subscriber; import com.alibaba.nacos.naming.pojo.Subscriber;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -45,16 +46,18 @@ public class AbstractClientTest {
instancePublishInfo = new InstancePublishInfo("127.0.0.1", 8890); instancePublishInfo = new InstancePublishInfo("127.0.0.1", 8890);
subscriber = new Subscriber("127.0.0.1:8848", "agent1", "appName", "127.0.0.1", subscriber = new Subscriber("127.0.0.1:8848", "agent1", "appName", "127.0.0.1",
"ns1", "serviceName001", 9090); "ns1", "serviceName001", 9090);
addServiceInstance(); MetricsMonitor.getIpCountMonitor().set(0);
addServiceSubscriber(); MetricsMonitor.getSubscriberCount().set(0);
} }
private void addServiceInstance() { @Test
public void addServiceInstance() {
boolean result = abstractClient.addServiceInstance(service, instancePublishInfo); boolean result = abstractClient.addServiceInstance(service, instancePublishInfo);
Assert.assertTrue(result); Assert.assertTrue(result);
} }
private void addServiceSubscriber() { @Test
public void addServiceSubscriber() {
Assert.assertTrue(abstractClient.addServiceSubscriber(service, subscriber)); Assert.assertTrue(abstractClient.addServiceSubscriber(service, subscriber));
} }
@ -65,12 +68,14 @@ public class AbstractClientTest {
@Test @Test
public void removeServiceInstanceSuccess() { public void removeServiceInstanceSuccess() {
addServiceInstance();
InstancePublishInfo publishInfo = abstractClient.removeServiceInstance(service); InstancePublishInfo publishInfo = abstractClient.removeServiceInstance(service);
Assert.assertNotNull(publishInfo); Assert.assertNotNull(publishInfo);
} }
@Test @Test
public void getInstancePublishInfo() { public void getInstancePublishInfo() {
addServiceInstance();
InstancePublishInfo publishInfo = abstractClient.getInstancePublishInfo(service); InstancePublishInfo publishInfo = abstractClient.getInstancePublishInfo(service);
Assert.assertNotNull(publishInfo); Assert.assertNotNull(publishInfo);
} }
@ -89,6 +94,7 @@ public class AbstractClientTest {
@Test @Test
public void getSubscriber() { public void getSubscriber() {
addServiceSubscriber();
Subscriber subscriber1 = abstractClient.getSubscriber(service); Subscriber subscriber1 = abstractClient.getSubscriber(service);
Assert.assertNotNull(subscriber1); Assert.assertNotNull(subscriber1);
} }
@ -107,11 +113,15 @@ public class AbstractClientTest {
@Test @Test
public void release() { public void release() {
try {
abstractClient.addServiceInstance(service, instancePublishInfo);
Assert.assertEquals(1, MetricsMonitor.getIpCountMonitor().get());
abstractClient.addServiceSubscriber(service, subscriber);
Assert.assertEquals(1, MetricsMonitor.getSubscriberCount().get());
abstractClient.release(); abstractClient.release();
} catch (Exception e) {
e.printStackTrace(); Assert.assertEquals(0, MetricsMonitor.getSubscriberCount().get());
Assert.assertNotNull(e); Assert.assertEquals(0, MetricsMonitor.getIpCountMonitor().get());
}
} }
} }