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();
}
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());
}
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);
}
Aggregations