Start using CCM for integration tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ dist
|
|||||||
.coverage
|
.coverage
|
||||||
cover/
|
cover/
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
tests/integration/ccm
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -62,7 +62,7 @@ setup(
|
|||||||
packages=["cassandra", "cassandra.io"],
|
packages=["cassandra", "cassandra.io"],
|
||||||
ext_modules=[murmur3],
|
ext_modules=[murmur3],
|
||||||
install_requires=['futures'],
|
install_requires=['futures'],
|
||||||
test_requires=['nose', 'mock'],
|
tests_require=['nose', 'mock', 'ccm'],
|
||||||
cmdclass={"doc": doc},
|
cmdclass={"doc": doc},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 3 - Alpha',
|
'Development Status :: 3 - Alpha',
|
||||||
|
|||||||
@@ -1,53 +1,75 @@
|
|||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
from threading import Event
|
||||||
|
|
||||||
from cassandra.cluster import Cluster
|
logging.getLogger().addHandler(logging.StreamHandler())
|
||||||
from cassandra.policies import HostDistance
|
|
||||||
|
try:
|
||||||
|
from ccmlib.cluster import Cluster as CCMCluster
|
||||||
|
from ccmlib import common
|
||||||
|
except ImportError:
|
||||||
|
raise unittest.SkipTest('ccm is a dependency for integration tests')
|
||||||
|
|
||||||
|
CLUSTER_NAME = 'test_cluster'
|
||||||
|
CCM_CLUSTER = None
|
||||||
|
|
||||||
|
path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'ccm')
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.mkdir(path)
|
||||||
|
|
||||||
|
|
||||||
|
def get_cluster():
|
||||||
|
return CCM_CLUSTER
|
||||||
|
|
||||||
existing_keyspaces = None
|
|
||||||
|
|
||||||
def setup_package():
|
def setup_package():
|
||||||
try:
|
try:
|
||||||
cluster = Cluster()
|
try:
|
||||||
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
cluster = CCMCluster.load(path, CLUSTER_NAME)
|
||||||
cluster.set_max_connections_per_host(HostDistance.LOCAL, 1)
|
log.debug("Found existing ccm test cluster, clearing")
|
||||||
session = cluster.connect()
|
cluster.clear()
|
||||||
except Exception, exc:
|
except:
|
||||||
log.exception('Failed to connect to cluster:')
|
log.debug("Creating new ccm test cluster")
|
||||||
raise unittest.SkipTest('Failed to connect to cluster: %r' % exc)
|
cluster = CCMCluster(path, CLUSTER_NAME, cassandra_version='1.2.6')
|
||||||
|
cluster.set_configuration_options({'start_native_transport': True})
|
||||||
|
common.switch_cluster(path, CLUSTER_NAME)
|
||||||
|
cluster.populate(3)
|
||||||
|
|
||||||
try:
|
log.debug("Starting ccm test cluster")
|
||||||
global existing_keyspaces
|
cluster.start(wait_for_binary_proto=True)
|
||||||
results = session.execute("SELECT keyspace_name FROM system.schema_keyspaces")
|
except:
|
||||||
existing_keyspaces = set([row[0] for row in results])
|
log.exception("Failed to start ccm cluster:")
|
||||||
finally:
|
raise
|
||||||
try:
|
|
||||||
cluster.shutdown()
|
global CCM_CLUSTER
|
||||||
except Exception, exc:
|
CCM_CLUSTER = cluster
|
||||||
log.exception('Failed to connect to cluster:')
|
|
||||||
raise unittest.SkipTest('Failed to connect to cluster: %r' % exc)
|
|
||||||
|
|
||||||
|
|
||||||
def teardown_package():
|
def teardown_package():
|
||||||
|
if CCM_CLUSTER:
|
||||||
try:
|
try:
|
||||||
cluster = Cluster()
|
CCM_CLUSTER.clear()
|
||||||
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
|
||||||
cluster.set_max_connections_per_host(HostDistance.LOCAL, 1)
|
|
||||||
session = cluster.connect()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception('Failed to connect to cluster:')
|
log.exception("Failed to clear cluster")
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
if existing_keyspaces:
|
|
||||||
results = session.execute("SELECT keyspace_name FROM system.schema_keyspaces")
|
|
||||||
current_keyspaces = set([row[0] for row in results])
|
|
||||||
for keyspace in current_keyspaces - existing_keyspaces:
|
|
||||||
session.execute("DROP KEYSPACE %s" % (keyspace,))
|
|
||||||
|
|
||||||
finally:
|
class UpDownWaiter(object):
|
||||||
try:
|
|
||||||
cluster.shutdown()
|
def __init__(self, host):
|
||||||
except:
|
self.down_event = Event()
|
||||||
log.exception('Failed to connect to cluster:')
|
self.up_event = Event()
|
||||||
|
host.monitor.register(self)
|
||||||
|
|
||||||
|
def on_up(self, host):
|
||||||
|
self.up_event.set()
|
||||||
|
|
||||||
|
def on_down(self, host):
|
||||||
|
self.down_event.set()
|
||||||
|
|
||||||
|
def wait_for_down(self):
|
||||||
|
self.down_event.wait()
|
||||||
|
|
||||||
|
def wait_for_up(self):
|
||||||
|
self.up_event.wait()
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ class TokenMetadataTest(unittest.TestCase):
|
|||||||
cluster = Cluster()
|
cluster = Cluster()
|
||||||
cluster.connect()
|
cluster.connect()
|
||||||
tmap = cluster.metadata.token_map
|
tmap = cluster.metadata.token_map
|
||||||
self.assertTrue(issubclass(tmap.token_cls, Token))
|
self.assertTrue(issubclass(tmap.token_class, Token))
|
||||||
self.assertEqual(1, len(tmap.ring))
|
self.assertEqual(1, len(tmap.ring))
|
||||||
self.assertEqual(1, len(tmap.tokens_to_hosts))
|
self.assertEqual(1, len(tmap.tokens_to_hosts))
|
||||||
cluster.shutdown()
|
cluster.shutdown()
|
||||||
|
|||||||
Reference in New Issue
Block a user