use of com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy in project nacos by alibaba.
the class BeatReactorTest method testBuildBeatInfo2.
@Test
public void testBuildBeatInfo2() {
String ip = "11.11.11.11";
int port = 1234;
double weight = 1.0;
String serviceName = "service";
String clusterName = "cluster1";
Map<String, String> meta = new HashMap<>();
Instance instance = new Instance();
instance.setServiceName(serviceName);
instance.setIp(ip);
instance.setPort(port);
instance.setWeight(weight);
instance.setMetadata(meta);
instance.setClusterName(clusterName);
String groupedService = "group1@@service";
BeatInfo expectInfo = new BeatInfo();
expectInfo.setServiceName(groupedService);
expectInfo.setIp(ip);
expectInfo.setPort(port);
expectInfo.setCluster(clusterName);
expectInfo.setWeight(weight);
expectInfo.setMetadata(meta);
expectInfo.setScheduled(false);
expectInfo.setPeriod(Constants.DEFAULT_HEART_BEAT_INTERVAL);
NamingHttpClientProxy proxy = Mockito.mock(NamingHttpClientProxy.class);
BeatReactor beatReactor = new BeatReactor(proxy);
assertBeatInfoEquals(expectInfo, beatReactor.buildBeatInfo(groupedService, instance));
}
use of com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy in project nacos by alibaba.
the class BeatReactorTest method testBuildKey.
@Test
public void testBuildKey() {
String ip = "11.11.11.11";
int port = 1234;
String serviceName = "serviceName1";
NamingHttpClientProxy proxy = Mockito.mock(NamingHttpClientProxy.class);
BeatReactor beatReactor = new BeatReactor(proxy);
Assert.assertEquals(serviceName + Constants.NAMING_INSTANCE_ID_SPLITTER + ip + Constants.NAMING_INSTANCE_ID_SPLITTER + port, beatReactor.buildKey(serviceName, ip, port));
}
use of com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy in project nacos by alibaba.
the class BeatReactorTest method testIntervalFromResponse.
@Test
public void testIntervalFromResponse() throws JsonProcessingException, NacosException, InterruptedException {
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName("test");
beatInfo.setIp("11.11.11.11");
beatInfo.setPort(1234);
beatInfo.setCluster("clusterName");
beatInfo.setWeight(1);
beatInfo.setMetadata(new HashMap<String, String>());
beatInfo.setScheduled(false);
beatInfo.setPeriod(10L);
NamingHttpClientProxy proxy = Mockito.mock(NamingHttpClientProxy.class);
String jsonString = "{\"clientBeatInterval\":20}";
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree(jsonString);
Mockito.when(proxy.sendBeat(beatInfo, false)).thenReturn(actualObj);
BeatReactor beatReactor = new BeatReactor(proxy);
String serviceName = "serviceName1";
beatReactor.addBeatInfo(serviceName, beatInfo);
TimeUnit.MILLISECONDS.sleep(12);
Mockito.verify(proxy, Mockito.times(1)).sendBeat(beatInfo, false);
TimeUnit.MILLISECONDS.sleep(20);
Mockito.verify(proxy, Mockito.times(2)).sendBeat(beatInfo, false);
}
use of com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy in project nacos by alibaba.
the class BeatReactorTest method testBuildBeatInfo1.
@Test
public void testBuildBeatInfo1() {
String ip = "11.11.11.11";
int port = 1234;
double weight = 1.0;
String serviceName = "service@@group1";
String clusterName = "cluster1";
Map<String, String> meta = new HashMap<>();
Instance instance = new Instance();
instance.setServiceName(serviceName);
instance.setIp(ip);
instance.setPort(port);
instance.setWeight(weight);
instance.setMetadata(meta);
instance.setClusterName(clusterName);
BeatInfo expectInfo = new BeatInfo();
expectInfo.setServiceName(serviceName);
expectInfo.setIp(ip);
expectInfo.setPort(port);
expectInfo.setCluster(clusterName);
expectInfo.setWeight(weight);
expectInfo.setMetadata(meta);
expectInfo.setScheduled(false);
expectInfo.setPeriod(Constants.DEFAULT_HEART_BEAT_INTERVAL);
NamingHttpClientProxy proxy = Mockito.mock(NamingHttpClientProxy.class);
BeatReactor beatReactor = new BeatReactor(proxy);
assertBeatInfoEquals(expectInfo, beatReactor.buildBeatInfo(instance));
}
use of com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testRegisterServiceByHttp.
@Test
public void testRegisterServiceByHttp() throws NacosException, NoSuchFieldException, IllegalAccessException {
String ns = "ns1";
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Properties props = new Properties();
props.setProperty("serverAddr", "localhost");
InstancesChangeNotifier notifier = new InstancesChangeNotifier();
NamingClientProxyDelegate delegate = new NamingClientProxyDelegate(ns, holder, props, notifier);
NamingHttpClientProxy mockHttpClient = Mockito.mock(NamingHttpClientProxy.class);
Field mockHttpClientField = NamingClientProxyDelegate.class.getDeclaredField("httpClientProxy");
mockHttpClientField.setAccessible(true);
mockHttpClientField.set(delegate, mockHttpClient);
String serviceName = "service1";
String groupName = "group1";
Instance instance = new Instance();
instance.setServiceName(serviceName);
instance.setClusterName(groupName);
instance.setIp("1.1.1.1");
instance.setPort(1);
// use grpc
instance.setEphemeral(false);
delegate.registerService(serviceName, groupName, instance);
verify(mockHttpClient, times(1)).registerService(serviceName, groupName, instance);
}
Aggregations