use of com.twitter.thrift.ServiceInstance in project commons by twitter.
the class StaticServerSet method join.
private EndpointStatus join(InetSocketAddress endpoint, Map<String, InetSocketAddress> auxEndpoints, Optional<Integer> shardId) {
LOG.warning("Attempt to join fixed server set ignored.");
ServiceInstance joining = new ServiceInstance(ServerSets.toEndpoint(endpoint), Maps.transformValues(auxEndpoints, ServerSets.TO_ENDPOINT), Status.ALIVE);
if (shardId.isPresent()) {
joining.setShard(shardId.get());
}
if (!hosts.contains(joining)) {
LOG.log(Level.SEVERE, "Joining instance " + joining + " does not match any member of the static set.");
}
return new EndpointStatus() {
@Override
public void leave() throws UpdateException {
LOG.warning("Attempt to adjust state of fixed server set ignored.");
}
@Override
public void update(Status status) throws UpdateException {
LOG.warning("Attempt to adjust state of fixed server set ignored.");
}
};
}
use of com.twitter.thrift.ServiceInstance in project commons by twitter.
the class ThriftFactoryTest method testCreateEmpty.
@Test(expected = TResourceExhaustedException.class)
public void testCreateEmpty() throws Exception {
@SuppressWarnings("unchecked") DynamicHostSet<ServiceInstance> emptyHostSet = control.createMock(DynamicHostSet.class);
final Thrift<GoodService.Iface> thrift = ThriftFactory.create(GoodService.Iface.class).withMaxConnectionsPerEndpoint(1).build(emptyHostSet);
addTearDown(new TearDown() {
@Override
public void tearDown() {
thrift.close();
}
});
GoodService.Iface client = thrift.create();
// This should throw a TResourceExhaustedException
client.doWork();
}
use of com.twitter.thrift.ServiceInstance in project commons by twitter.
the class CompoundServerSetTest method testMonitorFailure.
@Test(expected = MonitorException.class)
public void testMonitorFailure() throws Exception {
serverSet1.watch(EasyMock.<HostChangeMonitor<ServiceInstance>>anyObject());
expectLastCall().andThrow(new MonitorException("Monitor exception", null));
control.replay();
compoundServerSet.watch(compoundMonitor);
}
use of com.twitter.thrift.ServiceInstance in project commons by twitter.
the class ServerSetImplTest method testJsonCodecRoundtrip.
@Test
public void testJsonCodecRoundtrip() throws Exception {
Codec<ServiceInstance> codec = ServerSetImpl.createJsonCodec();
ServiceInstance instance1 = new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.of("http", new Endpoint("foo", 8080)), Status.ALIVE).setShard(0);
byte[] data = ServerSets.serializeServiceInstance(instance1, codec);
assertTrue(ServerSets.deserializeServiceInstance(data, codec).getServiceEndpoint().isSetPort());
assertTrue(ServerSets.deserializeServiceInstance(data, codec).isSetShard());
ServiceInstance instance2 = new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.of("http-admin1", new Endpoint("foo", 8080)), Status.ALIVE);
data = ServerSets.serializeServiceInstance(instance2, codec);
assertTrue(ServerSets.deserializeServiceInstance(data, codec).getServiceEndpoint().isSetPort());
assertFalse(ServerSets.deserializeServiceInstance(data, codec).isSetShard());
ServiceInstance instance3 = new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.<String, Endpoint>of(), Status.ALIVE);
data = ServerSets.serializeServiceInstance(instance3, codec);
assertTrue(ServerSets.deserializeServiceInstance(data, codec).getServiceEndpoint().isSetPort());
assertFalse(ServerSets.deserializeServiceInstance(data, codec).isSetShard());
}
Aggregations