Skip to content

Commit

Permalink
test: naming-test error
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhouyu committed Dec 3, 2024
1 parent aa8e847 commit ac83b9d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
import com.alibaba.nacos.test.base.Params;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand All @@ -41,6 +43,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

/**
* @author nkorange
Expand All @@ -55,6 +58,9 @@ class CPInstancesAPI_ITCase extends NamingBase {

private NamingService naming2;

@MockBean
private NamespacePersistService namespacePersistService;

@LocalServerPort
private int port;

Expand All @@ -75,6 +81,8 @@ void setUp() throws Exception {
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);
naming2 = NamingFactory.createNamingService(properties);
isNamingServerReady();
when(namespacePersistService.tenantInfoCountByTenantId(TEST_NAMESPACE_1)).thenReturn(1);
when(namespacePersistService.tenantInfoCountByTenantId(TEST_NAMESPACE_2)).thenReturn(1);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.web.server.LocalServerPort;

import java.util.Arrays;
Expand All @@ -50,6 +52,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

/**
* @author nkorange
Expand All @@ -64,6 +67,9 @@ class MultiTenant_ITCase {

private NamingService naming2;

@MockBean
private NamespacePersistService namespacePersistService;

@LocalServerPort
private int port;

Expand Down Expand Up @@ -93,6 +99,10 @@ void init() throws Exception {
properties.put(PropertyKeyConst.NAMESPACE, "namespace-2");
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);
naming2 = NamingFactory.createNamingService(properties);


when(namespacePersistService.tenantInfoCountByTenantId("namespace-1")).thenReturn(1);
when(namespacePersistService.tenantInfoCountByTenantId("namespace-2")).thenReturn(1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
import com.alibaba.nacos.test.base.Params;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpEntity;
Expand All @@ -49,6 +52,7 @@
import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

/**
* @author nkorange
Expand All @@ -71,6 +75,9 @@ class MultiTenant_InstanceAPI_ITCase {
@Autowired
private TestRestTemplate restTemplate;

@MockBean
private NamespacePersistService namespacePersistService;

private URL base;

@BeforeEach
Expand Down Expand Up @@ -100,6 +107,9 @@ void init() throws Exception {
properties.put(PropertyKeyConst.NAMESPACE, "namespace-2");
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);
naming2 = NamingFactory.createNamingService(properties);

when(namespacePersistService.tenantInfoCountByTenantId("namespace-1")).thenReturn(1);
when(namespacePersistService.tenantInfoCountByTenantId("namespace-2")).thenReturn(1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import com.alibaba.nacos.client.naming.listener.NamingChangeEvent;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
import com.alibaba.nacos.test.base.Params;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand All @@ -47,6 +49,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;

/**
* Created by wangtong.wt on 2018/6/20.
Expand All @@ -65,6 +68,9 @@ class Subscribe_ITCase extends NamingBase {

private volatile List<Instance> instances = Collections.emptyList();

@MockBean
private NamespacePersistService namespacePersistService;

@BeforeEach
void init() throws Exception {
instances.clear();
Expand Down Expand Up @@ -272,6 +278,8 @@ void subscribeSameServiceForTwoNamingService() throws Exception {
Properties properties2 = new Properties();
properties2.setProperty("serverAddr", "127.0.0.1" + ":" + port);
properties2.setProperty("namespace", "ns-002");
when(namespacePersistService.tenantInfoCountByTenantId("ns-001")).thenReturn(1);
when(namespacePersistService.tenantInfoCountByTenantId("ns-002")).thenReturn(1);
final NamingService naming2 = NamingFactory.createNamingService(properties2);

final ConcurrentHashSet<Instance> concurrentHashSet1 = new ConcurrentHashSet();
Expand Down

0 comments on commit ac83b9d

Please sign in to comment.