Java Code Examples for io.grpc.NameResolver#Factory

The following examples show how to use io.grpc.NameResolver#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagedChannelImplGetNameResolverTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void validTargetNoResovler() {
  Factory nameResolverFactory = new NameResolver.Factory() {
    @Override
    public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
      return null;
    }

    @Override
    public String getDefaultScheme() {
      return "defaultscheme";
    }
  };
  try {
    ManagedChannelImpl.getNameResolver(
        "foo.googleapis.com:8080", nameResolverFactory, NAMERESOLVER_ARGS);
    fail("Should fail");
  } catch (IllegalArgumentException e) {
    // expected
  }
}
 
Example 2
Source File: ManagedChannelImplGetNameResolverTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void validTargetNoResovler() {
  Factory nameResolverFactory = new NameResolver.Factory() {
    @Override
    public NameResolver newNameResolver(URI targetUri, Attributes params) {
      return null;
    }

    @Override
    public String getDefaultScheme() {
      return "defaultscheme";
    }
  };
  try {
    ManagedChannelImpl.getNameResolver(
        "foo.googleapis.com:8080", nameResolverFactory, NAME_RESOLVER_PARAMS);
    fail("Should fail");
  } catch (IllegalArgumentException e) {
    // expected
  }
}
 
Example 3
Source File: AbstractManagedChannelImplBuilderTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void nameResolverFactory_normal() {
  NameResolver.Factory nameResolverFactory = mock(NameResolver.Factory.class);
  assertEquals(builder, builder.nameResolverFactory(nameResolverFactory));
  assertEquals(nameResolverFactory, builder.getNameResolverFactory());
}
 
Example 4
Source File: AbstractManagedChannelImplBuilder.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link NameResolver.Factory} for the channel.
 */
NameResolver.Factory getNameResolverFactory() {
  if (authorityOverride == null) {
    return nameResolverFactory;
  } else {
    return new OverrideAuthorityNameResolverFactory(nameResolverFactory, authorityOverride);
  }
}
 
Example 5
Source File: AbstractManagedChannelImplBuilder.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Deprecated
@Override
public final T nameResolverFactory(NameResolver.Factory resolverFactory) {
  Preconditions.checkState(directServerAddress == null,
      "directServerAddress is set (%s), which forbids the use of NameResolverFactory",
      directServerAddress);
  if (resolverFactory != null) {
    this.nameResolverFactory = resolverFactory;
  } else {
    this.nameResolverFactory = nameResolverRegistry.asFactory();
  }
  return thisT();
}
 
Example 6
Source File: OverrideAuthorityNameResolverTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void overridesAuthority() {
  NameResolver nameResolverMock = mock(NameResolver.class);
  NameResolver.Factory wrappedFactory = mock(NameResolver.Factory.class);
  when(wrappedFactory.newNameResolver(any(URI.class), any(Attributes.class)))
      .thenReturn(nameResolverMock);
  String override = "override:5678";
  NameResolver.Factory factory =
      new OverrideAuthorityNameResolverFactory(wrappedFactory, override);
  NameResolver nameResolver = factory.newNameResolver(URI.create("dns:///localhost:443"),
      Attributes.EMPTY);
  assertNotNull(nameResolver);
  assertEquals(override, nameResolver.getServiceAuthority());
}
 
Example 7
Source File: OverrideAuthorityNameResolverTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void overridesAuthority() {
  NameResolver nameResolverMock = mock(NameResolver.class);
  NameResolver.Factory wrappedFactory = mock(NameResolver.Factory.class);
  when(wrappedFactory.newNameResolver(any(URI.class), any(NameResolver.Args.class)))
      .thenReturn(nameResolverMock);
  String override = "override:5678";
  NameResolver.Factory factory =
      new OverrideAuthorityNameResolverFactory(wrappedFactory, override);
  NameResolver nameResolver = factory.newNameResolver(URI.create("dns:///localhost:443"), ARGS);
  assertNotNull(nameResolver);
  assertEquals(override, nameResolver.getServiceAuthority());
}
 
