Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--other=add unit test for polaris routing module #44

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
--other=add unittest
smartboyjia committed Jun 15, 2024
commit 9fcc6c3a65b5395479c5489e813729f90863d001
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.factory.api.APIFactory;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import com.tencent.polaris.plugins.loadbalancer.random.WeightedRandomBalance;
import com.tencent.polaris.plugins.loadbalancer.ringhash.ConsistentHashLoadBalance;
import com.tencent.trpc.core.common.ConfigManager;
import com.tencent.trpc.core.common.config.PluginConfig;
import com.tencent.trpc.core.rpc.Request;
@@ -338,9 +340,10 @@ public void testGetConsumerAPI() {
}

@Test
public void testInit() {
public void testExceptionInit() {
PolarisSelector polarisSelector = new PolarisSelector();
try {
polarisSelector.setPluginConfig(selectorConfig);
polarisSelector.init();
Assert.assertNull(polarisSelector.getPolarisAPI());
polarisSelector.destroy();
@@ -350,7 +353,7 @@ public void testInit() {
}

@Test
public void testWarmup() {
public void testExceptionWarmup() {
PolarisSelector clusterNaming = new PolarisSelector();
clusterNaming.setPluginConfig(selectorConfig);
clusterNaming.init();
@@ -384,15 +387,15 @@ public void testAsyncSelectOne() {
}

@Test
public void testEmptyAsyncSelectOne() {
public void testGetCriteria() {
PolarisSelector clusterNaming = new PolarisSelector();
clusterNaming.setPluginConfig(selectorConfig);
clusterNaming.init();
ServiceId serviceId = DataTest.newServiceId();
serviceId.setServiceName("service-metadata-select-one");
clusterNaming.warmup(serviceId);
Request request = DataTest.mockServiceMetadataRequest();
request.getMeta().setHashVal(null);
request.getMeta().setHashVal("123333");
CompletionStage<ServiceInstance> future = clusterNaming.asyncSelectOne(serviceId, request);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
CompletionStage<ServiceInstance> stage = future.whenComplete((res, err) -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能正常获取到实例,就没有异常吧,也可以判断一下ServiceInstance

@@ -412,7 +415,6 @@ public void testExceptionAsyncSelectOne() {
ServiceId serviceId = DataTest.newServiceId();
serviceId.setServiceName("fallback");
Request request = DataTest.request;
request.getMeta().setHashVal(null);
try {
CompletionStage<ServiceInstance> future = clusterNaming
.asyncSelectOne(serviceId, request);
@@ -432,4 +434,17 @@ public void testExceptionReport() {
return;
}
}

@Test
public void testExceptionAsyncSelectAll() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

异常测试,需要断言一下,其他也是

PolarisSelector clusterNaming = new PolarisSelector();
clusterNaming.setPluginConfig(selectorConfig);
clusterNaming.init();
try {
ServiceId serviceId = Mockito.mock(ServiceId.class);
clusterNaming.asyncSelectAll(serviceId,DataTest.request);
} catch (Exception e) {
return;
}
}
}