Search in sources :

Example 1 with GroupWeightConfig

use of org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig in project spring-cloud-gateway by spring-cloud.

the class WeightCalculatorWebFilterTests method assertWeightCalculation.

private void assertWeightCalculation(WeightCalculatorWebFilter filter, String group, int item, int weight, List<Double> normalized, Double... middleRanges) {
    String routeId = route(item);
    filter.addWeightConfig(new WeightConfig(group, routeId, weight));
    Map<String, GroupWeightConfig> groupWeights = filter.getGroupWeights();
    assertThat(groupWeights).containsKey(group);
    GroupWeightConfig config = groupWeights.get(group);
    assertThat(config.group).isEqualTo(group);
    assertThat(config.weights).hasSize(item).containsEntry(routeId, weight);
    assertThat(config.normalizedWeights).hasSize(item);
    for (int i = 0; i < normalized.size(); i++) {
        assertThat(config.normalizedWeights).containsEntry(route(i + 1), normalized.get(i));
    }
    for (int i = 0; i < normalized.size(); i++) {
        assertThat(config.rangeIndexes).containsEntry(i, route(i + 1));
    }
    assertThat(config.ranges).hasSize(item + 1).startsWith(0.0).endsWith(1.0);
    if (middleRanges.length > 0) {
        assertThat(config.ranges).contains(middleRanges);
    }
}
Also used : GroupWeightConfig(org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig) WeightConfig(org.springframework.cloud.gateway.support.WeightConfig) GroupWeightConfig(org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig)

Aggregations

GroupWeightConfig (org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig)1 WeightConfig (org.springframework.cloud.gateway.support.WeightConfig)1