Пример #1
0
 def tearDownClass(cls):
     execute_with_long_wait_retry(cls.setup_session, "DROP KEYSPACE {0}".format(cls.keyspace1))
     execute_with_long_wait_retry(cls.setup_session, "DROP KEYSPACE {0}".format(cls.keyspace2))
     models.DEFAULT_KEYSPACE = DEFAULT_KEYSPACE
     cls.setup_cluster.shutdown()
     setup_connection(DEFAULT_KEYSPACE)
     models.DEFAULT_KEYSPACE
Пример #2
0
 def tearDownClass(cls):
     execute_with_long_wait_retry(cls.setup_session, "DROP KEYSPACE {0}".format(cls.keyspace1))
     execute_with_long_wait_retry(cls.setup_session, "DROP KEYSPACE {0}".format(cls.keyspace2))
     models.DEFAULT_KEYSPACE = DEFAULT_KEYSPACE
     cls.setup_cluster.shutdown()
     setup_connection(DEFAULT_KEYSPACE)
     models.DEFAULT_KEYSPACE
Пример #3
0
 def setUpClass(cls):
     connection.unregister_connection('default')
     cls.keyspace1 = 'ctest1'
     cls.keyspace2 = 'ctest2'
     super(ConnectionTest, cls).setUpClass()
     cls.setup_cluster = Cluster(protocol_version=PROTOCOL_VERSION)
     cls.setup_session = cls.setup_cluster.connect()
     ddl = "CREATE KEYSPACE {0} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '{1}'}}".format(cls.keyspace1, 1)
     execute_with_long_wait_retry(cls.setup_session, ddl)
     ddl = "CREATE KEYSPACE {0} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '{1}'}}".format(cls.keyspace2, 1)
     execute_with_long_wait_retry(cls.setup_session, ddl)
Пример #4
0
 def setUpClass(cls):
     connection.unregister_connection('default')
     cls.keyspace1 = 'ctest1'
     cls.keyspace2 = 'ctest2'
     super(ConnectionTest, cls).setUpClass()
     cls.setup_cluster = Cluster(protocol_version=PROTOCOL_VERSION)
     cls.setup_session = cls.setup_cluster.connect()
     ddl = "CREATE KEYSPACE {0} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '{1}'}}".format(cls.keyspace1, 1)
     execute_with_long_wait_retry(cls.setup_session, ddl)
     ddl = "CREATE KEYSPACE {0} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '{1}'}}".format(cls.keyspace2, 1)
     execute_with_long_wait_retry(cls.setup_session, ddl)
Пример #5
0
    def _test_basic(self, dse_version):
        """
        Test basic connection and usage
        """
        cluster_name = '{}-{}'.format(
            self.__class__.__name__, dse_version.base_version.replace('.', '_')
        )
        use_cluster(cluster_name=cluster_name, nodes=[3],
                    dse_cluster=True, dse_options={}, dse_version=dse_version)

        cluster = Cluster(
            allow_beta_protocol_version=(dse_version >= Version('6.7.0')))
        session = cluster.connect()
        result = execute_until_pass(
            session,
            """
            CREATE KEYSPACE clustertests
            WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
            """)
        self.assertFalse(result)

        result = execute_with_long_wait_retry(
            session,
            """
            CREATE TABLE clustertests.cf0 (
                a text,
                b text,
                c text,
                PRIMARY KEY (a, b)
            )
            """)
        self.assertFalse(result)

        result = session.execute(
            """
            INSERT INTO clustertests.cf0 (a, b, c) VALUES ('a', 'b', 'c')
            """)
        self.assertFalse(result)

        result = session.execute("SELECT * FROM clustertests.cf0")
        self.assertEqual([('a', 'b', 'c')], result)

        execute_with_long_wait_retry(session, "DROP KEYSPACE clustertests")

        cluster.shutdown()
Пример #6
0
    def _test_basic(self, dse_version):
        """
        Test basic connection and usage
        """
        cluster_name = '{}-{}'.format(
            self.__class__.__name__,
            dse_version.base_version.replace('.', '_'))
        use_cluster(cluster_name=cluster_name,
                    nodes=[3],
                    dse_cluster=True,
                    dse_options={},
                    dse_version=dse_version)

        cluster = Cluster(
            allow_beta_protocol_version=(dse_version >= Version('6.7.0')))
        session = cluster.connect()
        result = execute_until_pass(
            session, """
            CREATE KEYSPACE clustertests
            WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
            """)
        self.assertFalse(result)

        result = execute_with_long_wait_retry(
            session, """
            CREATE TABLE clustertests.cf0 (
                a text,
                b text,
                c text,
                PRIMARY KEY (a, b)
            )
            """)
        self.assertFalse(result)

        result = session.execute("""
            INSERT INTO clustertests.cf0 (a, b, c) VALUES ('a', 'b', 'c')
            """)
        self.assertFalse(result)

        result = session.execute("SELECT * FROM clustertests.cf0")
        self.assertEqual([('a', 'b', 'c')], result)

        execute_with_long_wait_retry(session, "DROP KEYSPACE clustertests")

        cluster.shutdown()
