Exemplo n.º 1
0
    def test_prepare_on_all_hosts(self):
        """
        Test to validate prepare_on_all_hosts flag is honored.

        Use a special ForcedHostSwitchPolicy to ensure prepared queries are cycled over nodes that should not
        have them prepared. Check the logs to insure they are being re-prepared on those nodes

        @since 3.4.0
        @jira_ticket PYTHON-556
        @expected_result queries will have to re-prepared on hosts that aren't the control connection
        """
        white_list = ForcedHostSwitchPolicy()
        clus = Cluster(
            load_balancing_policy=white_list,
            protocol_version=PROTOCOL_VERSION, prepare_on_all_hosts=False, reprepare_on_up=False)
        try:
            session = clus.connect(wait_for_all_pools=True)
            mock_handler = MockLoggingHandler()
            logger = logging.getLogger(cluster.__name__)
            logger.addHandler(mock_handler)
            select_statement = session.prepare("SELECT * FROM system.local")
            session.execute(select_statement)
            session.execute(select_statement)
            session.execute(select_statement)
            self.assertEqual(2, mock_handler.get_message_count('debug', "Re-preparing"))
        finally:
            clus.shutdown()
Exemplo n.º 2
0
    def test_sync_warnings(self):
        """
        Test to insure when inconsistent changes are made to a table, or type as part of a sync call that the proper logging messages are surfaced

        @since 3.2
        @jira_ticket PYTHON-260
        @expected_result warnings are logged

        @test_category object_mapper
        """
        mock_handler = MockLoggingHandler()
        logger = logging.getLogger(management.__name__)
        logger.addHandler(mock_handler)
        sync_table(BaseInconsistent)
        sync_table(ChangedInconsistent)
        self.assertTrue('differing from the model type' in mock_handler.messages.get('warning')[0])
        if CASSANDRA_VERSION >= '2.1':
            sync_type(DEFAULT_KEYSPACE, BaseInconsistentType)
            mock_handler.reset()
            sync_type(DEFAULT_KEYSPACE, ChangedInconsistentType)
            self.assertTrue('differing from the model user type' in mock_handler.messages.get('warning')[0])
        logger.removeHandler(mock_handler)
    def test_duplicate(self):
        """
        Test duplicate RPC addresses.

        Modifies the system.peers table to make hosts have the same rpc address. Ensures such hosts are filtered out and a message is logged

        @since 3.4
        @jira_ticket PYTHON-366
        @expected_result only one hosts' metadata will be populated

        @test_category metadata
        """
        mock_handler = MockLoggingHandler()
        logger = logging.getLogger(cassandra.cluster.__name__)
        logger.addHandler(mock_handler)
        test_cluster = self.cluster = Cluster(
            protocol_version=PROTOCOL_VERSION,
            load_balancing_policy=self.load_balancing_policy)
        test_cluster.connect()
        warnings = mock_handler.messages.get("warning")
        self.assertEqual(len(warnings), 1)
        self.assertTrue('multiple' in warnings[0])
        logger.removeHandler(mock_handler)
Exemplo n.º 4
0
 def setUpClass(cls):
     cls.logger_handler = MockLoggingHandler()
     logger = logging.getLogger(cluster.__name__)
     logger.addHandler(cls.logger_handler)