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_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.º 3
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
        # """
        with Cluster(protocol_version=PROTOCOL_VERSION,
                     prepare_on_all_hosts=False,
                     reprepare_on_up=False,
                     execution_profiles={
                         EXEC_PROFILE_DEFAULT:
                         ExecutionProfile(
                             load_balancing_policy=ForcedHostSwitchPolicy())
                     }) as cluster:
            session = cluster.connect(wait_for_all_pools=True)
            mock_handler = MockLoggingHandler()
            logger = logging.getLogger(dse.cluster.__name__)
            logger.addHandler(mock_handler)
            self.assertGreaterEqual(len(cluster.metadata.all_hosts()), 3)
            select_statement = session.prepare("SELECT * FROM system.local")
            reponse_first = session.execute(select_statement)
            reponse_second = session.execute(select_statement)
            reponse_third = session.execute(select_statement)

            self.assertEqual(
                len({
                    reponse_first.response_future.attempted_hosts[0],
                    reponse_second.response_future.attempted_hosts[0],
                    reponse_third.response_future.attempted_hosts[0]
                }), 3)

            self.assertEqual(
                2, mock_handler.get_message_count('debug', "Re-preparing"))