27
27
import com .tencent .polaris .client .api .SDKContext ;
28
28
import com .tencent .polaris .factory .api .APIFactory ;
29
29
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 ;
30
32
import com .tencent .trpc .core .common .ConfigManager ;
31
33
import com .tencent .trpc .core .common .config .PluginConfig ;
32
34
import com .tencent .trpc .core .rpc .Request ;
@@ -338,9 +340,10 @@ public void testGetConsumerAPI() {
338
340
}
339
341
340
342
@ Test
341
- public void testInit () {
343
+ public void testExceptionInit () {
342
344
PolarisSelector polarisSelector = new PolarisSelector ();
343
345
try {
346
+ polarisSelector .setPluginConfig (selectorConfig );
344
347
polarisSelector .init ();
345
348
Assert .assertNull (polarisSelector .getPolarisAPI ());
346
349
polarisSelector .destroy ();
@@ -350,7 +353,7 @@ public void testInit() {
350
353
}
351
354
352
355
@ Test
353
- public void testWarmup () {
356
+ public void testExceptionWarmup () {
354
357
PolarisSelector clusterNaming = new PolarisSelector ();
355
358
clusterNaming .setPluginConfig (selectorConfig );
356
359
clusterNaming .init ();
@@ -384,15 +387,15 @@ public void testAsyncSelectOne() {
384
387
}
385
388
386
389
@ Test
387
- public void testEmptyAsyncSelectOne () {
390
+ public void testGetCriteria () {
388
391
PolarisSelector clusterNaming = new PolarisSelector ();
389
392
clusterNaming .setPluginConfig (selectorConfig );
390
393
clusterNaming .init ();
391
394
ServiceId serviceId = DataTest .newServiceId ();
392
395
serviceId .setServiceName ("service-metadata-select-one" );
393
396
clusterNaming .warmup (serviceId );
394
397
Request request = DataTest .mockServiceMetadataRequest ();
395
- request .getMeta ().setHashVal (null );
398
+ request .getMeta ().setHashVal ("123333" );
396
399
CompletionStage <ServiceInstance > future = clusterNaming .asyncSelectOne (serviceId , request );
397
400
AtomicReference <Throwable > errorRef = new AtomicReference <>();
398
401
CompletionStage <ServiceInstance > stage = future .whenComplete ((res , err ) -> {
@@ -412,7 +415,6 @@ public void testExceptionAsyncSelectOne() {
412
415
ServiceId serviceId = DataTest .newServiceId ();
413
416
serviceId .setServiceName ("fallback" );
414
417
Request request = DataTest .request ;
415
- request .getMeta ().setHashVal (null );
416
418
try {
417
419
CompletionStage <ServiceInstance > future = clusterNaming
418
420
.asyncSelectOne (serviceId , request );
@@ -432,4 +434,17 @@ public void testExceptionReport() {
432
434
return ;
433
435
}
434
436
}
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
+ }
435
450
}
0 commit comments