Skip to content

Commit

Permalink
Optimize nacos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Apr 19, 2024
1 parent 84ea4af commit eca86f3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import com.alibaba.nacos.api.exception.NacosException;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -70,7 +68,7 @@ public void onSuccess() {
@Override
public void onFail(Exception e) {
latch.countDown();
log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e);
log.error("{}, failed", this.getClass().getSimpleName(), e);
}
});
latch.await(2, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@
@NoArgsConstructor
public class CreateNacosConfig implements CreateSDKConfig {

private String serverAddress;
private String serverAddress = "127.0.0.1:8848";

private String namespace = "";

private String username = "nacos";

private String password = "nacos";

private String accessKey = "";

private String secretKey = "";

@Override
public String getUniqueKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public SimpleEntry<String, ConfigService> createClient(CreateSDKConfig clientCon
try {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, config.getServerAddress());
properties.put(PropertyKeyConst.NAMESPACE, config.getNamespace());
properties.put(PropertyKeyConst.USERNAME, config.getUsername());
properties.put(PropertyKeyConst.PASSWORD, config.getPassword());
properties.put(PropertyKeyConst.ACCESS_KEY, config.getAccessKey());
properties.put(PropertyKeyConst.SECRET_KEY, config.getSecretKey());
configService = NacosFactory.createConfigService(properties);
} catch (NacosException e) {
log.error("NacosCheck init failed caused by {}", e.getErrMsg());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public SimpleEntry<String, NamingService> createClient(CreateSDKConfig clientCon
try {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, config.getServerAddress());
properties.put(PropertyKeyConst.NAMESPACE, config.getNamespace());
properties.put(PropertyKeyConst.USERNAME, config.getUsername());
properties.put(PropertyKeyConst.PASSWORD, config.getPassword());
properties.put(PropertyKeyConst.ACCESS_KEY, config.getAccessKey());
properties.put(PropertyKeyConst.SECRET_KEY, config.getSecretKey());
namingService = NacosFactory.createNamingService(properties);
} catch (NacosException e) {
log.error("NacosCheck init failed caused by {}", e.getErrMsg());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ class NacosNamingSDKOperationTest {
@Test
public void testCreateNamingService() throws NacosException, InterruptedException {
try {
CreateNacosConfig createClientConfig = new CreateNacosConfig();
createClientConfig.setServerAddress("127.0.0.1:8848");
NamingService namingService = (NamingService) SDKManager.getInstance().createClient(SDKTypeEnum.META_NACOS_NAMING, createClientConfig)
.getValue();
namingService.registerInstance("eventmesh-dashboard-sdk-nacos-test", "11.11.11.11", 8888, "eventmesh-dashboard-sdk-nacos-test-cluster-name");

namingService.deregisterInstance("eventmesh-dashboard-sdk-nacos-test", "11.11.11.11", 8888,
"eventmesh-dashboard-sdk-nacos-test-cluster-name");}
catch (Exception e){
CreateNacosConfig createClientConfig = new CreateNacosConfig();
createClientConfig.setServerAddress("127.0.0.1:8848");
createClientConfig.setUsername("nacos");
createClientConfig.setPassword("nacos");
NamingService namingService = (NamingService) SDKManager.getInstance().createClient(SDKTypeEnum.META_NACOS_NAMING, createClientConfig)
.getValue();
namingService.registerInstance("eventmesh-dashboard-sdk-nacos-test", "192.168.11.11", 8888,
"eventmesh-dashboard-sdk-nacos-test-cluster-name");
namingService.deregisterInstance("eventmesh-dashboard-sdk-nacos-test", "192.168.11.11", 8888,
"eventmesh-dashboard-sdk-nacos-test-cluster-name");
} catch (Exception e) {
log.error("create nacos naming service failed", e);
}
}
Expand Down

0 comments on commit eca86f3

Please sign in to comment.