Exemplo n.º 1
0
    def test_all_size_tiered_options(self):
        class AllSizeTieredOptionsModel(Model):
            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "SizeTieredCompactionStrategy"),
                    "bucket_low":
                    ".3",
                    "bucket_high":
                    "2",
                    "min_threshold":
                    "2",
                    "max_threshold":
                    "64",
                    "tombstone_compaction_interval":
                    "86400",
                }
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllSizeTieredOptionsModel)
        sync_table(self.conn, AllSizeTieredOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllSizeTieredOptionsModel)
        self._verify_options(table_meta, AllSizeTieredOptionsModel.__options__)
Exemplo n.º 2
0
 def setUpClass(cls):
     super(TestUpdating, cls).setUpClass()
     conn = cls.connection()
     drop_table(conn, TestModelSave)
     drop_table(conn, TestMultiKeyModel)
     sync_table(conn, TestModelSave)
     sync_table(conn, TestMultiKeyModel)
    def test_compaction_not_altered_without_changes_sizetiered(self):
        class SizeTieredCompactionChangesDetectionTest(Model):

            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'SizeTieredCompactionStrategy'),
                    'bucket_high':
                    '20',
                    'bucket_low':
                    '10',
                    'max_threshold':
                    '200',
                    'min_threshold':
                    '100',
                    'min_sstable_size':
                    '1000',
                    'tombstone_threshold':
                    '0.125',
                    'tombstone_compaction_interval':
                    '3600',
                },
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, SizeTieredCompactionChangesDetectionTest)
        sync_table(self.conn, SizeTieredCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(
                self.conn,
                SizeTieredCompactionChangesDetectionTest,
            ))
Exemplo n.º 4
0
 def test_extra_field(self):
     drop_table(self.conn, self.TestModel)
     sync_table(self.conn, self.TestModel)
     self.TestModel.create(self.conn)
     self.conn.execute("ALTER TABLE {0} add blah int".format(
         self.TestModel.column_family_name()))
     self.TestModel.objects().find_all(self.conn)
    def test_all_size_tiered_options(self):
        class AllSizeTieredOptionsModel(Model):
            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'SizeTieredCompactionStrategy'),
                    'bucket_low':
                    '.3',
                    'bucket_high':
                    '2',
                    'min_threshold':
                    '2',
                    'max_threshold':
                    '64',
                    'tombstone_compaction_interval':
                    '86400',
                },
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllSizeTieredOptionsModel)
        sync_table(self.conn, AllSizeTieredOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllSizeTieredOptionsModel)
        self._verify_options(
            table_meta,
            AllSizeTieredOptionsModel.__options__,
        )
Exemplo n.º 6
0
    def test_compaction_not_altered_without_changes_sizetiered(self):
        class SizeTieredCompactionChangesDetectionTest(Model):

            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "SizeTieredCompactionStrategy"),
                    "bucket_high":
                    "20",
                    "bucket_low":
                    "10",
                    "max_threshold":
                    "200",
                    "min_threshold":
                    "100",
                    "min_sstable_size":
                    "1000",
                    "tombstone_threshold":
                    "0.125",
                    "tombstone_compaction_interval":
                    "3600",
                }
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, SizeTieredCompactionChangesDetectionTest)
        sync_table(self.conn, SizeTieredCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(self.conn,
                            SizeTieredCompactionChangesDetectionTest))