Пример #7
0
    def _protocol_divergence_fail_by_flag_uses_int(self,
                                                   version,
                                                   uses_int_query_flag,
                                                   int_flag=True,
                                                   beta=False):
        cluster = Cluster(protocol_version=version,
                          allow_beta_protocol_version=beta)
        session = cluster.connect()

        query_one = SimpleStatement(
            "INSERT INTO test3rf.test (k, v) VALUES (1, 1)")
        query_two = SimpleStatement(
            "INSERT INTO test3rf.test (k, v) VALUES (2, 2)")

        execute_with_long_wait_retry(session, query_one)
        execute_with_long_wait_retry(session, query_two)

        with mock.patch(
                'cassandra.protocol.ProtocolVersion.uses_int_query_flags',
                new=mock.Mock(return_value=int_flag)):
            future = self._send_query_message(
                session,
                10,
                consistency_level=ConsistencyLevel.ONE,
                fetch_size=1)

            response = future.result()

            # This means the flag are not handled as they are meant by the server if uses_int=False
            self.assertEqual(response.has_more_pages, uses_int_query_flag)

        execute_with_long_wait_retry(session,
                                     SimpleStatement("TRUNCATE test3rf.test"))
        cluster.shutdown()
Пример #8
0
    def test_basic(self):
        """
        Test basic connection and usage
        """

        cluster = Cluster(protocol_version=PROTOCOL_VERSION)
        session = cluster.connect()
        result = execute_until_pass(session,
            """
            CREATE KEYSPACE clustertests
            WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
            """)
        self.assertFalse(result)

        result = execute_with_long_wait_retry(session,
            """
            CREATE TABLE clustertests.cf0 (
                a text,
                b text,
                c text,
                PRIMARY KEY (a, b)
            )
            """)
        self.assertFalse(result)

        result = session.execute(
            """
            INSERT INTO clustertests.cf0 (a, b, c) VALUES ('a', 'b', 'c')
            """)
        self.assertFalse(result)

        result = session.execute("SELECT * FROM clustertests.cf0")
        self.assertEqual([('a', 'b', 'c')], result)

        execute_with_long_wait_retry(session, "DROP KEYSPACE clustertests")

        cluster.shutdown()
Пример #9
0
    def test_basic(self):
        """
        Test basic connection and usage
        """

        cluster = Cluster(protocol_version=PROTOCOL_VERSION)
        session = cluster.connect()
        result = execute_until_pass(session,
            """
            CREATE KEYSPACE clustertests
            WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
            """)
        self.assertFalse(result)

        result = execute_with_long_wait_retry(session,
            """
            CREATE TABLE clustertests.cf0 (
                a text,
                b text,
                c text,
                PRIMARY KEY (a, b)
            )
            """)
        self.assertFalse(result)

        result = session.execute(
            """
            INSERT INTO clustertests.cf0 (a, b, c) VALUES ('a', 'b', 'c')
            """)
        self.assertFalse(result)

        result = session.execute("SELECT * FROM clustertests.cf0")
        self.assertEqual([('a', 'b', 'c')], result)

        execute_with_long_wait_retry(session, "DROP KEYSPACE clustertests")

        cluster.shutdown()
    def _protocol_divergence_fail_by_flag_uses_int(self, version, uses_int_query_flag, int_flag = True, beta=False):
        cluster = Cluster(protocol_version=version, allow_beta_protocol_version=beta)
        session = cluster.connect()

        query_one = SimpleStatement("INSERT INTO test3rf.test (k, v) VALUES (1, 1)")
        query_two = SimpleStatement("INSERT INTO test3rf.test (k, v) VALUES (2, 2)")

        execute_with_long_wait_retry(session, query_one)
        execute_with_long_wait_retry(session, query_two)

        with mock.patch('cassandra.protocol.ProtocolVersion.uses_int_query_flags', new=mock.Mock(return_value=int_flag)):
            future = self._send_query_message(session, 10,
                                              consistency_level=ConsistencyLevel.ONE, fetch_size=1)

            response = future.result()

            # This means the flag are not handled as they are meant by the server if uses_int=False
            self.assertEqual(response.has_more_pages, uses_int_query_flag)

        execute_with_long_wait_retry(session, SimpleStatement("TRUNCATE test3rf.test"))
        cluster.shutdown()