@Test public final void testLookup() throws Exception { final String localAddress = localAddressProvider.getLocalAddress(); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int serverPort = server.getPort(); final Configuration nameResolverConf = NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, serverPort) .set(NameResolverConfiguration.CACHE_TIMEOUT, 150) .set(NameResolverConfiguration.RETRY_TIMEOUT, RETRY_TIMEOUT) .set(NameResolverConfiguration.RETRY_COUNT, RETRY_COUNT) .build(); try (NameResolver client = Tang.Factory.getTang().newInjector(nameResolverConf).getInstance(NameClient.class)) { final Identifier id = factory.getNewInstance("Task1"); client.register(id, new InetSocketAddress(localAddress, 7001)); client.lookup(id); client.unregister(id); Thread.sleep(100); try { InetSocketAddress addr = client.lookup(id); Thread.sleep(100); addr = client.lookup(id); Assert.assertNull("client.lookup(id)", addr); } catch (final Exception e) { if (e instanceof ExecutionException) { Assert.assertTrue("Execution Exception cause is instanceof NamingException", e.getCause() instanceof NamingException); } else { throw e; } } } } }
@Override public InetSocketAddress lookup(final Identifier id) throws Exception { return this.lookupClient.lookup(id); }
NameClient implements NameResolver { @Override public InetSocketAddress lookup(final Identifier id) throws Exception { return this.lookupClient.lookup(id); } }
NameClient implements NameResolver { @Override public InetSocketAddress lookup(final Identifier id) throws Exception { return this.lookupClient.lookup(id); } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); }
NameClient implements NameResolver { @Override public InetSocketAddress lookup(final Identifier id) throws Exception { return this.lookupClient.lookup(id); } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); @Override void register(final Identifier id, final InetSocketAddress addr); @Override void unregister(final Identifier id); @Override InetSocketAddress lookup(final Identifier id); InetSocketAddress remoteLookup(final Identifier id); @Override void close(); }
NameClient implements NameResolver { @Override public InetSocketAddress lookup(final Identifier id) throws Exception { return this.lookupClient.lookup(id); } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); @Override void register(final Identifier id, final InetSocketAddress addr); @Override void unregister(final Identifier id); @Override InetSocketAddress lookup(final Identifier id); InetSocketAddress remoteLookup(final Identifier id); @Override void close();  }