SingleEndpointService extends EndpointServiceImpl { @Override public void lookup(EndpointPromise future) { final String methodName = "lookup"; logger.entry(this, methodName, future); if (exhausted) { exhausted = false; future.setWait(calculateDelay(retryCount++)); } else { exhausted = true; future.setSuccess(endpoint); } logger.exit(this, methodName); } SingleEndpointService(String uri, String user, String password, SSLOptions sslOptions); @Override void lookup(EndpointPromise future); @Override void onSuccess(Endpoint endpoint);  }
@Test public void getOneEndpoint() { EndpointService service = new SingleEndpointService("amqp: MockEndpointPromise endpointPromise = new MockEndpointPromise(MockEndpointPromise.Method.SUCCESS); service.lookup(endpointPromise); assertTrue("Expected future to be marked as done", endpointPromise.isComplete()); Endpoint endpoint = endpointPromise.getEndoint(); assertNotNull("Expected a non-null Endpoint object", endpoint); assertEquals("Endpoint hostname does not match", "example.org", endpoint.getHost()); assertEquals(5672, endpoint.getPort()); assertNull(endpoint.getUser()); assertNull(endpoint.getPassword()); assertFalse(endpoint.useSsl()); assertFalse(endpoint.getSSLOptions().getVerifyName()); }
@Test public void exhaustEndpoints() { EndpointService service = new SingleEndpointService("amqp: MockEndpointPromise[] promises = new MockEndpointPromise[6]; for (int i = 0; i < promises.length; ++i) { promises[i] = new MockEndpointPromise(i % 2 == 0 ? MockEndpointPromise.Method.SUCCESS : MockEndpointPromise.Method.WAIT); service.lookup(promises[i]); assertTrue("Expected future " + i + " to be marked as done", promises[i].isComplete()); } long t1 = promises[1].actualDelay; long t2 = promises[3].actualDelay; long t3 = promises[5].actualDelay; assertTrue("Retry time #1 (" + t1 + ") should be > 0", t1 > 0); assertTrue("Retry time #2 (" + t2 + ") should be > time #1 (" + t1 + ")", t2 > t1); assertTrue("Retry time #3 (" + t3 + ") should be > time #2 (" + t2 + ")", t3 > t2); }