### Question:
RouteFilter extends AbstractFilter { IndexRouting.ConditionTarget randomTargetGroupByWeight(List<IndexRouting.ConditionTarget> randomList) { if (randomList.size() == 1) { return randomList.get(0); } int weight = randomList.stream().mapToInt(IndexRouting.ConditionTarget::getWeight).sum(); if (weight <= 0) { LogUtils.warn(logger, SearchLogEvent.NORMAL_EVENT, "计算出权重是负数：{}, group IDs:{}", weight, randomList); randomList.get(0); } int selected = InternalThreadLocalMap.get().random().nextInt(weight) + 1; for(IndexRouting.ConditionTarget t : randomList) { selected -= t.getWeight(); if (selected <= 0) { return t; } } LogUtils.warn(logger, SearchLogEvent.NORMAL_EVENT, "权重计算错误：{}, group IDs:{}", selected, randomList); return null; }  @Override String name(); @Override void run(AbstractFilterContext filterContext, SessionContext sessionContext); List<ServiceInfo> genShardLevelRoutingServerList(String indexName, IndexRouting.ConditionTarget target,
			IndexRoutingTargetGroup targetGroup, PallasRequest req,
			List<IndexRoutingTargetGroup.ClusterInfo> clusterInfoList, List<String> availableNodes); static String DEFAULT_NAME; static String className; static String classMethod; }### Answer:
@Test public void testRandomTargetGroupByWeight() { IndexRouting.ConditionTarget t1 = new IndexRouting.ConditionTarget(); t1.setId(1L); t1.setWeight(7); IndexRouting.ConditionTarget t2 = new IndexRouting.ConditionTarget(); t2.setId(2L); t2.setWeight(2); IndexRouting.ConditionTarget t3 = new IndexRouting.ConditionTarget(); t3.setId(3L); t3.setWeight(1); List<IndexRouting.ConditionTarget> collect = Stream.of(t1).collect(toList()); IndexRouting.ConditionTarget result = filter.randomTargetGroupByWeight(collect); assertTrue(result.getId().equals(1L)); collect = Stream.of(t1, t2, t3).collect(toList()); int c1 = 0, c2 = 0, c3 = 0; for(int i = 0; i< 100; i++) { result = filter.randomTargetGroupByWeight(collect); if (result.getId().equals(1L)) { c1++; } else if (result.getId().equals(2L)) { c2++; } else if (result.getId().equals(3L)) { c3++; } } System.out.println(c1); System.out.println(c2); System.out.println(c3); assertTrue(c1 > 0); assertTrue(c2 > 0); assertTrue(c3 > 0); }