|
19 | 19 | # limitations under the License.
|
20 | 20 |
|
21 | 21 |
|
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 |
23 | 25 | from neo4j.bolt import ProtocolError, ServiceUnavailable
|
24 | 26 |
|
25 | 27 | from test.stub.tools import StubTestCase, StubCluster
|
@@ -215,3 +217,27 @@ def test_should_error_when_missing_reader(self):
|
215 | 217 | uri = "bolt+routing://127.0.0.1:9001"
|
216 | 218 | with self.assertRaises(ProtocolError):
|
217 | 219 | 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