use of com.alibaba.nacos.api.naming.pojo.Service in project nacos by alibaba.
the class NacosNamingMaintainService method updateService.
@Override
public void updateService(String serviceName, String groupName, float protectThreshold) throws NacosException {
Service service = new Service();
service.setName(serviceName);
service.setGroupName(groupName);
service.setProtectThreshold(protectThreshold);
updateService(service, new NoneSelector());
}
use of com.alibaba.nacos.api.naming.pojo.Service 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));
}
use of com.alibaba.nacos.api.naming.pojo.Service 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"));
}
Aggregations