Exemplo n.º 7
0
    def test_compaction_not_altered_without_changes_leveled(self):

        class LeveledCompactionChangesDetectionTest(Model):

            __options__ = {
                'compaction': {
                    'class': (
                        'org.apache.cassandra.db.compaction.'
                        'LeveledCompactionStrategy'
                    ),
                    'sstable_size_in_mb': '160',
                    'tombstone_threshold': '0.125',
                    'tombstone_compaction_interval': '3600',
                },
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, LeveledCompactionChangesDetectionTest)
        sync_table(self.conn, LeveledCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(
                self.conn,
                LeveledCompactionChangesDetectionTest
            )
        )
    def test_alter_options(self):
        class AlterTable(Model):

            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'LeveledCompactionStrategy'),
                    'sstable_size_in_mb':
                    '64',
                },
            }
            user_id = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AlterTable)
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(
            table_meta.export_as_string(),
            ".*'sstable_size_in_mb': '64'.*",
        )
        AlterTable.__options__['compaction']['sstable_size_in_mb'] = '128'
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(
            table_meta.export_as_string(),
            ".*'sstable_size_in_mb': '128'.*",
        )
Exemplo n.º 9
0
    def test_model_over_write(self):
        """
        Test to ensure overwriting of primary keys in model inheritance is
        allowed

        This is currently only an issue in PyPy. When PYTHON-504 is
        introduced this should be updated error out and warn the user

        @since 3.6.0
        @jira_ticket PYTHON-576
        @expected_result primary keys can be overwritten via inheritance

        @test_category object_mapper
        """
        class TimeModelBase(Model):
            uuid = columns.TimeUUID(primary_key=True)

        class DerivedTimeModel(TimeModelBase):
            __table_name__ = "derived_time"
            uuid = columns.TimeUUID(primary_key=True, partition_key=True)
            value = columns.Text(required=False)

        # In case the table already exists in keyspace
        drop_table(self.conn, DerivedTimeModel)

        sync_table(self.conn, DerivedTimeModel)
        uuid_value = uuid1()
        uuid_value2 = uuid1()
        DerivedTimeModel.create(self.conn, uuid=uuid_value, value="first")
        DerivedTimeModel.create(self.conn, uuid=uuid_value2, value="second")
        DerivedTimeModel.objects.filter(uuid=uuid_value)
Exemplo n.º 10
0
    def test_static_columns(self):
        if PROTOCOL_VERSION < 2:
            raise unittest.SkipTest(
                "Native protocol 2+ required, currently using: {0}".format(PROTOCOL_VERSION)
            )

        class StaticModel(Model):
            id = columns.Integer(primary_key=True)
            c = columns.Integer(primary_key=True)
            name = columns.Text(static=True)

        drop_table(self.conn, StaticModel)

        session = self.conn.session

        with mock.patch.object(session, "execute", wraps=session.execute) as m:
            sync_table(self.conn, StaticModel)

        self.assertGreater(m.call_count, 0)
        statement = m.call_args[0][0].query_string
        self.assertIn('"name" text static', statement)

        # if we sync again, we should not apply an alter w/ a static
        sync_table(self.conn, StaticModel)

        with mock.patch.object(session, "execute", wraps=session.execute) as m2:
            sync_table(self.conn, StaticModel)

        self.assertEqual(len(m2.call_args_list), 0)
Exemplo n.º 11
0
    def test_table_definition(self):
        """ Tests that creating a table with capitalized column names succeeds """
        sync_table(self.conn, LowercaseKeyModel)
        sync_table(self.conn, CapitalizedKeyModel)

        drop_table(self.conn, LowercaseKeyModel)
        drop_table(self.conn, CapitalizedKeyModel)
 def setUpClass(cls):
     # Skip annotations don't seem to skip class level teradown and setup
     # methods
     super(TestNestedType, cls).setUpClass()
     if CASSANDRA_VERSION >= "2.1":
         conn = cls.connection()
         drop_table(conn, TestNestedModel)
         sync_table(conn, TestNestedModel)
Exemplo n.º 13
0
    def setUpClass(cls):
        if PROTOCOL_VERSION < 4:
            return

        super(TestQuerying, cls).setUpClass()
        conn = cls.connection()
        drop_table(conn, TestQueryModel)
        sync_table(conn, TestQueryModel)
