diff --git a/trpc-selector/trpc-selector-open-polaris/src/test/java/com/tencent/trpc/selector/open/polaris/PolarisSelectorTest.java b/trpc-selector/trpc-selector-open-polaris/src/test/java/com/tencent/trpc/selector/open/polaris/PolarisSelectorTest.java index e7077e3dd..67ae1eff9 100644 --- a/trpc-selector/trpc-selector-open-polaris/src/test/java/com/tencent/trpc/selector/open/polaris/PolarisSelectorTest.java +++ b/trpc-selector/trpc-selector-open-polaris/src/test/java/com/tencent/trpc/selector/open/polaris/PolarisSelectorTest.java @@ -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,7 +387,7 @@ public void testAsyncSelectOne() { } @Test - public void testEmptyAsyncSelectOne() { + public void testGetCriteria() { PolarisSelector clusterNaming = new PolarisSelector(); clusterNaming.setPluginConfig(selectorConfig); clusterNaming.init(); @@ -392,7 +395,7 @@ public void testEmptyAsyncSelectOne() { serviceId.setServiceName("service-metadata-select-one"); clusterNaming.warmup(serviceId); Request request = DataTest.mockServiceMetadataRequest(); - request.getMeta().setHashVal(null); + request.getMeta().setHashVal("123333"); CompletionStage future = clusterNaming.asyncSelectOne(serviceId, request); AtomicReference errorRef = new AtomicReference<>(); CompletionStage stage = future.whenComplete((res, err) -> { @@ -412,7 +415,6 @@ public void testExceptionAsyncSelectOne() { ServiceId serviceId = DataTest.newServiceId(); serviceId.setServiceName("fallback"); Request request = DataTest.request; - request.getMeta().setHashVal(null); try { CompletionStage future = clusterNaming .asyncSelectOne(serviceId, request); @@ -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; + } + } }