use of com.twitter.thrift.Endpoint in project distributedlog by twitter.
the class TestInetNameResolution method testInetNameResolution.
@Test(timeout = 10000)
public void testInetNameResolution() throws Exception {
String nameStr = "inet!127.0.0.1:3181";
final CountDownLatch resolved = new CountDownLatch(1);
final AtomicBoolean validationFailed = new AtomicBoolean(false);
NameServerSet serverSet = new NameServerSet(nameStr);
serverSet.watch(new DynamicHostSet.HostChangeMonitor<ServiceInstance>() {
@Override
public void onChange(ImmutableSet<ServiceInstance> hostSet) {
if (hostSet.size() > 1) {
logger.error("HostSet has more elements than expected {}", hostSet);
validationFailed.set(true);
resolved.countDown();
} else if (hostSet.size() == 1) {
ServiceInstance serviceInstance = hostSet.iterator().next();
Endpoint endpoint = serviceInstance.getAdditionalEndpoints().get("thrift");
InetSocketAddress address = new InetSocketAddress(endpoint.getHost(), endpoint.getPort());
if (endpoint.getPort() != 3181) {
logger.error("Port does not match the expected port {}", endpoint.getPort());
validationFailed.set(true);
} else if (!address.getAddress().getHostAddress().equals("127.0.0.1")) {
logger.error("Host address does not match the expected address {}", address.getAddress().getHostAddress());
validationFailed.set(true);
}
resolved.countDown();
}
}
});
resolved.await();
Assert.assertEquals(false, validationFailed.get());
}
use of com.twitter.thrift.Endpoint in project distributedlog by twitter.
the class NameServerSet method endpointAddressToServiceInstance.
private ServiceInstance endpointAddressToServiceInstance(Address endpointAddress) {
if (endpointAddress instanceof Address.Inet) {
InetSocketAddress inetSocketAddress = ((Address.Inet) endpointAddress).addr();
Endpoint endpoint = new Endpoint(inetSocketAddress.getHostString(), inetSocketAddress.getPort());
HashMap<String, Endpoint> map = new HashMap<String, Endpoint>();
map.put("thrift", endpoint);
return new ServiceInstance(endpoint, map, Status.ALIVE);
} else {
logger.error("We expect InetSocketAddress while the resolved address {} was {}", endpointAddress, endpointAddress.getClass());
throw new UnsupportedOperationException("invalid endpoint address: " + endpointAddress);
}
}
use of com.twitter.thrift.Endpoint in project distributedlog by twitter.
the class NameServerSet method hostSetToString.
private String hostSetToString(ImmutableSet<ServiceInstance> hostSet) {
StringBuilder result = new StringBuilder();
result.append("(");
for (ServiceInstance serviceInstance : hostSet) {
Endpoint endpoint = serviceInstance.getServiceEndpoint();
result.append(String.format(" %s:%d", endpoint.getHost(), endpoint.getPort()));
}
result.append(" )");
return result.toString();
}
Aggregations