<commit_before>import math
import time
from distutils.version import LooseVersion

from cassandra import FunctionFailure

from assertions import assert_invalid, assert_none, assert_one
from dtest import CASSANDRA_VERSION_FROM_BUILD, Tester, debug
from tools import since


@since('2.2')
class TestUserFunctions(Tester):

    def __init__(self, *args, **kwargs):
        if CASSANDRA_VERSION_FROM_BUILD >= '3.0':
            kwargs['cluster_options'] = {'enable_user_defined_functions': 'true',
                                         'enable_scripted_user_defined_functions': 'true'}
        else:
            kwargs['cluster_options'] = {'enable_user_defined_functions': 'true'}
        Tester.__init__(self, *args, **kwargs)

    def prepare(self, create_keyspace=True, nodes=1, rf=1):
        cluster = self.cluster

        cluster.populate(nodes).start()
        node1 = cluster.nodelist()[0]
        time.sleep(0.2)

        session = self.patient_cql_connection(node1)
        if create_keyspace:
            self.create_ks(session, 'ks', rf)
        return session

    def test_migration(self):
        """ Test migration of user functions """
        cluster = self.cluster

        # Uses 3 nodes just to make sure function mutations are correctly serialized
        cluster.populate(3).start()
        node1 = cluster.nodelist()[0]
        node2 = cluster.nodelist()[1]
        node3 = cluster.nodelist()[2]
        time.sleep(0.2)

        session1 = self.patient_exclusive_cql_connection(node1)<commit_msg>Added annotation<commit_after>import math
import time
from distutils.version import LooseVersion

from cassandra import FunctionFailure

from assertions import assert_invalid, assert_none, assert_one
from dtest import CASSANDRA_VERSION_FROM_BUILD, Tester, debug
from tools import since, known_failure


@since('2.2')
class TestUserFunctions(Tester):

    def __init__(self, *args, **kwargs):
        if CASSANDRA_VERSION_FROM_BUILD >= '3.0':
            kwargs['cluster_options'] = {'enable_user_defined_functions': 'true',
                                         'enable_scripted_user_defined_functions': 'true'}
        else:
            kwargs['cluster_options'] = {'enable_user_defined_functions': 'true'}
        Tester.__init__(self, *args, **kwargs)

    def prepare(self, create_keyspace=True, nodes=1, rf=1):
        cluster = self.cluster

        cluster.populate(nodes).start()
        node1 = cluster.nodelist()[0]
        time.sleep(0.2)

        session = self.patient_cql_connection(node1)
        if create_keyspace:
            self.create_ks(session, 'ks', rf)
        return session

    @known_failure(failure_source='test',
                   jira_url='https://issues.apache.org/jira/browse/CASSANDRA-11951',
                   flaky=True)
    def test_migration(self):
        """ Test migration of user functions """
        cluster = self.cluster

        # Uses 3 nodes just to make sure function mutations are correctly serialized
        cluster.populate(3).start()
        node1 = cluster.nodelist()[0]
        node2 = cluster.nodelist()[1]
        node3 = cluster.nodelist()[2]
        time.sleep(0.2)

        session1 = self.patient_exclusive_cql_connection(node1)
{'fraction_non_alphanumeric': 0.1019266625233064, 'fraction_numerical': 0.015848353014294592, 'mean_word_length': 2.878313253012048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6923277', 'n_tokens_mistral': 951, 'n_tokens_neox': 910, 'n_words': 206}