本文整理汇总了Python中cassandra.cluster.Cluster.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.shutdown方法的具体用法?Python Cluster.shutdown怎么用?Python Cluster.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: teardown_class
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def teardown_class(cls):
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
try:
session.execute("DROP KEYSPACE %s" % cls.ksname)
finally:
cluster.shutdown()
示例2: test_pool_management
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_pool_management(self):
# Ensure that in_flight and request_ids quiesce after cluster operations
cluster = Cluster(protocol_version=PROTOCOL_VERSION, idle_heartbeat_interval=0) # no idle heartbeat here, pool management is tested in test_idle_heartbeat
session = cluster.connect()
session2 = cluster.connect()
# prepare
p = session.prepare("SELECT * FROM system.local WHERE key=?")
self.assertTrue(session.execute(p, ('local',)))
# simple
self.assertTrue(session.execute("SELECT * FROM system.local WHERE key='local'"))
# set keyspace
session.set_keyspace('system')
session.set_keyspace('system_traces')
# use keyspace
session.execute('USE system')
session.execute('USE system_traces')
# refresh schema
cluster.refresh_schema_metadata()
cluster.refresh_schema_metadata(max_schema_agreement_wait=0)
# submit schema refresh
future = cluster.submit_schema_refresh()
future.result()
assert_quiescent_pool_state(self, cluster)
cluster.shutdown()
示例3: handle_noargs
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def handle_noargs(self, **options):
cluster = Cluster()
session = cluster.connect()
# Checking if keysapce exists
query = "SELECT * FROM system.schema_keyspaces WHERE keyspace_name='%s';" % KEYSPACE_NAME
result = session.execute(query)
if len(result) != 0:
msg = 'Looks like you already have a %s keyspace.\nDo you want to delete it and recreate it? All current data will be deleted! (y/n): ' % KEYSPACE_NAME
resp = raw_input(msg)
if not resp or resp[0] != 'y':
print "Ok, then we're done here."
return
query = "DROP KEYSPACE %s" % KEYSPACE_NAME
session.execute(query)
# Creating keysapce
query = "CREATE KEYSPACE tess WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};"
session.execute(query)
# Creating tables
query = "USE tess;"
session.execute(query)
query = "CREATE TABLE emotiv_eeg_record (test_id int, time double, AF3 double, F7 double, F3 double, FC5 double, T7 double, P7 double, O1 double, O2 double, P8 double, T8 double, FC6 double, F4 double, F8 double, AF4 double, PRIMARY KEY (test_id, time));"
session.execute(query)
cluster.shutdown()
print 'All done!'
示例4: test_session_no_cluster
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_session_no_cluster(self):
"""
Test session context without cluster context.
@since 3.4
@jira_ticket PYTHON-521
@expected_result session should be created correctly. Session should shutdown correctly outside of context
@test_category configuration
"""
cluster = Cluster(**self.cluster_kwargs)
unmanaged_session = cluster.connect()
with cluster.connect() as session:
self.assertFalse(cluster.is_shutdown)
self.assertFalse(session.is_shutdown)
self.assertFalse(unmanaged_session.is_shutdown)
self.assertTrue(session.execute('select release_version from system.local')[0])
self.assertTrue(session.is_shutdown)
self.assertFalse(cluster.is_shutdown)
self.assertFalse(unmanaged_session.is_shutdown)
unmanaged_session.shutdown()
self.assertTrue(unmanaged_session.is_shutdown)
self.assertFalse(cluster.is_shutdown)
cluster.shutdown()
self.assertTrue(cluster.is_shutdown)
示例5: test_connect_to_already_shutdown_cluster
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_connect_to_already_shutdown_cluster(self):
"""
Ensure you cannot connect to a cluster that's been shutdown
"""
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
cluster.shutdown()
self.assertRaises(Exception, cluster.connect)
示例6: test_can_insert_tuples_all_primitive_datatypes
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_can_insert_tuples_all_primitive_datatypes(self):
"""
Ensure tuple subtypes are appropriately handled.
"""
if self.cass_version < (2, 1, 0):
raise unittest.SkipTest("The tuple type was introduced in Cassandra 2.1")
c = Cluster(protocol_version=PROTOCOL_VERSION)
s = c.connect(self.keyspace_name)
s.encoder.mapping[tuple] = s.encoder.cql_encode_tuple
s.execute("CREATE TABLE tuple_primitive ("
"k int PRIMARY KEY, "
"v frozen<tuple<%s>>)" % ','.join(PRIMITIVE_DATATYPES))
values = []
type_count = len(PRIMITIVE_DATATYPES)
for i, data_type in enumerate(PRIMITIVE_DATATYPES):
# create tuples to be written and ensure they match with the expected response
# responses have trailing None values for every element that has not been written
values.append(get_sample(data_type))
expected = tuple(values + [None] * (type_count - len(values)))
s.execute("INSERT INTO tuple_primitive (k, v) VALUES (%s, %s)", (i, tuple(values)))
result = s.execute("SELECT v FROM tuple_primitive WHERE k=%s", (i,))[0]
self.assertEqual(result.v, expected)
c.shutdown()
示例7: setup
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def setup(hosts):
log.info("Using 'cassandra' package from %s", cassandra.__path__)
cluster = Cluster(hosts)
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
try:
session = cluster.connect()
log.debug("Creating keyspace...")
session.execute("""
CREATE KEYSPACE %s
WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '2' }
""" % KEYSPACE)
log.debug("Setting keyspace...")
session.set_keyspace(KEYSPACE)
log.debug("Creating table...")
session.execute("""
CREATE TABLE %s (
thekey text,
col1 text,
col2 text,
PRIMARY KEY (thekey, col1)
)
""" % TABLE)
finally:
cluster.shutdown()
示例8: test_white_list
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_white_list(self):
use_singledc()
keyspace = 'test_white_list'
cluster = Cluster(('127.0.0.2',), load_balancing_policy=WhiteListRoundRobinPolicy((IP_FORMAT % 2,)),
protocol_version=PROTOCOL_VERSION, topology_event_refresh_window=0,
status_event_refresh_window=0)
session = cluster.connect()
self._wait_for_nodes_up([1, 2, 3])
create_schema(cluster, session, keyspace)
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 12)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
# white list policy should not allow reconnecting to ignored hosts
force_stop(3)
self._wait_for_nodes_down([3])
self.assertFalse(cluster.metadata._hosts[IP_FORMAT % 3].is_currently_reconnecting())
self.coordinator_stats.reset_counts()
force_stop(2)
self._wait_for_nodes_down([2])
try:
self._query(session, keyspace)
self.fail()
except NoHostAvailable:
pass
cluster.shutdown()
示例9: test_can_insert_udts_with_nulls
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_can_insert_udts_with_nulls(self):
"""
Test the insertion of UDTs with null and empty string fields
"""
c = Cluster(protocol_version=PROTOCOL_VERSION)
s = c.connect(self.keyspace_name, wait_for_all_pools=True)
s.execute("CREATE TYPE user (a text, b int, c uuid, d blob)")
User = namedtuple('user', ('a', 'b', 'c', 'd'))
c.register_user_type(self.keyspace_name, "user", User)
s.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)")
insert = s.prepare("INSERT INTO mytable (a, b) VALUES (0, ?)")
s.execute(insert, [User(None, None, None, None)])
results = s.execute("SELECT b FROM mytable WHERE a=0")
self.assertEqual((None, None, None, None), results[0].b)
select = s.prepare("SELECT b FROM mytable WHERE a=0")
self.assertEqual((None, None, None, None), s.execute(select)[0].b)
# also test empty strings
s.execute(insert, [User('', None, None, six.binary_type())])
results = s.execute("SELECT b FROM mytable WHERE a=0")
self.assertEqual(('', None, None, six.binary_type()), results[0].b)
c.shutdown()
示例10: step
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def step(self):
# Connect to Cassandra
cluster = Cluster(['192.168.3.2'],
port= 9042)
session = cluster.connect()
# Link to kafka
consumer = KafkaConsumer('observation-persist',
bootstrap_servers="192.168.3.5:9092")
# Process observations
for msg in consumer:
split_msg = string.split(msg.value,"::")
if(len(split_msg) == 16) :
session.execute(
"""
INSERT INTO observation.observations_numeric (feature, procedure, observableproperty,
year, month, phenomenontimestart, phenomenontimeend, value, quality, accuracy, status,
processing, uncertml, comment, location, parameters)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""",
(split_msg[0],split_msg[1],split_msg[2],int(split_msg[3]),int(split_msg[4]),int(split_msg[5]),int(split_msg[6]),
float(split_msg[7]),split_msg[8],float(split_msg[9]),split_msg[10],split_msg[11],split_msg[12],
split_msg[13],split_msg[14],split_msg[15])
)
# Close link to kafka
consumer.close()
cluster.shutdown()
示例11: test_udts_with_nulls
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_udts_with_nulls(self):
"""
Test UDTs with null and empty string fields.
"""
c = Cluster(protocol_version=PROTOCOL_VERSION)
s = c.connect()
s.execute("""
CREATE KEYSPACE test_udts_with_nulls
WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }
""")
s.set_keyspace("test_udts_with_nulls")
s.execute("CREATE TYPE user (a text, b int, c uuid, d blob)")
User = namedtuple('user', ('a', 'b', 'c', 'd'))
c.register_user_type("test_udts_with_nulls", "user", User)
s.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)")
insert = s.prepare("INSERT INTO mytable (a, b) VALUES (0, ?)")
s.execute(insert, [User(None, None, None, None)])
results = s.execute("SELECT b FROM mytable WHERE a=0")
self.assertEqual((None, None, None, None), results[0].b)
select = s.prepare("SELECT b FROM mytable WHERE a=0")
self.assertEqual((None, None, None, None), s.execute(select)[0].b)
# also test empty strings
s.execute(insert, [User('', None, None, '')])
results = s.execute("SELECT b FROM mytable WHERE a=0")
self.assertEqual(('', None, None, ''), results[0].b)
self.assertEqual(('', None, None, ''), s.execute(select)[0].b)
c.shutdown()
示例12: insert_rows
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def insert_rows(starting_partition, ending_partition, rows_per_partition, counter, counter_lock):
cluster = Cluster(['127.0.0.1'], load_balancing_policy=TokenAwarePolicy(RoundRobinPolicy()))
try:
session = cluster.connect('ks')
try:
statement = session.prepare('INSERT INTO tbl (a, b, c, d) VALUES (?, ?, ?, ?)')
for partition_key in xrange(starting_partition, ending_partition):
batch = None
batch_size = 0
for cluster_column in xrange(rows_per_partition):
if batch is None:
batch = BatchStatement(batch_type=BatchType.UNLOGGED)
value1 = random.randint(1, 1000000)
value2 = random.randint(1, 1000000)
batch.add(statement, [partition_key, cluster_column, value1, value2])
batch_size += 1
if (batch_size == MAX_BATCH_SIZE) or (cluster_column + 1 == rows_per_partition):
with counter_lock:
counter.value += batch_size
session.execute(batch)
batch = None
batch_size = 0
finally:
session.shutdown()
finally:
cluster.shutdown()
示例13: validate_ssl_options
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def validate_ssl_options(ssl_options):
# find absolute path to client CA_CERTS
tries = 0
while True:
if tries > 5:
raise RuntimeError("Failed to connect to SSL cluster after 5 attempts")
try:
cluster = Cluster(protocol_version=PROTOCOL_VERSION, ssl_options=ssl_options)
session = cluster.connect()
break
except Exception:
ex_type, ex, tb = sys.exc_info()
log.warn("{0}: {1} Backtrace: {2}".format(ex_type.__name__, ex, traceback.extract_tb(tb)))
del tb
tries += 1
# attempt a few simple commands.
insert_keyspace = """CREATE KEYSPACE ssltest
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}
"""
statement = SimpleStatement(insert_keyspace)
statement.consistency_level = 3
session.execute(statement)
drop_keyspace = "DROP KEYSPACE ssltest"
statement = SimpleStatement(drop_keyspace)
statement.consistency_level = ConsistencyLevel.ANY
session.execute(statement)
cluster.shutdown()
示例14: test_cannot_connect_with_bad_client_auth
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_cannot_connect_with_bad_client_auth(self):
"""
Test to validate that we cannot connect with invalid client auth.
This test will use bad keys/certs to preform client authentication. It will then attempt to connect
to a server that has client authentication enabled.
@since 2.7.0
@expected_result The client will throw an exception on connect
@test_category connection:ssl
"""
# Setup absolute paths to key/cert files
abs_path_ca_cert_path = os.path.abspath(CLIENT_CA_CERTS)
abs_driver_keyfile = os.path.abspath(DRIVER_KEYFILE)
abs_driver_certfile = os.path.abspath(DRIVER_CERTFILE_BAD)
cluster = Cluster(protocol_version=PROTOCOL_VERSION, ssl_options={'ca_certs': abs_path_ca_cert_path,
'ssl_version': ssl.PROTOCOL_TLSv1,
'keyfile': abs_driver_keyfile,
'certfile': abs_driver_certfile})
with self.assertRaises(NoHostAvailable) as context:
cluster.connect()
cluster.shutdown()
示例15: test_raise_error_on_prepared_statement_execution_dropped_table
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import shutdown [as 别名]
def test_raise_error_on_prepared_statement_execution_dropped_table(self):
"""
test for error in executing prepared statement on a dropped table
test_raise_error_on_execute_prepared_statement_dropped_table tests that an InvalidRequest is raised when a
prepared statement is executed after its corresponding table is dropped. This happens because if a prepared
statement is invalid, the driver attempts to automatically re-prepare it on a non-existing table.
@expected_errors InvalidRequest If a prepared statement is executed on a dropped table
@since 2.6.0
@jira_ticket PYTHON-207
@expected_result InvalidRequest error should be raised upon prepared statement execution.
@test_category prepared_statements
"""
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
session = cluster.connect("test3rf")
session.execute("CREATE TABLE error_test (k int PRIMARY KEY, v int)")
prepared = session.prepare("SELECT * FROM error_test WHERE k=?")
session.execute("DROP TABLE error_test")
with self.assertRaises(InvalidRequest):
session.execute(prepared, [0])
cluster.shutdown()