forked from datastax/python-driver
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RackAwareRoundRobinPolicy for host selection
- Loading branch information
1 parent
c9b24b7
commit 05e59a5
Showing
6 changed files
with
264 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
|
||
from cassandra.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT, NoHostAvailable | ||
from cassandra.policies import ConstantReconnectionPolicy, HostFilterPolicy, RackAwareRoundRobinPolicy, RoundRobinPolicy, SimpleConvictionPolicy, \ | ||
WhiteListRoundRobinPolicy, ExponentialBackoffRetryPolicy | ||
from cassandra.pool import Host | ||
from cassandra.connection import DefaultEndPoint | ||
|
||
from tests.integration import PROTOCOL_VERSION, local, use_multidc, use_singledc, TestCluster | ||
|
||
from concurrent.futures import wait as wait_futures | ||
|
||
|
||
def setup_module(): | ||
use_multidc({'DC1': {'RC1': 2, 'RC2': 2}, 'DC2': {'RC1': 2}}) | ||
|
||
class RackAwareRoundRobinPolicyTests(unittest.TestCase): | ||
@classmethod | ||
def setup_class(cls): | ||
cls.cluster = Cluster(contact_points=["127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6"], protocol_version=PROTOCOL_VERSION, | ||
load_balancing_policy=RackAwareRoundRobinPolicy("DC1", "RAC1", used_hosts_per_remote_dc=1), | ||
reconnection_policy=ConstantReconnectionPolicy(1)) | ||
cls.session = cls.cluster.connect() | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
cls.cluster.shutdown() | ||
|
||
def test_rack_aware(self): | ||
self.cluster = Cluster(contact_points=["127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6"], protocol_version=PROTOCOL_VERSION, | ||
load_balancing_policy=RackAwareRoundRobinPolicy("DC1", "RAC1", used_hosts_per_remote_dc=1), | ||
reconnection_policy=ConstantReconnectionPolicy(1)) | ||
self.session = self.cluster.connect() | ||
queried_hosts = set() | ||
for _ in range(10): | ||
response = self.session.execute('SELECT * from system.local') | ||
queried_hosts.update(response.response_future.attempted_hosts) | ||
queried_hosts = set(host.address for host in queried_hosts) | ||
# Performe some checks | ||
self.cluster.shutdown() | ||
|
||
def test_rack_aware_wrong_dc(self): | ||
self.cluster = Cluster(contact_points=["127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6"], protocol_version=PROTOCOL_VERSION, | ||
load_balancing_policy=RackAwareRoundRobinPolicy("WRONG_DC1", "RAC1", used_hosts_per_remote_dc=0), | ||
reconnection_policy=ConstantReconnectionPolicy(1)) | ||
self.assertRaises(NoHostAvailable, self.cluster.connect) | ||
self.cluster.shutdown() | ||
|
Oops, something went wrong.