Search in sources :

Example 1 with ServerSetImpl

use of com.twitter.common.zookeeper.ServerSetImpl in project commons by twitter.

the class DynamicPoolTest method mySetUp.

@Before
public void mySetUp() throws Exception {
    control = createControl();
    @SuppressWarnings("unchecked") Function<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>> poolFactory = control.createMock(Function.class);
    this.poolFactory = poolFactory;
    LoadBalancerImpl<InetSocketAddress> lb = LoadBalancerImpl.create(new RandomStrategy<InetSocketAddress>());
    poolRebuilds = new LinkedBlockingQueue<Pair<Set<ObjectPool<Connection<TTransport, InetSocketAddress>>>, Map<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>>>>();
    serverSet = new ServerSetImpl(createZkClient(), ZooDefs.Ids.OPEN_ACL_UNSAFE, "/test-service");
    Closure<Collection<InetSocketAddress>> onBackendsChosen = Closures.noop();
    Amount<Long, Time> restoreInterval = Amount.of(1L, Time.MINUTES);
    connectionPool = new DynamicPool<ServiceInstance, TTransport, InetSocketAddress>(serverSet, poolFactory, lb, onBackendsChosen, restoreInterval, Util.GET_ADDRESS, Util.IS_ALIVE) {

        @Override
        void poolRebuilt(Set<ObjectPool<Connection<TTransport, InetSocketAddress>>> deadPools, Map<InetSocketAddress, ObjectPool<Connection<TTransport, InetSocketAddress>>> livePools) {
            super.poolRebuilt(deadPools, livePools);
            poolRebuilds.offer(Pair.of(deadPools, livePools));
        }
    };
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServiceInstance(com.twitter.thrift.ServiceInstance) Time(com.twitter.common.quantity.Time) ServerSetImpl(com.twitter.common.zookeeper.ServerSetImpl) Collection(java.util.Collection) TTransport(org.apache.thrift.transport.TTransport) Pair(com.twitter.common.collections.Pair) Before(org.junit.Before)

Aggregations

Pair (com.twitter.common.collections.Pair)1 Time (com.twitter.common.quantity.Time)1 ServerSetImpl (com.twitter.common.zookeeper.ServerSetImpl)1 ServiceInstance (com.twitter.thrift.ServiceInstance)1 InetSocketAddress (java.net.InetSocketAddress)1 Collection (java.util.Collection)1 TTransport (org.apache.thrift.transport.TTransport)1 Before (org.junit.Before)1