def test_get_sync(self): """ Test retrieve sync classes """ sock, conn, pool = get_rexpro('sync') self.assertTrue(issubclass(sock, RexProSyncSocket)) self.assertTrue(issubclass(conn, RexProSyncConnection)) self.assertTrue(issubclass(pool, RexProSyncConnectionPool)) sock, conn, pool = get_rexpro(u'sync') self.assertTrue(issubclass(sock, RexProSyncSocket)) self.assertTrue(issubclass(conn, RexProSyncConnection)) self.assertTrue(issubclass(pool, RexProSyncConnectionPool))
def test_retrieve_defaults(self): """ Test retreive default classes (Sync) """ sock, conn, pool = get_rexpro() self.assertTrue(issubclass(sock, RexProSyncSocket)) self.assertTrue(issubclass(conn, RexProSyncConnection)) self.assertTrue(issubclass(pool, RexProSyncConnectionPool)) sock, conn, pool = get_rexpro(None) self.assertTrue(issubclass(sock, RexProSyncSocket)) self.assertTrue(issubclass(conn, RexProSyncConnection)) self.assertTrue(issubclass(pool, RexProSyncConnectionPool))
def test_get_gevent(self): """ Test retrieve gevent classes """ if PY2: sock, conn, pool = get_rexpro('gevent') self.assertTrue(issubclass(sock, RexProGeventSocket)) self.assertTrue(issubclass(conn, RexProGeventConnection)) self.assertTrue(issubclass(pool, RexProGeventConnectionPool))
def setup(host, graph_name='graph', graph_obj_name='g', username='', password='', metric_reporters=None, pool_size=10, concurrency='sync'): """ Sets up the connection, and instantiates the models """ global _connection_pool global SOCKET_TYPE, CONNECTION_TYPE, CONNECTION_POOL_TYPE, HOST_PARAMS global metric_manager if metric_reporters: # pragma: no cover metric_manager.setup_reporters(metric_reporters) sock, conn, pool = get_rexpro(stype=concurrency) # store for reference SOCKET_TYPE = sock CONNECTION_TYPE = conn CONNECTION_POOL_TYPE = pool HOST_PARAMS = _parse_host(host, username, password, graph_name, graph_obj_name) if isinstance(host, string_types): _connection_pool = pool(pool_size=pool_size, **HOST_PARAMS) else: # pragma: no cover raise MogwaiConnectionError("Must Specify at least one host or list of hosts: host: {}, graph_name: {}".format( host, graph_name) )
def setup(host, graph_name='graph', graph_obj_name='g', username='', password='', metric_reporters=None, pool_size=10, concurrency='sync'): """ Sets up the connection, and instantiates the models """ global _connection_pool global SOCKET_TYPE, CONNECTION_TYPE, CONNECTION_POOL_TYPE, HOST_PARAMS global metric_manager if metric_reporters: # pragma: no cover metric_manager.setup_reporters(metric_reporters) sock, conn, pool = get_rexpro(stype=concurrency) # store for reference SOCKET_TYPE = sock CONNECTION_TYPE = conn CONNECTION_POOL_TYPE = pool HOST_PARAMS = _parse_host(host, username, password, graph_name, graph_obj_name) if isinstance(host, string_types): _connection_pool = pool(pool_size=pool_size, **HOST_PARAMS) else: # pragma: no cover raise MogwaiConnectionError( "Must Specify at least one host or list of hosts: host: {}, graph_name: {}" .format(host, graph_name))
def test_get_eventlet(self): """ Test retrieve eventlet classes """ sock, conn, pool = get_rexpro('eventlet') self.assertTrue(issubclass(sock, RexProEventletSocket)) self.assertTrue(issubclass(conn, RexProEventletConnection)) self.assertTrue(issubclass(pool, RexProEventletConnectionPool))
def test_raise_invalid_type(self): with self.assertRaises(RexProInvalidConnectorTypeException): sock, conn, pool = get_rexpro('doesnotexist')