<s> import tornado . ioloop <EOL> import logging <EOL> import time <EOL> from asyncmongo . errors import TooManyConnections <EOL> import test_shunt <EOL> import asyncmongo <EOL> TEST_TIMESTAMP = int ( time . time ( ) ) <EOL> class PooledDBTest ( test_shunt . MongoTest ) : <EOL> def test_pooled_db ( self ) : <EOL> """<STR_LIT>""" <EOL> print asyncmongo . __file__ <EOL> test_shunt . setup ( ) <EOL> client = asyncmongo . Client ( '<STR_LIT>' , maxconnections = <NUM_LIT:5> , host = '<STR_LIT:127.0.0.1>' , port = <NUM_LIT> , dbname = '<STR_LIT:test>' ) <EOL> test_users_collection = client . connection ( '<STR_LIT>' ) <EOL> def insert_callback ( response , error ) : <EOL> tornado . ioloop . IOLoop . instance ( ) . stop ( ) <EOL> logging . info ( response ) <EOL> assert len ( response ) == <NUM_LIT:1> <EOL> test_shunt . register_called ( '<STR_LIT>' ) <EOL> test_users_collection . insert ( { "<STR_LIT>" : "<STR_LIT>" % TEST_TIMESTAMP } , safe = True , callback = insert_callback ) <EOL> tornado . ioloop . IOLoop . instance ( ) . start ( ) <EOL> test_shunt . assert_called ( '<STR_LIT>' ) <EOL> def pool_callback ( response , error ) : <EOL> if test_shunt . is_called ( '<STR_LIT>' ) : <EOL> tornado . ioloop . IOLoop . instance ( ) . stop ( ) <EOL> assert len ( response ) == <NUM_LIT:1> <EOL> test_shunt . register_called ( '<STR_LIT>' ) <EOL> def pool_callback2 ( response , error ) : <EOL> if test_shunt . is_called ( '<STR_LIT>' ) : <EOL> tornado . ioloop . IOLoop . instance ( ) . stop ( ) <EOL> assert len ( response ) == <NUM_LIT:1> <EOL> test_shunt . register_called ( '<STR_LIT>' ) <EOL> test_users_collection . find ( { } , limit = <NUM_LIT:1> , callback = pool_callback ) <EOL> test_users_collection . find ( { } , limit = <NUM_LIT:1> , callback = pool_callback2 ) <EOL> tornado . ioloop . IOLoop . instance ( ) . start ( ) <EOL> test_shunt . assert_called ( '<STR_LIT>' ) <EOL> test_shunt . assert_called ( '<STR_LIT>' ) <EOL> def too_many_connections ( self ) : <EOL> clients = [ <EOL> asyncmongo . Client ( '<STR_LIT>' , maxconnections = <NUM_LIT:2> , host = '<STR_LIT:127.0.0.1>' , port = <NUM_LIT> , dbname = '<STR_LIT:test>' ) <EOL> for i in range ( <NUM_LIT:3> ) <EOL> ] <EOL> def callback ( response , error ) : <EOL> pass <EOL> for client in clients [ : <NUM_LIT:2> ] : <EOL> client . connection ( '<STR_LIT:foo>' ) . find ( { } , callback = callback ) <EOL> self . assertRaises ( <EOL> TooManyConnections , <EOL> lambda : clients [ <NUM_LIT:2> ] . connection ( '<STR_LIT:foo>' ) . find ( { } , callback = callback ) <EOL> ) </s>
