Skip to content

Commit 9fcc6c3

Browse files
committed
--other=add unittest
1 parent 4c5e1fc commit 9fcc6c3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

trpc-selector/trpc-selector-open-polaris/src/test/java/com/tencent/trpc/selector/open/polaris/PolarisSelectorTest.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.tencent.polaris.client.api.SDKContext;
2828
import com.tencent.polaris.factory.api.APIFactory;
2929
import com.tencent.polaris.factory.config.ConfigurationImpl;
30+
import com.tencent.polaris.plugins.loadbalancer.random.WeightedRandomBalance;
31+
import com.tencent.polaris.plugins.loadbalancer.ringhash.ConsistentHashLoadBalance;
3032
import com.tencent.trpc.core.common.ConfigManager;
3133
import com.tencent.trpc.core.common.config.PluginConfig;
3234
import com.tencent.trpc.core.rpc.Request;
@@ -338,9 +340,10 @@ public void testGetConsumerAPI() {
338340
}
339341

340342
@Test
341-
public void testInit() {
343+
public void testExceptionInit() {
342344
PolarisSelector polarisSelector = new PolarisSelector();
343345
try {
346+
polarisSelector.setPluginConfig(selectorConfig);
344347
polarisSelector.init();
345348
Assert.assertNull(polarisSelector.getPolarisAPI());
346349
polarisSelector.destroy();
@@ -350,7 +353,7 @@ public void testInit() {
350353
}
351354

352355
@Test
353-
public void testWarmup() {
356+
public void testExceptionWarmup() {
354357
PolarisSelector clusterNaming = new PolarisSelector();
355358
clusterNaming.setPluginConfig(selectorConfig);
356359
clusterNaming.init();
@@ -384,15 +387,15 @@ public void testAsyncSelectOne() {
384387
}
385388

386389
@Test
387-
public void testEmptyAsyncSelectOne() {
390+
public void testGetCriteria() {
388391
PolarisSelector clusterNaming = new PolarisSelector();
389392
clusterNaming.setPluginConfig(selectorConfig);
390393
clusterNaming.init();
391394
ServiceId serviceId = DataTest.newServiceId();
392395
serviceId.setServiceName("service-metadata-select-one");
393396
clusterNaming.warmup(serviceId);
394397
Request request = DataTest.mockServiceMetadataRequest();
395-
request.getMeta().setHashVal(null);
398+
request.getMeta().setHashVal("123333");
396399
CompletionStage<ServiceInstance> future = clusterNaming.asyncSelectOne(serviceId, request);
397400
AtomicReference<Throwable> errorRef = new AtomicReference<>();
398401
CompletionStage<ServiceInstance> stage = future.whenComplete((res, err) -> {
@@ -412,7 +415,6 @@ public void testExceptionAsyncSelectOne() {
412415
ServiceId serviceId = DataTest.newServiceId();
413416
serviceId.setServiceName("fallback");
414417
Request request = DataTest.request;
415-
request.getMeta().setHashVal(null);
416418
try {
417419
CompletionStage<ServiceInstance> future = clusterNaming
418420
.asyncSelectOne(serviceId, request);
@@ -432,4 +434,17 @@ public void testExceptionReport() {
432434
return;
433435
}
434436
}
437+
438+
@Test
439+
public void testExceptionAsyncSelectAll() {
440+
PolarisSelector clusterNaming = new PolarisSelector();
441+
clusterNaming.setPluginConfig(selectorConfig);
442+
clusterNaming.init();
443+
try {
444+
ServiceId serviceId = Mockito.mock(ServiceId.class);
445+
clusterNaming.asyncSelectAll(serviceId,DataTest.request);
446+
} catch (Exception e) {
447+
return;
448+
}
449+
}
435450
}

0 commit comments

Comments
 (0)