def authenticated_client(request): try: if request.param == 'basic': # turn off certificate verification for testing purposes only ssl_opts = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) ssl_opts.verify_mode = ssl.CERT_NONE client = Client(basic_url, 'gmodern', username='******', password='******', transport_factory=lambda: TornadoTransport( ssl_options=ssl_opts)) elif request.param == 'kerberos': client = Client(kerberos_url, 'gmodern', kerberized_service=kerberized_service) else: raise ValueError("Invalid authentication option - " + request.param) except OSError: pytest.skip('Gremlin Server is not running') else: def fin(): client.close() request.addfinalizer(fin) return client
def remote_connection_authenticated(request): try: if request.param == 'basic': # turn off certificate verification for testing purposes only ssl_opts = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) ssl_opts.verify_mode = ssl.CERT_NONE remote_conn = DriverRemoteConnection( basic_url, 'gmodern', username='******', password='******', message_serializer=serializer.GraphSONSerializersV2d0(), transport_factory=lambda: TornadoTransport(ssl_options=ssl_opts )) elif request.param == 'kerberos': remote_conn = DriverRemoteConnection( kerberos_url, 'gmodern', kerberized_service=kerberized_service, message_serializer=serializer.GraphSONSerializersV2d0()) else: raise ValueError("Invalid authentication option - " + request.param) except OSError: pytest.skip('Gremlin Server is not running') else: def fin(): remote_conn.close() request.addfinalizer(fin) return remote_conn
def __init__(self, url, traversal_source, protocol_factory=None, transport_factory=None, pool_size=None, max_workers=None, message_serializer=None, username="", password="", kerberized_service="", headers=None, session=""): self._url = url self._headers = headers self._traversal_source = traversal_source if message_serializer is None: message_serializer = serializer.GraphSONSerializersV3d0() self._message_serializer = message_serializer self._username = username self._password = password self._session = session self._sessionEnabled = (session != "") if transport_factory is None: try: from gremlin_python.driver.tornado.transport import ( TornadoTransport) except ImportError: raise Exception("Please install Tornado or pass" "custom transport factory") else: transport_factory = lambda: TornadoTransport() self._transport_factory = transport_factory if protocol_factory is None: protocol_factory = lambda: protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password, kerberized_service=kerberized_service) self._protocol_factory = protocol_factory if self._sessionEnabled: if pool_size is None: pool_size = 1 elif pool_size != 1: raise Exception("PoolSize must be 1 on session mode!") if pool_size is None: pool_size = 4 self._pool_size = pool_size # This is until concurrent.futures backport 3.1.0 release if max_workers is None: # If your application is overlapping Gremlin I/O on multiple threads # consider passing kwarg max_workers = (cpu_count() or 1) * 5 max_workers = pool_size self._executor = ThreadPoolExecutor(max_workers=max_workers) # Threadsafe queue self._pool = queue.Queue() self._fill_pool()
def __init__(self, url, traversal_source, protocol_factory=None, transport_factory=None, pool_size=None, max_workers=None, message_serializer=None, username="", password="", headers=None, ping_interval=None): self._url = url self._headers = headers self._traversal_source = traversal_source if message_serializer is None: message_serializer = serializer.GraphSONSerializersV3d0() self._message_serializer = message_serializer self._username = username self._password = password self._ping_interval = ping_interval if transport_factory is None: try: from gremlin_python.driver.tornado.transport import ( TornadoTransport) except ImportError: raise Exception("Please install Tornado or pass" "custom transport factory") else: transport_factory = lambda: TornadoTransport() self._transport_factory = transport_factory if protocol_factory is None: protocol_factory = lambda: protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password) self._protocol_factory = protocol_factory if pool_size is None: pool_size = 4 self._pool_size = pool_size # This is until concurrent.futures backport 3.1.0 release if max_workers is None: # Use this number because ThreadPoolExecutor is often # used to overlap I/O instead of CPU work. max_workers = (cpu_count() or 1) * 5 self._executor = ThreadPoolExecutor(max_workers=max_workers) # Threadsafe queue self._pool = queue.Queue() self._fill_pool() if (ping_interval): self._ping_event_loop = asyncio.new_event_loop() self._ping_thread = Thread(target=self.ping_server, args=(self._ping_event_loop, ), daemon=True) self._ping_thread.start()
def test_client_side_timeout_set_for_tornado(client): client = Client('ws://localhost:45940/gremlin', 'gmodern', transport_factory=lambda: TornadoTransport(read_timeout=1, write_timeout=1)) try: # should fire an exception client.submit('Thread.sleep(2000);1').all().result() assert False except TimeoutError as toerr: assert str(toerr) == "Operation timed out after 1 seconds"
def connection(request): protocol = GremlinServerWSProtocol( GraphSONMessageSerializer(), username='******', password='******') executor = concurrent.futures.ThreadPoolExecutor(5) pool = queue.Queue() try: conn = Connection('ws://localhost:45941/gremlin', 'gmodern', protocol, lambda: TornadoTransport(), executor, pool) except OSError: executor.shutdown() pytest.skip('Gremlin Server is not running') else: def fin(): executor.shutdown() conn.close() request.addfinalizer(fin) return conn
def __init__(self): TornadoTransport.__init__(self)