3131 SessionConfig ,
3232 WorkspaceConfig ,
3333)
34+ from ..exceptions import (
35+ ServiceUnavailable ,
36+ SessionExpired ,
37+ )
3438from ..meta import (
3539 deprecation_warn ,
3640 experimental ,
@@ -236,9 +240,11 @@ class AsyncDriver:
236240 #: Flag if the driver has been closed
237241 _closed = False
238242
239- def __init__ (self , pool ):
243+ def __init__ (self , pool , default_workspace_config ):
240244 assert pool is not None
245+ assert default_workspace_config is not None
241246 self ._pool = pool
247+ self ._default_workspace_config = default_workspace_config
242248
243249 async def __aenter__ (self ):
244250 return self
@@ -285,17 +291,56 @@ async def close(self):
285291 await self ._pool .close ()
286292 self ._closed = True
287293
288- @ experimental ( "The configuration may change in the future." )
294+ # TODO: 6.0 - remove config argument
289295 async def verify_connectivity (self , ** config ):
290- """ This verifies if the driver can connect to a remote server or a cluster
291- by establishing a network connection with the remote and possibly exchanging
292- a few data before closing the connection. It throws exception if fails to connect.
296+ """Verify that the driver can establish a connection to the server.
297+
298+ This verifies if the driver can establish a reading connection to a
299+ remote server or a cluster. Some data will be exchanged.
293300
294- Use the exception to further understand the cause of the connectivity problem.
301+ .. note::
302+ Even if this method raises an exception, the driver still needs to
303+ be closed via :meth:`close` to free up all resources.
295304
296- Note: Even if this method throws an exception, the driver still need to be closed via close() to free up all resources.
305+ :raises DriverError: if the driver cannot connect to the remote.
306+ Use the exception to further understand the cause of the
307+ connectivity problem.
308+
309+ .. versionchanged:: 5.0 the config parameters will be removed in
310+ version 6 0. It has no effect starting in version 5.0.
297311 """
298- raise NotImplementedError
312+ if config :
313+ deprecation_warn (
314+ "verify_connectivity() will not accept any configuration "
315+ "parameters starting with version 6.0."
316+ )
317+
318+ await self .get_server_info ()
319+
320+ async def get_server_info (self ):
321+ """Get information about the connected Neo4j server.
322+
323+ Try to establish a working read connection to the remote server or a
324+ member of a cluster and exchange some data. Then return the contacted
325+ server's information.
326+
327+ In a cluster, there is no guarantee about which server will be
328+ contacted.
329+
330+ .. note::
331+ Even if this method raises an exception, the driver still needs to
332+ be closed via :meth:`close` to free up all resources.
333+
334+ :rtype: ServerInfo
335+
336+ :raises DriverError: if the driver cannot connect to the remote.
337+ Use the exception to further understand the cause of the
338+ connectivity problem.
339+
340+ .. versionadded:: 5.0
341+ """
342+ async with self .session () as session :
343+ return await session ._get_server_info ()
299344
300345 @experimental ("Feature support query, based on Bolt Protocol Version and Neo4j Server Version will change in the future." )
301346 async def supports_multi_db (self ):
@@ -339,7 +384,7 @@ def open(cls, target, *, auth=None, **config):
339384
340385 def __init__ (self , pool , default_workspace_config ):
341386 _Direct .__init__ (self , pool .address )
342- AsyncDriver .__init__ (self , pool )
387+ AsyncDriver .__init__ (self , pool , default_workspace_config )
343388 self ._default_workspace_config = default_workspace_config
344389
345390 def session (self , ** config ):
@@ -354,17 +399,6 @@ def session(self, **config):
354399 SessionConfig .consume (config ) # Consume the config
355400 return AsyncSession (self ._pool , session_config )
356401
357- @experimental ("The configuration may change in the future." )
358- async def verify_connectivity (self , ** config ):
359- server_agent = None
360- config ["fetch_size" ] = - 1
361- async with self .session (** config ) as session :
362- result = await session .run ("RETURN 1 AS x" )
363- value = await result .single ().value ()
364- summary = await result .consume ()
365- server_agent = summary .server .agent
366- return server_agent
367-
368402
369403class AsyncNeo4jDriver (_Routing , AsyncDriver ):
370404 """:class:`.AsyncNeo4jDriver` is instantiated for ``neo4j`` URIs. The
@@ -387,45 +421,10 @@ def open(cls, *targets, auth=None, routing_context=None, **config):
387421
388422 def __init__ (self , pool , default_workspace_config ):
389423 _Routing .__init__ (self , pool .get_default_database_initial_router_addresses ())
390- AsyncDriver .__init__ (self , pool )
391- self ._default_workspace_config = default_workspace_config
424+ AsyncDriver .__init__ (self , pool , default_workspace_config )
392425
393426 def session (self , ** config ):
394427 from .work import AsyncSession
395428 session_config = SessionConfig (self ._default_workspace_config , config )
396429 SessionConfig .consume (config ) # Consume the config
397430 return AsyncSession (self ._pool , session_config )
398-
399- @experimental ("The configuration may change in the future." )
400- async def verify_connectivity (self , ** config ):
401- """
402- :raise ServiceUnavailable: raised if the server does not support routing or if routing support is broken.
403- """
404- # TODO: Improve and update Stub Test Server to be able to test.
405- return await self ._verify_routing_connectivity ()
406-
407- async def _verify_routing_connectivity (self ):
408- from ..exceptions import (
409- Neo4jError ,
410- ServiceUnavailable ,
411- SessionExpired ,
412- )
413-
414- table = self ._pool .get_routing_table_for_default_database ()
415- routing_info = {}
416- for ix in list (table .routers ):
417- try :
418- routing_info [ix ] = await self ._pool .fetch_routing_info (
419- address = table .routers [0 ],
420- database = self ._default_workspace_config .database ,
421- imp_user = self ._default_workspace_config .impersonated_user ,
422- bookmarks = None ,
423- timeout = self ._default_workspace_config
424- .connection_acquisition_timeout
425- )
426- except (ServiceUnavailable , SessionExpired , Neo4jError ):
427- routing_info [ix ] = None
428- for key , val in routing_info .items ():
429- if val is not None :
430- return routing_info
431- raise ServiceUnavailable ("Could not connect to any routing servers." )
0 commit comments