Exemplo n.º 14
0
    def test_keywords_as_names(self):
        """
        Test for CQL keywords as names

        test_keywords_as_names tests that CQL keywords are properly and
        automatically quoted in cqlengine. It creates a keyspace, keyspace,
        which should be automatically quoted to "keyspace" in CQL. It then
        creates a table, table, which should also be automatically quoted to
        "table". It then verfies that operations can be done on the
        "keyspace"."table" which has been created. It also verifies that table
        alternations work and operations can be performed on the altered table.

        @since 2.6.0
        @jira_ticket PYTHON-244
        @expected_result Cqlengine should quote CQL keywords properly when
        creating keyspaces and tables.

        @test_category schema:generation
        """

        # If the keyspace exists, it will not be re-created
        create_keyspace_simple(self.conn, "keyspace", 1)
        k_conn = self.connection("keyspace")

        class table(Model):
            select = columns.Integer(primary_key=True)
            table = columns.Text()

        # In case the table already exists in keyspace
        drop_table(k_conn, table)

        # Create should work
        sync_table(k_conn, table)

        created = table.create(k_conn, select=0, table="table")
        selected = table.objects(select=0).first(k_conn)
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)

        # Alter should work
        class table(Model):
            select = columns.Integer(primary_key=True)
            table = columns.Text()
            where = columns.Text()

        sync_table(k_conn, table)

        created = table.create(k_conn, select=1, table="table")
        selected = table.objects(select=1).first(k_conn)
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)
        self.assertEqual(created.where, selected.where)

        drop_keyspace(self.conn, "keyspace")
        del k_conn
Exemplo n.º 15
0
    def test_alter_actually_alters(self):
        tmp = copy.deepcopy(LeveledCompactionTestTable)
        drop_table(self.conn, tmp)
        sync_table(self.conn, tmp)
        tmp.__options__ = {
            "compaction": {
                "class": ("org.apache.cassandra.db.compaction."
                          "SizeTieredCompactionStrategy")
            }
        }
        sync_table(self.conn, tmp)

        table_meta = _get_table_metadata(self.conn, tmp)

        self.assertRegexpMatches(table_meta.export_as_string(),
                                 ".*SizeTieredCompactionStrategy.*")
Exemplo n.º 16
0
    def test_alter_actually_alters(self):
        tmp = copy.deepcopy(LeveledCompactionTestTable)
        drop_table(self.conn, tmp)
        sync_table(self.conn, tmp)
        tmp.__options__ = {
            'compaction': {
                'class': ('org.apache.cassandra.db.compaction.'
                          'SizeTieredCompactionStrategy'),
            },
        }
        sync_table(self.conn, tmp)

        table_meta = _get_table_metadata(self.conn, tmp)

        self.assertRegexpMatches(table_meta.export_as_string(),
                                 '.*SizeTieredCompactionStrategy.*')
Exemplo n.º 17
0
    def test_clustering_order_more_complex(self):
        """
        Tests that models can be saved and retrieved
        """
        sync_table(self.conn, TestClusteringComplexModel)

        items = list(range(20))
        random.shuffle(items)
        for i in items:
            TestClusteringComplexModel.create(self.conn, id=1, clustering_key=i, some_value=2)

        values = list(
            TestClusteringComplexModel.objects.values_list("some_value", flat=True).iter(self.conn)
        )

        self.assertEqual([2] * 20, values)
        drop_table(self.conn, TestClusteringComplexModel)
Exemplo n.º 18
0
    def test_all_leveled_options(self):
        class AllLeveledOptionsModel(Model):
            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "LeveledCompactionStrategy"),
                    "sstable_size_in_mb":
                    "64",
                }
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllLeveledOptionsModel)
        sync_table(self.conn, AllLeveledOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllLeveledOptionsModel)
        self._verify_options(table_meta, AllLeveledOptionsModel.__options__)
    def test_concrete_class_table_creation_cycle(self):
        """
        Tests that models with inherited abstract classes can be created, and
        have io performed
        """
        from cqlmapper.management import sync_table, drop_table
        sync_table(self.conn, ConcreteModelWithCol)

        w1 = ConcreteModelWithCol.create(self.conn, pkey=5, data=6)
        w2 = ConcreteModelWithCol.create(self.conn, pkey=6, data=7)

        r1 = ConcreteModelWithCol.get(self.conn, pkey=5)
        r2 = ConcreteModelWithCol.get(self.conn, pkey=6)

        assert w1.pkey == r1.pkey
        assert w1.data == r1.data
        assert w2.pkey == r2.pkey
        assert w2.data == r2.data

        drop_table(self.conn, ConcreteModelWithCol)
