Search in sources :

Example 1 with BeatReactor

use of com.alibaba.nacos.client.naming.beat.BeatReactor in project nacos by alibaba.

the class NamingHttpClientProxyTest method testGetBeatReactor.

@Test
public void testGetBeatReactor() throws Exception {
    SecurityProxy proxy = mock(SecurityProxy.class);
    ServerListManager mgr = mock(ServerListManager.class);
    when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
    Properties props = new Properties();
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    String namespaceId = "aaa";
    NamingHttpClientProxy clientProxy = new NamingHttpClientProxy(namespaceId, proxy, mgr, props, holder);
    BeatReactor mockBeatReactor = mock(BeatReactor.class);
    final Field mockBeatReactorField = NamingHttpClientProxy.class.getDeclaredField("beatReactor");
    mockBeatReactorField.setAccessible(true);
    mockBeatReactorField.set(clientProxy, mockBeatReactor);
    // when
    BeatReactor beatReactor = clientProxy.getBeatReactor();
    // then
    Assert.assertEquals(mockBeatReactor, beatReactor);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ServerListManager(com.alibaba.nacos.client.naming.core.ServerListManager) BeatReactor(com.alibaba.nacos.client.naming.beat.BeatReactor) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with BeatReactor

use of com.alibaba.nacos.client.naming.beat.BeatReactor in project nacos by alibaba.

the class NamingHttpClientProxyTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    SecurityProxy proxy = mock(SecurityProxy.class);
    ServerListManager mgr = mock(ServerListManager.class);
    when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
    Properties props = new Properties();
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    String namespaceId = "aaa";
    NamingHttpClientProxy clientProxy = new NamingHttpClientProxy(namespaceId, proxy, mgr, props, holder);
    BeatReactor mockBeatReactor = mock(BeatReactor.class);
    final Field mockBeatReactorField = NamingHttpClientProxy.class.getDeclaredField("beatReactor");
    mockBeatReactorField.setAccessible(true);
    mockBeatReactorField.set(clientProxy, mockBeatReactor);
    // when
    clientProxy.shutdown();
    // then
    verify(mockBeatReactor, times(1)).shutdown();
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ServerListManager(com.alibaba.nacos.client.naming.core.ServerListManager) BeatReactor(com.alibaba.nacos.client.naming.beat.BeatReactor) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with BeatReactor

use of com.alibaba.nacos.client.naming.beat.BeatReactor in project nacos by alibaba.

the class NamingHttpClientProxyTest method testUpdateBeatInfo.

@Test
public void testUpdateBeatInfo() throws Exception {
    // given
    BeatReactor mockBeatReactor = mock(BeatReactor.class);
    Field dom2Beat = BeatReactor.class.getDeclaredField("dom2Beat");
    ConcurrentHashMap<String, BeatInfo> beatMap = new ConcurrentHashMap<>();
    String beatServiceName = "service1#127.0.0.1#10000";
    beatMap.put(beatServiceName, new BeatInfo());
    dom2Beat.setAccessible(true);
    dom2Beat.set(mockBeatReactor, beatMap);
    SecurityProxy proxy = mock(SecurityProxy.class);
    ServerListManager mgr = mock(ServerListManager.class);
    when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
    Properties props = new Properties();
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, props, holder);
    final Field mockBeatReactorField = NamingHttpClientProxy.class.getDeclaredField("beatReactor");
    mockBeatReactorField.setAccessible(true);
    mockBeatReactorField.set(clientProxy, mockBeatReactor);
    Instance instance = new Instance();
    instance.setInstanceId("id1");
    instance.setIp("127.0.0.1");
    instance.setPort(10000);
    instance.setServiceName("service1");
    instance.setClusterName("cluster1");
    Set<Instance> beats = new HashSet<>();
    beats.add(instance);
    when(mockBeatReactor.buildKey("service1", "127.0.0.1", 10000)).thenReturn(beatServiceName);
    // when
    clientProxy.updateBeatInfo(beats);
    // then
    verify(mockBeatReactor, times(1)).addBeatInfo(eq("service1"), any());
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ServerListManager(com.alibaba.nacos.client.naming.core.ServerListManager) Instance(com.alibaba.nacos.api.naming.pojo.Instance) BeatReactor(com.alibaba.nacos.client.naming.beat.BeatReactor) BeatInfo(com.alibaba.nacos.client.naming.beat.BeatInfo) Properties(java.util.Properties) Field(java.lang.reflect.Field) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BeatReactor (com.alibaba.nacos.client.naming.beat.BeatReactor)3 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)3 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)3 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)3 Field (java.lang.reflect.Field)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 BeatInfo (com.alibaba.nacos.client.naming.beat.BeatInfo)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1