Search in sources :

Example 6 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testUpdateService.

@Test
public void testUpdateService() throws NacosException {
    // TODO thrown.expect(UnsupportedOperationException.class);
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    client.updateService(service, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Service(com.alibaba.nacos.api.naming.pojo.Service) NamingGrpcRedoService(com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 7 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NacosNamingMaintainServiceTest method testCreateService4.

@Test
public void testCreateService4() throws NacosException {
    // given
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    // when
    nacosNamingMaintainService.createService(service, selector);
    // then
    verify(serverProxy, times(1)).createService(service, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Service(com.alibaba.nacos.api.naming.pojo.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 8 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NacosNamingServiceTest method testGetServicesOfServer4.

@Test
public void testGetServicesOfServer4() throws NacosException {
    // given
    int pageNo = 1;
    int pageSize = 10;
    String groupName = "group1";
    AbstractSelector selector = new AbstractSelector("aaa") {

        @Override
        public String getType() {
            return super.getType();
        }
    };
    // when
    client.getServicesOfServer(pageNo, pageSize, groupName, selector);
    // then
    verify(proxy, times(1)).getServiceList(pageNo, pageSize, groupName, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class AbstractNamingClientProxyTest method testGetSecurityHeaders.

@Test
public void testGetSecurityHeaders() {
    SecurityProxy sc = Mockito.mock(SecurityProxy.class);
    Properties props = new Properties();
    AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {

        @Override
        public void onEvent(ServerListChangedEvent event) {
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return ServerListChangedEvent.class;
        }

        @Override
        public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
            return null;
        }

        @Override
        public Service queryService(String serviceName, String groupName) throws NacosException {
            return null;
        }

        @Override
        public void createService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public boolean deleteService(String serviceName, String groupName) throws NacosException {
            return false;
        }

        @Override
        public void updateService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
            return null;
        }

        @Override
        public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
            return null;
        }

        @Override
        public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
        }

        @Override
        public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
            return false;
        }

        @Override
        public void updateBeatInfo(Set<Instance> modifiedInstances) {
        }

        @Override
        public boolean serverHealthy() {
            return false;
        }

        @Override
        public void shutdown() throws NacosException {
        }
    };
    String token = "aa";
    Mockito.when(sc.getAccessToken()).thenReturn(token);
    Map<String, String> securityHeaders = proxy.getSecurityHeaders();
    Assert.assertEquals(1, securityHeaders.size());
    Assert.assertEquals(token, securityHeaders.get(Constants.ACCESS_TOKEN));
}
Also used : ServerListChangedEvent(com.alibaba.nacos.client.naming.event.ServerListChangedEvent) Set(java.util.Set) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Service(com.alibaba.nacos.api.naming.pojo.Service) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class AbstractNamingClientProxyTest method testGetSpasHeaders.

@Test
public void testGetSpasHeaders() throws Exception {
    SecurityProxy sc = Mockito.mock(SecurityProxy.class);
    Properties props = new Properties();
    String ak = "aa";
    String sk = "bb";
    props.put(PropertyKeyConst.ACCESS_KEY, ak);
    props.put(PropertyKeyConst.SECRET_KEY, sk);
    AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {

        @Override
        public void onEvent(ServerListChangedEvent event) {
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return ServerListChangedEvent.class;
        }

        @Override
        public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
            return null;
        }

        @Override
        public Service queryService(String serviceName, String groupName) throws NacosException {
            return null;
        }

        @Override
        public void createService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public boolean deleteService(String serviceName, String groupName) throws NacosException {
            return false;
        }

        @Override
        public void updateService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
            return null;
        }

        @Override
        public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
            return null;
        }

        @Override
        public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
        }

        @Override
        public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
            return false;
        }

        @Override
        public void updateBeatInfo(Set<Instance> modifiedInstances) {
        }

        @Override
        public boolean serverHealthy() {
            return false;
        }

        @Override
        public void shutdown() throws NacosException {
        }
    };
    String serviceName = "aaa";
    Map<String, String> spasHeaders = proxy.getSpasHeaders(serviceName);
    Assert.assertEquals(4, spasHeaders.size());
    Assert.assertEquals(AppNameUtils.getAppName(), spasHeaders.get("app"));
    Assert.assertEquals(ak, spasHeaders.get("ak"));
    Assert.assertTrue(spasHeaders.get("data").endsWith("@@" + serviceName));
    String expectSign = SignUtil.sign(spasHeaders.get("data"), sk);
    Assert.assertEquals(expectSign, spasHeaders.get("signature"));
}
Also used : ServerListChangedEvent(com.alibaba.nacos.client.naming.event.ServerListChangedEvent) Set(java.util.Set) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Service(com.alibaba.nacos.api.naming.pojo.Service) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)10 Test (org.junit.Test)10 Service (com.alibaba.nacos.api.naming.pojo.Service)6 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)5 Properties (java.util.Properties)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ServerListChangedEvent (com.alibaba.nacos.client.naming.event.ServerListChangedEvent)2 NamingGrpcRedoService (com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService)2 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)2 Set (java.util.Set)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ServiceListResponse (com.alibaba.nacos.api.naming.remote.response.ServiceListResponse)1 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)1 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)1 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)1 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)1 Field (java.lang.reflect.Field)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1