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);
}
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");
}
}
Aggregations