Exemplo n.º 20
0
    def test_all_leveled_options(self):
        class AllLeveledOptionsModel(Model):
            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'LeveledCompactionStrategy'),
                    'sstable_size_in_mb':
                    '64'
                },
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllLeveledOptionsModel)
        sync_table(self.conn, AllLeveledOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllLeveledOptionsModel)
        self._verify_options(
            table_meta,
            AllLeveledOptionsModel.__options__,
        )
Exemplo n.º 21
0
    def test_compaction_not_altered_without_changes_leveled(self):
        class LeveledCompactionChangesDetectionTest(Model):

            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "LeveledCompactionStrategy"),
                    "sstable_size_in_mb":
                    "160",
                    "tombstone_threshold":
                    "0.125",
                    "tombstone_compaction_interval":
                    "3600",
                }
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, LeveledCompactionChangesDetectionTest)
        sync_table(self.conn, LeveledCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(self.conn, LeveledCompactionChangesDetectionTest))
Exemplo n.º 22
0
    def test_alter_options(self):
        class AlterTable(Model):

            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "LeveledCompactionStrategy"),
                    "sstable_size_in_mb":
                    "64",
                }
            }
            user_id = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AlterTable)
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(table_meta.export_as_string(),
                                 ".*'sstable_size_in_mb': '64'.*")
        AlterTable.__options__["compaction"]["sstable_size_in_mb"] = "128"
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(table_meta.export_as_string(),
                                 ".*'sstable_size_in_mb': '128'.*")
Exemplo n.º 23
0
 def tearDownClass(cls):
     super(BaseColumnIOTest, cls).tearDownClass()
     if not cls.column:
         return
     drop_table(cls.connection(), cls._generated_model)
Exemplo n.º 24
0
 def test_alter_is_called_table(self):
     drop_table(self.conn, LeveledCompactionTestTable)
     sync_table(self.conn, LeveledCompactionTestTable)
     with patch("cqlmapper.management._update_options") as mock:
         sync_table(self.conn, LeveledCompactionTestTable)
     assert mock.called == 1
Exemplo n.º 25
0
 def tearDownClass(cls):
     super(BaseTTLTest, cls).tearDownClass()
     drop_table(cls.connection(), TestTTLModel)
Exemplo n.º 26
0
 def tearDownClass(cls):
     super(TestConditional, cls).tearDownClass()
     drop_table(cls.connection(), TestConditionalModel)
Exemplo n.º 27
0
 def tearDownClass(cls):
     super(BaseIfNotExistsWithCounterTest, cls).tearDownClass()
     drop_table(cls.connection(), TestIfNotExistsWithCounterModel)
Exemplo n.º 28
0
    def test_multiple_deletes_dont_fail(self):
        sync_table(self.conn, TestModel)

        drop_table(self.conn, TestModel)
        drop_table(self.conn, TestModel)
Exemplo n.º 29
0
 def tearDownClass(cls):
     if CASSANDRA_VERSION >= "2.0":
         super(BaseDefaultTTLTest, cls).tearDownClass()
         conn = cls.connection()
         drop_table(conn, TestDefaultTTLModel)
         drop_table(conn, TestTTLModel)
Exemplo n.º 30
0
 def setUp(self):
     super(IndexTests, self).setUp()
     drop_table(self.conn, IndexModel)
     drop_table(self.conn, IndexCaseSensitiveModel)