@Test public void getRetryPolicies() throws Exception { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(RetryPolicyTest.class.getResourceAsStream( "/io/grpc/internal/test_retry_service_config.json"), "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); } Object serviceConfigObj = JsonParser.parse(sb.toString()); assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") Map<String, Object> serviceConfig = (Map<String, Object>) serviceConfigObj; ServiceConfigInterceptor serviceConfigInterceptor = new ServiceConfigInterceptor( true, 4, 3); serviceConfigInterceptor.handleUpdate(serviceConfig); MethodDescriptor.Builder<Void, Void> builder = TestMethodDescriptors.voidMethod().toBuilder(); MethodDescriptor<Void, Void> method = builder.setFullMethodName("not/exist").build(); assertEquals( RetryPolicy.DEFAULT, serviceConfigInterceptor.getRetryPolicyFromConfig(method)); method = builder.setFullMethodName("not_exist/Foo1").build(); assertEquals( RetryPolicy.DEFAULT, serviceConfigInterceptor.getRetryPolicyFromConfig(method)); method = builder.setFullMethodName("SimpleService1/not_exist").build(); assertEquals( new RetryPolicy( 3, TimeUnit.MILLISECONDS.toNanos(2100), TimeUnit.MILLISECONDS.toNanos(2200), parseDouble("3"), ImmutableSet.of(Code.UNAVAILABLE, Code.RESOURCE_EXHAUSTED)), serviceConfigInterceptor.getRetryPolicyFromConfig(method)); method = builder.setFullMethodName("SimpleService1/Foo1").build(); assertEquals( new RetryPolicy( 4, TimeUnit.MILLISECONDS.toNanos(100), TimeUnit.MILLISECONDS.toNanos(1000), parseDouble("2"), ImmutableSet.of(Code.UNAVAILABLE)), serviceConfigInterceptor.getRetryPolicyFromConfig(method)); method = builder.setFullMethodName("SimpleService2/not_exist").build(); assertEquals( RetryPolicy.DEFAULT, serviceConfigInterceptor.getRetryPolicyFromConfig(method)); method = builder.setFullMethodName("SimpleService2/Foo2").build(); assertEquals( new RetryPolicy( 4, TimeUnit.MILLISECONDS.toNanos(100), TimeUnit.MILLISECONDS.toNanos(1000), parseDouble("2"), ImmutableSet.of(Code.UNAVAILABLE)), serviceConfigInterceptor.getRetryPolicyFromConfig(method)); } finally { if (reader != null) { reader.close(); } } }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("maxAttempts", maxAttempts) .add("initialBackoffNanos", initialBackoffNanos) .add("maxBackoffNanos", maxBackoffNanos) .add("backoffMultiplier", backoffMultiplier) .add("retryableStatusCodes", retryableStatusCodes) .toString(); }
RetryPolicy { @Override public String toString() { return MoreObjects.toStringHelper(this) .add("maxAttempts", maxAttempts) .add("initialBackoffNanos", initialBackoffNanos) .add("maxBackoffNanos", maxBackoffNanos) .add("backoffMultiplier", backoffMultiplier) .add("retryableStatusCodes", retryableStatusCodes) .toString(); } }
RetryPolicy { @Override public String toString() { return MoreObjects.toStringHelper(this) .add("maxAttempts", maxAttempts) .add("initialBackoffNanos", initialBackoffNanos) .add("maxBackoffNanos", maxBackoffNanos) .add("backoffMultiplier", backoffMultiplier) .add("retryableStatusCodes", retryableStatusCodes) .toString(); } RetryPolicy(
      int maxAttempts,
      long initialBackoffNanos,
      long maxBackoffNanos,
      double backoffMultiplier,
      @Nonnull Set<Code> retryableStatusCodes); }
RetryPolicy { @Override public String toString() { return MoreObjects.toStringHelper(this) .add("maxAttempts", maxAttempts) .add("initialBackoffNanos", initialBackoffNanos) .add("maxBackoffNanos", maxBackoffNanos) .add("backoffMultiplier", backoffMultiplier) .add("retryableStatusCodes", retryableStatusCodes) .toString(); } RetryPolicy(
      int maxAttempts,
      long initialBackoffNanos,
      long maxBackoffNanos,
      double backoffMultiplier,
      @Nonnull Set<Code> retryableStatusCodes); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString(); }
RetryPolicy { @Override public String toString() { return MoreObjects.toStringHelper(this) .add("maxAttempts", maxAttempts) .add("initialBackoffNanos", initialBackoffNanos) .add("maxBackoffNanos", maxBackoffNanos) .add("backoffMultiplier", backoffMultiplier) .add("retryableStatusCodes", retryableStatusCodes) .toString(); } RetryPolicy(
      int maxAttempts,
      long initialBackoffNanos,
      long maxBackoffNanos,
      double backoffMultiplier,
      @Nonnull Set<Code> retryableStatusCodes); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString();  }