Skip to content

Commit

Permalink
--other=add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
smartboyjia committed Jun 15, 2024
1 parent 4c5e1fc commit 9fcc6c3
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -350,7 +353,7 @@ public void testInit() {
}

@Test
public void testWarmup() {
public void testExceptionWarmup() {
PolarisSelector clusterNaming = new PolarisSelector();
clusterNaming.setPluginConfig(selectorConfig);
clusterNaming.init();
Expand Down Expand Up @@ -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) -> {
Expand All @@ -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);
Expand All @@ -432,4 +434,17 @@ public void testExceptionReport() {
return;
}
}

@Test
public void testExceptionAsyncSelectAll() {
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;
}
}
}

0 comments on commit 9fcc6c3

Please sign in to comment.