def test_drop_keyspace(self): "removing a keyspace" conn = init() conn.execute(""" CREATE KEYSPACE Keyspace4Drop WITH strategy_class = SimpleStrategy AND replication_factor = 1 """) # TODO: temporary (until this can be done with CQL). thrift_client.describe_keyspace("Keyspace4Drop") conn.execute('DROP KEYSPACE Keyspace4Drop;') # Technically this should throw a ttypes.NotFound(), but this is # temporary and so not worth requiring it on PYTHONPATH. assert_raises(Exception, thrift_client.describe_keyspace, "Keyspace4Drop")
def test_drop_columnfamily(self): "removing a column family" cursor = init() cursor.execute(""" CREATE KEYSPACE Keyspace4CFDrop WITH strategy_options:replication_factor = '1' AND strategy_class = 'SimpleStrategy'; """) cursor.execute('USE Keyspace4CFDrop;') cursor.execute('CREATE COLUMNFAMILY CF4Drop (KEY varint PRIMARY KEY);') # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("Keyspace4CFDrop") assert len(ksdef.cf_defs), "Column family not created!" cursor.execute('DROP COLUMNFAMILY CF4Drop;') ksdef = thrift_client.describe_keyspace("Keyspace4CFDrop") assert not len(ksdef.cf_defs), "Column family not deleted!"
def test_drop_keyspace(self): "removing a keyspace" cursor = init() cursor.execute(""" CREATE KEYSPACE Keyspace4Drop WITH strategy_options:replication_factor = '1' AND strategy_class = 'SimpleStrategy' """) # TODO: temporary (until this can be done with CQL). thrift_client.describe_keyspace("Keyspace4Drop") cursor.execute('DROP KEYSPACE Keyspace4Drop;') # Technically this should throw a ttypes.NotFound(), but this is # temporary and so not worth requiring it on PYTHONPATH. assert_raises(Exception, thrift_client.describe_keyspace, "Keyspace4Drop")
def test_drop_columnfamily(self): "removing a column family" conn = init() conn.execute(""" CREATE KEYSPACE Keyspace4CFDrop WITH replication_factor = 1 AND strategy_class = 'SimpleStrategy'; """) conn.execute('USE Keyspace4CFDrop;') conn.execute('CREATE COLUMNFAMILY CF4Drop (KEY int PRIMARY KEY);') # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("Keyspace4CFDrop") assert len(ksdef.cf_defs), "Column family not created!" conn.execute('DROP COLUMNFAMILY CF4Drop;') ksdef = thrift_client.describe_keyspace("Keyspace4CFDrop") assert not len(ksdef.cf_defs), "Column family not deleted!"
def test_create_keyspace(self): "create a new keyspace" cursor = init() cursor.execute(""" CREATE KEYSPACE TestKeyspace42 WITH strategy_options:DC1 = '1' AND strategy_class = 'NetworkTopologyStrategy' """) # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("TestKeyspace42") strategy_class = "org.apache.cassandra.locator.NetworkTopologyStrategy" assert ksdef.strategy_class == strategy_class assert ksdef.strategy_options['DC1'] == "1"
def test_create_keyspace(self): "create a new keyspace" init().execute(""" CREATE KEYSPACE TestKeyspace42 WITH strategy_options:DC1 = '1' AND strategy_class = 'SimpleStrategy' AND replication_factor = 3 """) # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("TestKeyspace42") assert ksdef.replication_factor == 3 strategy_class = "org.apache.cassandra.locator.SimpleStrategy" assert ksdef.strategy_class == strategy_class assert ksdef.strategy_options['DC1'] == "1"
def test_create_indexs(self): "creating column indexes" conn = init() conn.execute("USE Keyspace1") conn.execute("CREATE COLUMNFAMILY CreateIndex1 (KEY utf8 PRIMARY KEY)") conn.execute("CREATE INDEX namedIndex ON CreateIndex1 (items)") conn.execute("CREATE INDEX ON CreateIndex1 (stuff)") # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("Keyspace1") cfam = [i for i in ksdef.cf_defs if i.name == "CreateIndex1"][0] items = [i for i in cfam.column_metadata if i.name == "items"][0] stuff = [i for i in cfam.column_metadata if i.name == "stuff"][0] assert items.index_name == "namedIndex", "missing index (or name)" assert items.index_type == 0, "missing index" assert not stuff.index_name, \ "index_name should be unset, not %s" % stuff.index_name assert stuff.index_type == 0, "missing index" # already indexed assert_raises(CQLException, conn.execute, "CREATE INDEX ON CreateIndex1 (stuff)")
def test_create_indexs(self): "creating column indexes" cursor = init() cursor.execute("USE Keyspace1") cursor.execute("CREATE COLUMNFAMILY CreateIndex1 (KEY text PRIMARY KEY)") cursor.execute("CREATE INDEX namedIndex ON CreateIndex1 (items)") cursor.execute("CREATE INDEX ON CreateIndex1 (stuff)") # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("Keyspace1") cfam = [i for i in ksdef.cf_defs if i.name == "CreateIndex1"][0] items = [i for i in cfam.column_metadata if i.name == "items"][0] stuff = [i for i in cfam.column_metadata if i.name == "stuff"][0] assert items.index_name == "namedIndex", "missing index (or name)" assert items.index_type == 0, "missing index" assert not stuff.index_name, \ "index_name should be unset, not %s" % stuff.index_name assert stuff.index_type == 0, "missing index" # already indexed assert_raises(cql.ProgrammingError, cursor.execute, "CREATE INDEX ON CreateIndex1 (stuff)")
def test_create_column_family(self): "create a new column family" cursor = init() cursor.execute(""" CREATE KEYSPACE CreateCFKeyspace WITH strategy_options:replication_factor = '1' AND strategy_class = 'SimpleStrategy'; """) cursor.execute("USE CreateCFKeyspace;") cursor.execute(""" CREATE COLUMNFAMILY NewCf1 ( KEY varint PRIMARY KEY, 'username' text, 'age' varint, 'birthdate' bigint, 'id' uuid ) WITH comment = 'shiny, new, cf' AND default_validation = ascii; """) # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 1, \ "expected 1 column family total, found %d" % len(ksdef.cf_defs) cfam= ksdef.cf_defs[0] assert len(cfam.column_metadata) == 4, \ "expected 4 columns, found %d" % len(cfam.column_metadata) assert cfam.comment == "shiny, new, cf" assert cfam.default_validation_class == "org.apache.cassandra.db.marshal.AsciiType" assert cfam.comparator_type == "org.apache.cassandra.db.marshal.UTF8Type" assert cfam.key_validation_class == "org.apache.cassandra.db.marshal.IntegerType" # Missing primary key assert_raises(cql.ProgrammingError, cursor.execute, "CREATE COLUMNFAMILY NewCf2") # Too many primary keys assert_raises(cql.ProgrammingError, cursor.execute, """CREATE COLUMNFAMILY NewCf2 (KEY varint PRIMARY KEY, KEY text PRIMARY KEY)""") # No column defs cursor.execute("""CREATE COLUMNFAMILY NewCf3 (KEY varint PRIMARY KEY) WITH comparator = bigint""") ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 2, \ "expected 3 column families total, found %d" % len(ksdef.cf_defs) cfam = [i for i in ksdef.cf_defs if i.name == "NewCf3"][0] assert cfam.comparator_type == "org.apache.cassandra.db.marshal.LongType" # Column defs, defaults otherwise cursor.execute("""CREATE COLUMNFAMILY NewCf4 (KEY varint PRIMARY KEY, 'a' varint, 'b' varint) WITH comparator = text;""") ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 3, \ "expected 4 column families total, found %d" % len(ksdef.cf_defs) cfam = [i for i in ksdef.cf_defs if i.name == "NewCf4"][0] assert len(cfam.column_metadata) == 2, \ "expected 2 columns, found %d" % len(cfam.column_metadata) for coldef in cfam.column_metadata: assert coldef.name in ("a", "b"), "Unknown column name " + coldef.name assert coldef.validation_class.endswith("marshal.IntegerType")
def test_create_column_family(self): "create a new column family" conn = init() conn.execute(""" CREATE KEYSPACE CreateCFKeyspace WITH replication_factor = 1 AND strategy_class = 'SimpleStrategy'; """) conn.execute("USE CreateCFKeyspace;") conn.execute(""" CREATE COLUMNFAMILY NewCf1 ( KEY int PRIMARY KEY, 'username' utf8, 'age' int, 'birthdate' long, 'id' uuid ) WITH comparator = utf8 AND comment = 'shiny, new, cf' AND default_validation = ascii; """) # TODO: temporary (until this can be done with CQL). ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 1, \ "expected 1 column family total, found %d" % len(ksdef.cf_defs) cfam = ksdef.cf_defs[0] assert len(cfam.column_metadata) == 4, \ "expected 4 columns, found %d" % len(cfam.column_metadata) assert cfam.comment == "shiny, new, cf" assert cfam.default_validation_class == "org.apache.cassandra.db.marshal.AsciiType" assert cfam.comparator_type == "org.apache.cassandra.db.marshal.UTF8Type" assert cfam.key_validation_class == "org.apache.cassandra.db.marshal.IntegerType" # Missing primary key assert_raises(CQLException, conn.execute, "CREATE COLUMNFAMILY NewCf2") # Too many primary keys assert_raises( CQLException, conn.execute, """CREATE COLUMNFAMILY NewCf2 (KEY int PRIMARY KEY, KEY utf8 PRIMARY KEY)""") # No column defs conn.execute("""CREATE COLUMNFAMILY NewCf3 (KEY int PRIMARY KEY) WITH comparator = long""") ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 2, \ "expected 3 column families total, found %d" % len(ksdef.cf_defs) cfam = [i for i in ksdef.cf_defs if i.name == "NewCf3"][0] assert cfam.comparator_type == "org.apache.cassandra.db.marshal.LongType" # Column defs, defaults otherwise conn.execute("""CREATE COLUMNFAMILY NewCf4 (KEY int PRIMARY KEY, 'a' int, 'b' int);""") ksdef = thrift_client.describe_keyspace("CreateCFKeyspace") assert len(ksdef.cf_defs) == 3, \ "expected 4 column families total, found %d" % len(ksdef.cf_defs) cfam = [i for i in ksdef.cf_defs if i.name == "NewCf4"][0] assert len(cfam.column_metadata) == 2, \ "expected 2 columns, found %d" % len(cfam.column_metadata) for coldef in cfam.column_metadata: assert coldef.name in ("a", "b"), "Unknown column name" assert coldef.validation_class.endswith("marshal.IntegerType")