Search in sources :

Example 1 with MockTSocket

use of com.twitter.common.thrift.testing.MockTSocket in project commons by twitter.

the class ThriftConnectionFactoryTest method createConnectionFactory.

private ThriftConnectionFactory createConnectionFactory(int maxConnections) {
    return new ThriftConnectionFactory("foo", 1234, maxConnections) {

        @Override
        TTransport createTransport(int timeoutMillis) throws TTransportException {
            TTransport transport = new MockTSocket();
            transport.open();
            return transport;
        }
    };
}
Also used : MockTSocket(com.twitter.common.thrift.testing.MockTSocket) TTransport(org.apache.thrift.transport.TTransport)

Example 2 with MockTSocket

use of com.twitter.common.thrift.testing.MockTSocket 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)

Aggregations

MockTSocket (com.twitter.common.thrift.testing.MockTSocket)2 TTransport (org.apache.thrift.transport.TTransport)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Amount (com.twitter.common.quantity.Amount)1 TTransportConnection (com.twitter.common.thrift.TTransportConnection)1 ServerSet (com.twitter.common.zookeeper.ServerSet)1 EndpointStatus (com.twitter.common.zookeeper.ServerSet.EndpointStatus)1 BaseZooKeeperTest (com.twitter.common.zookeeper.testing.BaseZooKeeperTest)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.junit.Test)1