Search in sources :

Example 11 with ServiceInstance

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.");
        }
    };
}
Also used : Status(com.twitter.thrift.Status) ServiceInstance(com.twitter.thrift.ServiceInstance)

Example 12 with ServiceInstance

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();
}
Also used : TearDown(com.google.common.testing.TearDown) AsyncIface(com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface) ServiceInstance(com.twitter.thrift.ServiceInstance) Test(org.junit.Test)

Example 13 with ServiceInstance

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);
}
Also used : ServiceInstance(com.twitter.thrift.ServiceInstance) MonitorException(com.twitter.common.net.pool.DynamicHostSet.MonitorException) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test)

Example 14 with ServiceInstance

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());
}
Also used : Endpoint(com.twitter.thrift.Endpoint) ServiceInstance(com.twitter.thrift.ServiceInstance) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest) Test(org.junit.Test)

Aggregations

ServiceInstance (com.twitter.thrift.ServiceInstance)14 Test (org.junit.Test)10 Endpoint (com.twitter.thrift.Endpoint)8 BaseZooKeeperTest (com.twitter.common.zookeeper.testing.BaseZooKeeperTest)5 InetSocketAddress (java.net.InetSocketAddress)5 EndpointStatus (com.twitter.common.zookeeper.ServerSet.EndpointStatus)3 DynamicHostSet (com.twitter.common.net.pool.DynamicHostSet)2 EasyMockTest (com.twitter.common.testing.easymock.EasyMockTest)2 Status (com.twitter.thrift.Status)2 TearDown (com.google.common.testing.TearDown)1 GsonBuilder (com.google.gson.GsonBuilder)1 Command (com.twitter.common.base.Command)1 Pair (com.twitter.common.collections.Pair)1 MonitorException (com.twitter.common.net.pool.DynamicHostSet.MonitorException)1 Time (com.twitter.common.quantity.Time)1 AsyncIface (com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface)1 Group (com.twitter.common.zookeeper.Group)1 ServerSetImpl (com.twitter.common.zookeeper.ServerSetImpl)1 ZooKeeperClient (com.twitter.common.zookeeper.ZooKeeperClient)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1