Example 8
Source File: OverrideAuthorityNameResolverTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void wontWrapNull() {
  NameResolver.Factory wrappedFactory = mock(NameResolver.Factory.class);
  when(wrappedFactory.newNameResolver(any(URI.class), any(NameResolver.Args.class)))
      .thenReturn(null);
  NameResolver.Factory factory =
      new OverrideAuthorityNameResolverFactory(wrappedFactory, "override:5678");
  assertEquals(null,
      factory.newNameResolver(URI.create("dns:///localhost:443"), ARGS));
}
 
Example 9
Source File: AbstractManagedChannelImplBuilderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void nameResolverFactory_null() {
  NameResolver.Factory defaultValue = builder.getNameResolverFactory();
  builder.nameResolverFactory(mock(NameResolver.Factory.class));
  assertEquals(builder, builder.nameResolverFactory(null));
  assertEquals(defaultValue, builder.getNameResolverFactory());
}
 
Example 10
Source File: GrpcNameResolverFactory.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * A GRPC name resolver factory that integrates with Micronaut's discovery client.
 * @param discoveryClient The discovery client
 * @param serviceInstanceLists The service instance list
 * @return The name resolver
 */
@Singleton
@Requires(beans = DiscoveryClient.class)
@Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE)
protected NameResolver.Factory nameResolverFactory(
        DiscoveryClient discoveryClient,
        List<ServiceInstanceList> serviceInstanceLists) {
    return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists);
}
 
Example 11
Source File: GrpcNamedManagedChannelConfiguration.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
@Inject
public void setNameResolverFactory(@Nullable NameResolver.Factory factory) {
    super.setNameResolverFactory(factory);
}
 
Example 12
Source File: HealthCheckingLoadBalancerFactoryTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public NameResolver.Factory getNameResolverFactory() {
  throw new AssertionError("Should not be called");
}
 
Example 13
Source File: ForwardingLoadBalancerHelper.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
  return delegate().getNameResolverFactory();
}
 
Example 14
Source File: GrpcNamedManagedChannelConfiguration.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
@Inject
public void setNameResolverFactory(@Nullable NameResolver.Factory factory) {
    super.setNameResolverFactory(factory);
}
 
Example 15
Source File: GrpcManagedChannelConfiguration.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the name resolver factor to use.
 * @param factory The factory
 */
public void setNameResolverFactory(@Nullable NameResolver.Factory factory) {
    if (factory != null && resolveName) {
        channelBuilder.nameResolverFactory(factory);
    }
}
 
Example 16
Source File: OrcaOobUtilTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
  throw new AssertionError("Should not be called");
}
 
Example 17
Source File: ForwardingLoadBalancerHelper.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public NameResolver.Factory getNameResolverFactory() {
  return delegate().getNameResolverFactory();
}
 
Example 18
Source File: ManagedChannelImpl.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public NameResolver.Factory getNameResolverFactory() {
  return nameResolverFactory;
}
 
Example 19
Source File: SmartNameResolverFactory.java    From jetcd with Apache License 2.0 2 votes vote down vote up
public static NameResolver.Factory forEndpoints(String authority, Collection<URI> endpoints, URIResolverLoader loader) {

        return new SmartNameResolverFactory(authority, endpoints, loader);
    }
 
Example 20
Source File: OverrideAuthorityNameResolverFactory.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor for the {@link NameResolver.Factory}
 *
 * @param delegate The actual underlying factory that will produce the a {@link NameResolver}
 * @param authorityOverride The authority that will be returned by {@link
 *   NameResolver#getServiceAuthority()}
 */
OverrideAuthorityNameResolverFactory(NameResolver.Factory delegate, String authorityOverride) {
  this.delegate = delegate;
  this.authorityOverride = authorityOverride;
}