Skip to content

Commit bb7fc5e

Browse files
committed
Load balancing strategy config
1 parent 1f4dd66 commit bb7fc5e

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/stub/test_routingdriver.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
# limitations under the License.
2020

2121

22-
from neo4j.v1 import GraphDatabase, RoutingDriver, READ_ACCESS, WRITE_ACCESS, SessionExpired
22+
from neo4j.v1 import GraphDatabase, READ_ACCESS, WRITE_ACCESS, SessionExpired, \
23+
RoutingDriver, RoutingConnectionPool, LeastConnectedLoadBalancingStrategy, LOAD_BALANCING_STRATEGY_ROUND_ROBIN, \
24+
RoundRobinLoadBalancingStrategy
2325
from neo4j.bolt import ProtocolError, ServiceUnavailable
2426

2527
from test.stub.tools import StubTestCase, StubCluster
@@ -215,3 +217,27 @@ def test_should_error_when_missing_reader(self):
215217
uri = "bolt+routing://127.0.0.1:9001"
216218
with self.assertRaises(ProtocolError):
217219
GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False)
220+
221+
def test_default_load_balancing_strategy_is_least_connected(self):
222+
with StubCluster({9001: "router.script"}):
223+
uri = "bolt+routing://127.0.0.1:9001"
224+
with GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False) as driver:
225+
self.assertIsInstance(driver, RoutingDriver)
226+
self.assertIsInstance(driver._pool, RoutingConnectionPool)
227+
self.assertIsInstance(driver._pool.load_balancing_strategy, LeastConnectedLoadBalancingStrategy)
228+
229+
def test_can_select_round_robin_load_balancing_strategy(self):
230+
with StubCluster({9001: "router.script"}):
231+
uri = "bolt+routing://127.0.0.1:9001"
232+
with GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False,
233+
load_balancing_strategy=LOAD_BALANCING_STRATEGY_ROUND_ROBIN) as driver:
234+
self.assertIsInstance(driver, RoutingDriver)
235+
self.assertIsInstance(driver._pool, RoutingConnectionPool)
236+
self.assertIsInstance(driver._pool.load_balancing_strategy, RoundRobinLoadBalancingStrategy)
237+
238+
def test_no_other_load_balancing_strategies_are_available(self):
239+
with StubCluster({9001: "router.script"}):
240+
uri = "bolt+routing://127.0.0.1:9001"
241+
with self.assertRaises(ValueError):
242+
with GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False, load_balancing_strategy=-1):
243+
pass

0 commit comments

Comments
 (0)