Search in sources :

Example 1 with NameMatcher

use of io.grpc.rls.RlsProtoData.NameMatcher in project grpc-java by grpc.

the class RlsProtoConvertersTest method convert_jsonRlsConfig_defaultValues.

@Test
public void convert_jsonRlsConfig_defaultValues() throws IOException {
    String jsonStr = "{\n" + "  \"grpcKeyBuilders\": [\n" + "    {\n" + "      \"names\": [\n" + "        {\n" + "          \"service\": \"service1\"\n" + "        }\n" + "      ]\n" + "    }\n" + "  ],\n" + "  \"lookupService\": \"service1\",\n" + "  \"validTargets\": [\"a valid target\"]," + "  \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + "}";
    RouteLookupConfig expectedConfig = RouteLookupConfig.builder().grpcKeyBuilders(ImmutableList.of(GrpcKeyBuilder.create(ImmutableList.of(Name.create("service1", null)), ImmutableList.<NameMatcher>of(), ExtraKeys.DEFAULT, ImmutableMap.<String, String>of()))).lookupService("service1").lookupServiceTimeoutInNanos(TimeUnit.SECONDS.toNanos(10)).maxAgeInNanos(TimeUnit.MINUTES.toNanos(5)).staleAgeInNanos(TimeUnit.MINUTES.toNanos(5)).cacheSizeBytes(5 * 1024 * 1024).defaultTarget("us_east_1.cloudbigtable.googleapis.com").build();
    RouteLookupConfigConverter converter = new RouteLookupConfigConverter();
    @SuppressWarnings("unchecked") Map<String, ?> parsedJson = (Map<String, ?>) JsonParser.parse(jsonStr);
    RouteLookupConfig converted = converter.convert(parsedJson);
    assertThat(converted).isEqualTo(expectedConfig);
}
Also used : RouteLookupConfig(io.grpc.rls.RlsProtoData.RouteLookupConfig) NameMatcher(io.grpc.rls.RlsProtoData.NameMatcher) RouteLookupConfigConverter(io.grpc.rls.RlsProtoConverters.RouteLookupConfigConverter) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with NameMatcher

use of io.grpc.rls.RlsProtoData.NameMatcher in project grpc-java by grpc.

the class RlsProtoConverters method checkUniqueKey.

private static void checkUniqueKey(List<NameMatcher> nameMatchers, Set<String> constantKeys) {
    Set<String> keys = new HashSet<>(constantKeys);
    keys.addAll(EXTRA_KEY_NAMES);
    for (NameMatcher nameMatcher : nameMatchers) {
        keys.add(nameMatcher.key());
    }
    if (keys.size() != nameMatchers.size() + constantKeys.size() + EXTRA_KEY_NAMES.size()) {
        throw new IllegalArgumentException("keys in KeyBuilder must be unique");
    }
}
Also used : NameMatcher(io.grpc.rls.RlsProtoData.NameMatcher) HashSet(java.util.HashSet)

Aggregations

NameMatcher (io.grpc.rls.RlsProtoData.NameMatcher)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RouteLookupConfigConverter (io.grpc.rls.RlsProtoConverters.RouteLookupConfigConverter)1 RouteLookupConfig (io.grpc.rls.RlsProtoData.RouteLookupConfig)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1