@Test public void handleUpdate_failsOnDuplicateService() { JsonObj name1 = new JsonObj("service", "service"); JsonObj name2 = new JsonObj("service", "service"); JsonObj methodConfig = new JsonObj("name", new JsonList(name1, name2)); JsonObj serviceConfig = new JsonObj("methodConfig", new JsonList(methodConfig)); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Duplicate service"); interceptor.handleUpdate(serviceConfig); }
void handleUpdate(@Nonnull Map<String, Object> serviceConfig) { Map<String, MethodInfo> newServiceMethodConfigs = new HashMap<String, MethodInfo>(); Map<String, MethodInfo> newServiceConfigs = new HashMap<String, MethodInfo>(); List<Map<String, Object>> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); nameResolveComplete = true; return; } for (Map<String, Object> methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); List<Map<String, Object>> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); for (Map<String, Object> name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); if (Strings.isNullOrEmpty(methodName)) { checkArgument( !newServiceConfigs.containsKey(serviceName), "Duplicate service %s", serviceName); newServiceConfigs.put(serviceName, info); } else { String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName); checkArgument( !newServiceMethodConfigs.containsKey(fullMethodName), "Duplicate method name %s", fullMethodName); newServiceMethodConfigs.put(fullMethodName, info); } } } serviceMethodMap.set(Collections.unmodifiableMap(newServiceMethodConfigs)); serviceMap.set(Collections.unmodifiableMap(newServiceConfigs)); nameResolveComplete = true; }
ServiceConfigInterceptor implements ClientInterceptor { void handleUpdate(@Nonnull Map<String, Object> serviceConfig) { Map<String, MethodInfo> newServiceMethodConfigs = new HashMap<String, MethodInfo>(); Map<String, MethodInfo> newServiceConfigs = new HashMap<String, MethodInfo>(); List<Map<String, Object>> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); nameResolveComplete = true; return; } for (Map<String, Object> methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); List<Map<String, Object>> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); for (Map<String, Object> name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); if (Strings.isNullOrEmpty(methodName)) { checkArgument( !newServiceConfigs.containsKey(serviceName), "Duplicate service %s", serviceName); newServiceConfigs.put(serviceName, info); } else { String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName); checkArgument( !newServiceMethodConfigs.containsKey(fullMethodName), "Duplicate method name %s", fullMethodName); newServiceMethodConfigs.put(fullMethodName, info); } } } serviceMethodMap.set(Collections.unmodifiableMap(newServiceMethodConfigs)); serviceMap.set(Collections.unmodifiableMap(newServiceConfigs)); nameResolveComplete = true; } }
ServiceConfigInterceptor implements ClientInterceptor { void handleUpdate(@Nonnull Map<String, Object> serviceConfig) { Map<String, MethodInfo> newServiceMethodConfigs = new HashMap<String, MethodInfo>(); Map<String, MethodInfo> newServiceConfigs = new HashMap<String, MethodInfo>(); List<Map<String, Object>> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); nameResolveComplete = true; return; } for (Map<String, Object> methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); List<Map<String, Object>> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); for (Map<String, Object> name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); if (Strings.isNullOrEmpty(methodName)) { checkArgument( !newServiceConfigs.containsKey(serviceName), "Duplicate service %s", serviceName); newServiceConfigs.put(serviceName, info); } else { String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName); checkArgument( !newServiceMethodConfigs.containsKey(fullMethodName), "Duplicate method name %s", fullMethodName); newServiceMethodConfigs.put(fullMethodName, info); } } } serviceMethodMap.set(Collections.unmodifiableMap(newServiceMethodConfigs)); serviceMap.set(Collections.unmodifiableMap(newServiceConfigs)); nameResolveComplete = true; } ServiceConfigInterceptor(
      boolean retryEnabled, int maxRetryAttemptsLimit, int maxHedgedAttemptsLimit); }
ServiceConfigInterceptor implements ClientInterceptor { void handleUpdate(@Nonnull Map<String, Object> serviceConfig) { Map<String, MethodInfo> newServiceMethodConfigs = new HashMap<String, MethodInfo>(); Map<String, MethodInfo> newServiceConfigs = new HashMap<String, MethodInfo>(); List<Map<String, Object>> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); nameResolveComplete = true; return; } for (Map<String, Object> methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); List<Map<String, Object>> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); for (Map<String, Object> name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); if (Strings.isNullOrEmpty(methodName)) { checkArgument( !newServiceConfigs.containsKey(serviceName), "Duplicate service %s", serviceName); newServiceConfigs.put(serviceName, info); } else { String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName); checkArgument( !newServiceMethodConfigs.containsKey(fullMethodName), "Duplicate method name %s", fullMethodName); newServiceMethodConfigs.put(fullMethodName, info); } } } serviceMethodMap.set(Collections.unmodifiableMap(newServiceMethodConfigs)); serviceMap.set(Collections.unmodifiableMap(newServiceConfigs)); nameResolveComplete = true; } ServiceConfigInterceptor(
      boolean retryEnabled, int maxRetryAttemptsLimit, int maxHedgedAttemptsLimit); @SuppressWarnings("BetaApi") // Verify is stabilized since Guava v24.0 @Override ClientCall<ReqT, RespT> interceptCall(
      final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next); }
ServiceConfigInterceptor implements ClientInterceptor { void handleUpdate(@Nonnull Map<String, Object> serviceConfig) { Map<String, MethodInfo> newServiceMethodConfigs = new HashMap<String, MethodInfo>(); Map<String, MethodInfo> newServiceConfigs = new HashMap<String, MethodInfo>(); List<Map<String, Object>> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); nameResolveComplete = true; return; } for (Map<String, Object> methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); List<Map<String, Object>> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); for (Map<String, Object> name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); if (Strings.isNullOrEmpty(methodName)) { checkArgument( !newServiceConfigs.containsKey(serviceName), "Duplicate service %s", serviceName); newServiceConfigs.put(serviceName, info); } else { String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName); checkArgument( !newServiceMethodConfigs.containsKey(fullMethodName), "Duplicate method name %s", fullMethodName); newServiceMethodConfigs.put(fullMethodName, info); } } } serviceMethodMap.set(Collections.unmodifiableMap(newServiceMethodConfigs)); serviceMap.set(Collections.unmodifiableMap(newServiceConfigs)); nameResolveComplete = true; } ServiceConfigInterceptor(
      boolean retryEnabled, int maxRetryAttemptsLimit, int maxHedgedAttemptsLimit); @SuppressWarnings("BetaApi") // Verify is stabilized since Guava v24.0 @Override ClientCall<ReqT, RespT> interceptCall(
      final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next);  }