def setUp(self): db.merge_conn( Connection(conn_id='cassandra_test', conn_type='cassandra', host='host-1,host-2', port='9042', schema='test_keyspace', extra='{"load_balancing_policy":"TokenAwarePolicy"}')) db.merge_conn( Connection(conn_id='cassandra_default_with_schema', conn_type='cassandra', host='cassandra', port='9042', schema='s')) hook = CassandraHook("cassandra_default") session = hook.get_conn() cqls = [ "DROP SCHEMA IF EXISTS s", """ CREATE SCHEMA s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 } """, ] for cql in cqls: session.execute(cql) session.shutdown() hook.shutdown_cluster()
def setUp(self): configuration.load_test_config() db.merge_conn( models.Connection( conn_id='cassandra_test', conn_type='cassandra', host='host-1,host-2', port='9042', schema='test_keyspace', extra='{"load_balancing_policy":"TokenAwarePolicy"}')) db.merge_conn( models.Connection( conn_id='cassandra_default_with_schema', conn_type='cassandra', host='cassandra', port='9042', schema='s')) hook = CassandraHook("cassandra_default") session = hook.get_conn() cqls = [ "DROP SCHEMA IF EXISTS s", """ CREATE SCHEMA s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 } """, ] for cql in cqls: session.execute(cql) session.shutdown() hook.shutdown_cluster()
def test_table_exists_with_keyspace_from_session(self): hook = CassandraHook("cassandra_default_with_schema") session = hook.get_conn() cqls = [ "DROP TABLE IF EXISTS t", "CREATE TABLE t (pk1 text PRIMARY KEY)", ] for cql in cqls: session.execute(cql) self.assertTrue(hook.table_exists("t")) self.assertFalse(hook.table_exists("u")) session.shutdown() hook.shutdown_cluster()
def test_record_exists_with_keyspace_from_session(self): hook = CassandraHook("cassandra_default_with_schema") session = hook.get_conn() cqls = [ "DROP TABLE IF EXISTS t", "CREATE TABLE t (pk1 text, pk2 text, c text, PRIMARY KEY (pk1, pk2))", "INSERT INTO t (pk1, pk2, c) VALUES ('foo', 'bar', 'baz')", ] for cql in cqls: session.execute(cql) self.assertTrue(hook.record_exists("t", {"pk1": "foo", "pk2": "bar"})) self.assertFalse(hook.record_exists("t", {"pk1": "foo", "pk2": "baz"})) session.shutdown() hook.shutdown_cluster()