Search in sources :

Example 6 with EndpointStatus

use of com.twitter.common.zookeeper.ServerSet.EndpointStatus in project commons by twitter.

the class DynamicPoolTest method testPoolRebuilds.

@Test
@SuppressWarnings("unchecked")
public void testPoolRebuilds() throws Exception {
    ConnectionFactory<Connection<TTransport, InetSocketAddress>> connectionFactory = control.createMock(ConnectionFactory.class);
    TTransport transport = new MockTSocket();
    Connection<TTransport, InetSocketAddress> connection = new TTransportConnection(transport, InetSocketAddress.createUnresolved("jake", 1137));
    expect(connectionFactory.create(EasyMock.isA(Amount.class))).andReturn(connection);
    ConnectionPool<Connection<TTransport, InetSocketAddress>> fooPool = new ConnectionPool<Connection<TTransport, InetSocketAddress>>(connectionFactory);
    expect(poolFactory.apply(InetSocketAddress.createUnresolved("foo", 42))).andReturn(fooPool);
    control.replay();
    Pair<Set<ObjectPool<Connection<TTransport, InetSocketAddress>>>, Map<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>>> rebuild1 = poolRebuilds.take();
    assertTrue("Should not have any dead pools on initial rebuild", rebuild1.getFirst().isEmpty());
    assertNoLivePools(rebuild1);
    EndpointStatus fooStatus = join("foo");
    Pair<Set<ObjectPool<Connection<TTransport, InetSocketAddress>>>, Map<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>>> rebuild2 = poolRebuilds.take();
    assertTrue("The NULL pool should never be tracked as dead", rebuild2.getFirst().isEmpty());
    assertEquals(transport, connectionPool.get().get());
    fooStatus.leave();
    Pair<Set<ObjectPool<Connection<TTransport, InetSocketAddress>>>, Map<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>>> rebuild3 = poolRebuilds.take();
    assertSame("Expected foo pool to be discarded", fooPool, Iterables.getOnlyElement(rebuild3.getFirst()));
    assertNoLivePools(rebuild1);
    control.verify();
}
Also used : ServerSet(com.twitter.common.zookeeper.ServerSet) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Amount(com.twitter.common.quantity.Amount) TTransportConnection(com.twitter.common.thrift.TTransportConnection) TTransportConnection(com.twitter.common.thrift.TTransportConnection) EndpointStatus(com.twitter.common.zookeeper.ServerSet.EndpointStatus) MockTSocket(com.twitter.common.thrift.testing.MockTSocket) TTransport(org.apache.thrift.transport.TTransport) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest)

Example 7 with EndpointStatus

use of com.twitter.common.zookeeper.ServerSet.EndpointStatus in project commons by twitter.

the class ServerSetImplTest method testStopMonitoring.

@Test
public void testStopMonitoring() throws Exception {
    ServerSetImpl client = createServerSet();
    Command stopMonitoring = client.watch(serverSetMonitor);
    assertChangeFiredEmpty();
    ServerSetImpl server = createServerSet();
    EndpointStatus foo = join(server, "foo");
    assertChangeFired("foo");
    EndpointStatus bar = join(server, "bar");
    assertChangeFired("foo", "bar");
    stopMonitoring.execute();
    // No new updates should be received since monitoring has stopped.
    foo.leave();
    assertTrue(serverSetBuffer.isEmpty());
    // Expiration event.
    assertTrue(serverSetBuffer.isEmpty());
}
Also used : EndpointStatus(com.twitter.common.zookeeper.ServerSet.EndpointStatus) Command(com.twitter.common.base.Command) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest) Test(org.junit.Test)

Example 8 with EndpointStatus

use of com.twitter.common.zookeeper.ServerSet.EndpointStatus in project commons by twitter.

the class StaticServerSetTest method testJoin.

@Test
public void testJoin() throws Exception {
    // Ensure join/update calls don't break.
    ImmutableSet<ServiceInstance> hosts = ImmutableSet.of();
    control.replay();
    ServerSet serverSet = new StaticServerSet(hosts);
    EndpointStatus status = serverSet.join(InetSocketAddress.createUnresolved("host", 1000), ImmutableMap.<String, InetSocketAddress>of(), Status.ALIVE);
    status.update(Status.DEAD);
}
Also used : EndpointStatus(com.twitter.common.zookeeper.ServerSet.EndpointStatus) ServiceInstance(com.twitter.thrift.ServiceInstance) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test)

Aggregations

EndpointStatus (com.twitter.common.zookeeper.ServerSet.EndpointStatus)8 Test (org.junit.Test)6 BaseZooKeeperTest (com.twitter.common.zookeeper.testing.BaseZooKeeperTest)5 ServiceInstance (com.twitter.thrift.ServiceInstance)3 Endpoint (com.twitter.thrift.Endpoint)2 InetSocketAddress (java.net.InetSocketAddress)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TearDown (com.google.common.testing.TearDown)1 Command (com.twitter.common.base.Command)1 ExceptionalCommand (com.twitter.common.base.ExceptionalCommand)1 Amount (com.twitter.common.quantity.Amount)1 EasyMockTest (com.twitter.common.testing.easymock.EasyMockTest)1 TTransportConnection (com.twitter.common.thrift.TTransportConnection)1 MockTSocket (com.twitter.common.thrift.testing.MockTSocket)1 Leader (com.twitter.common.zookeeper.Candidate.Leader)1 JoinException (com.twitter.common.zookeeper.Group.JoinException)1 ServerSet (com.twitter.common.zookeeper.ServerSet)1 LeadershipListener (com.twitter.common.zookeeper.SingletonService.LeadershipListener)1 Map (java.util.Map)1 Set (java.util.Set)1