cqle: make default CL based on core default
+ test updates PYTHON-416
This commit is contained in:
@@ -16,7 +16,6 @@ from collections import namedtuple
|
|||||||
import logging
|
import logging
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from cassandra import ConsistencyLevel
|
|
||||||
from cassandra.cluster import Cluster, _NOT_SET, NoHostAvailable, UserTypeDoesNotExist
|
from cassandra.cluster import Cluster, _NOT_SET, NoHostAvailable, UserTypeDoesNotExist
|
||||||
from cassandra.query import SimpleStatement, Statement, dict_factory
|
from cassandra.query import SimpleStatement, Statement, dict_factory
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ Host = namedtuple('Host', ['name', 'port'])
|
|||||||
cluster = None
|
cluster = None
|
||||||
session = None
|
session = None
|
||||||
lazy_connect_args = None
|
lazy_connect_args = None
|
||||||
default_consistency_level = ConsistencyLevel.LOCAL_QUORUM
|
|
||||||
|
|
||||||
|
|
||||||
# Because type models may be registered before a connection is present,
|
# Because type models may be registered before a connection is present,
|
||||||
@@ -95,7 +93,7 @@ def set_session(s):
|
|||||||
def setup(
|
def setup(
|
||||||
hosts,
|
hosts,
|
||||||
default_keyspace,
|
default_keyspace,
|
||||||
consistency=ConsistencyLevel.ONE,
|
consistency=None,
|
||||||
lazy_connect=False,
|
lazy_connect=False,
|
||||||
retry_connect=False,
|
retry_connect=False,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
@@ -104,12 +102,12 @@ def setup(
|
|||||||
|
|
||||||
:param list hosts: list of hosts, (``contact_points`` for :class:`cassandra.cluster.Cluster`)
|
:param list hosts: list of hosts, (``contact_points`` for :class:`cassandra.cluster.Cluster`)
|
||||||
:param str default_keyspace: The default keyspace to use
|
:param str default_keyspace: The default keyspace to use
|
||||||
:param int consistency: The global default :class:`~.ConsistencyLevel`
|
:param int consistency: The global default :class:`~.ConsistencyLevel` - default is the same as :attr:`.Session.default_consistency_level`
|
||||||
:param bool lazy_connect: True if should not connect until first use
|
:param bool lazy_connect: True if should not connect until first use
|
||||||
:param bool retry_connect: True if we should retry to connect even if there was a connection failure initially
|
:param bool retry_connect: True if we should retry to connect even if there was a connection failure initially
|
||||||
:param \*\*kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
|
:param \*\*kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
|
||||||
"""
|
"""
|
||||||
global cluster, session, default_consistency_level, lazy_connect_args
|
global cluster, session, lazy_connect_args
|
||||||
|
|
||||||
if 'username' in kwargs or 'password' in kwargs:
|
if 'username' in kwargs or 'password' in kwargs:
|
||||||
raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider")
|
raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider")
|
||||||
@@ -117,7 +115,6 @@ def setup(
|
|||||||
from cassandra.cqlengine import models
|
from cassandra.cqlengine import models
|
||||||
models.DEFAULT_KEYSPACE = default_keyspace
|
models.DEFAULT_KEYSPACE = default_keyspace
|
||||||
|
|
||||||
default_consistency_level = consistency
|
|
||||||
if lazy_connect:
|
if lazy_connect:
|
||||||
kwargs['default_keyspace'] = default_keyspace
|
kwargs['default_keyspace'] = default_keyspace
|
||||||
kwargs['consistency'] = consistency
|
kwargs['consistency'] = consistency
|
||||||
@@ -139,6 +136,8 @@ def setup(
|
|||||||
kwargs['retry_connect'] = retry_connect
|
kwargs['retry_connect'] = retry_connect
|
||||||
lazy_connect_args = (hosts, kwargs)
|
lazy_connect_args = (hosts, kwargs)
|
||||||
raise
|
raise
|
||||||
|
if consistency is not None:
|
||||||
|
session.default_consistency_level = consistency
|
||||||
session.row_factory = dict_factory
|
session.row_factory = dict_factory
|
||||||
|
|
||||||
_register_known_types(cluster)
|
_register_known_types(cluster)
|
||||||
@@ -151,9 +150,6 @@ def execute(query, params=None, consistency_level=None, timeout=NOT_SET):
|
|||||||
if not session:
|
if not session:
|
||||||
raise CQLEngineException("It is required to setup() cqlengine before executing queries")
|
raise CQLEngineException("It is required to setup() cqlengine before executing queries")
|
||||||
|
|
||||||
if consistency_level is None:
|
|
||||||
consistency_level = default_consistency_level
|
|
||||||
|
|
||||||
if isinstance(query, Statement):
|
if isinstance(query, Statement):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
from cassandra import ConsistencyLevel
|
||||||
|
|
||||||
from cassandra.cqlengine import connection
|
from cassandra.cqlengine import connection
|
||||||
from cassandra.cqlengine.management import create_keyspace_simple, CQLENG_ALLOW_SCHEMA_MANAGEMENT
|
from cassandra.cqlengine.management import create_keyspace_simple, CQLENG_ALLOW_SCHEMA_MANAGEMENT
|
||||||
@@ -29,6 +30,7 @@ def setup_package():
|
|||||||
|
|
||||||
keyspace = 'cqlengine_test'
|
keyspace = 'cqlengine_test'
|
||||||
connection.setup(['127.0.0.1'],
|
connection.setup(['127.0.0.1'],
|
||||||
|
consistency=ConsistencyLevel.ONE,
|
||||||
protocol_version=PROTOCOL_VERSION,
|
protocol_version=PROTOCOL_VERSION,
|
||||||
default_keyspace=keyspace)
|
default_keyspace=keyspace)
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
import mock
|
import mock
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from cassandra import ConsistencyLevel as CL
|
from cassandra import ConsistencyLevel as CL, ConsistencyLevel
|
||||||
|
from cassandra.cluster import Session
|
||||||
from cassandra.cqlengine import columns
|
from cassandra.cqlengine import columns
|
||||||
|
from cassandra.cqlengine import connection
|
||||||
from cassandra.cqlengine.management import sync_table, drop_table
|
from cassandra.cqlengine.management import sync_table, drop_table
|
||||||
from cassandra.cqlengine.models import Model
|
from cassandra.cqlengine.models import Model
|
||||||
from cassandra.cqlengine.query import BatchQuery
|
from cassandra.cqlengine.query import BatchQuery
|
||||||
@@ -110,3 +112,12 @@ class TestConsistency(BaseConsistencyTest):
|
|||||||
|
|
||||||
args = m.call_args
|
args = m.call_args
|
||||||
self.assertEqual(CL.ALL, args[0][0].consistency_level)
|
self.assertEqual(CL.ALL, args[0][0].consistency_level)
|
||||||
|
|
||||||
|
def test_default_consistency(self):
|
||||||
|
# verify global assumed default
|
||||||
|
self.assertEqual(Session.default_consistency_level, ConsistencyLevel.LOCAL_QUORUM)
|
||||||
|
|
||||||
|
# verify that this session default is set according to connection.setup
|
||||||
|
# assumes tests/cqlengine/__init__ setup uses CL.ONE
|
||||||
|
session = connection.get_session()
|
||||||
|
self.assertEqual(session.default_consistency_level, ConsistencyLevel.ONE)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ from cassandra.marshal import uint8_pack, uint32_pack, int32_pack
|
|||||||
from cassandra.protocol import (write_stringmultimap, write_int, write_string,
|
from cassandra.protocol import (write_stringmultimap, write_int, write_string,
|
||||||
SupportedMessage, ProtocolHandler)
|
SupportedMessage, ProtocolHandler)
|
||||||
|
|
||||||
import cassandra.cqlengine.connection
|
|
||||||
|
|
||||||
class ConnectionTest(unittest.TestCase):
|
class ConnectionTest(unittest.TestCase):
|
||||||
|
|
||||||
@@ -414,21 +413,3 @@ class ConnectionHeartbeatTest(unittest.TestCase):
|
|||||||
self.assertIsInstance(exc, Exception)
|
self.assertIsInstance(exc, Exception)
|
||||||
self.assertEqual(exc.args, Exception('Connection heartbeat failure').args)
|
self.assertEqual(exc.args, Exception('Connection heartbeat failure').args)
|
||||||
holder.return_connection.assert_has_calls([call(connection)] * get_holders.call_count)
|
holder.return_connection.assert_has_calls([call(connection)] * get_holders.call_count)
|
||||||
|
|
||||||
|
|
||||||
class ConnectionDefaultTest(unittest.TestCase):
|
|
||||||
"""
|
|
||||||
Test to ensure object mapper and base driver default cl's are the same.
|
|
||||||
|
|
||||||
|
|
||||||
@since 3.0.0
|
|
||||||
@jira_ticket PYTHON-416
|
|
||||||
@expected_result cl's matchy between object mapper and base driver.
|
|
||||||
|
|
||||||
@test_category consistency
|
|
||||||
"""
|
|
||||||
def test_default_cl(self, *args):
|
|
||||||
base_driver_cl = Session.default_consistency_level
|
|
||||||
cqlengine_cl = cassandra.cqlengine.connection.default_consistency_level
|
|
||||||
self.assertEqual(base_driver_cl, cqlengine_cl)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user