<commit_before>from dtest import Tester, debug
from tools import *
from assertions import *
from ccmlib.cluster import Cluster
from ccmlib.node import TimeoutError
import random
import time
import os

from tools import ThriftConnection

versions = (
    'git:cassandra-1.1', 'git:cassandra-1.2', 'git:cassandra-2.0', 'git:trunk'
)

class TestUpgradeThroughVersions(Tester):
    """
    upgrades a 3-node cluster through each of the above versions.
    """

    def __init__(self, *args, **kwargs):
        # Forcing cluster version on purpose
        os.environ['CASSANDRA_VERSION'] = versions[0]
        # Force cluster options that are common among versions:
        kwargs['cluster_options'] = {'partitioner':'org.apache.cassandra.dht.RandomPartitioner'}
        Tester.__init__(self, *args, **kwargs)

    def upgrade_test(self):
        self.upgrade_scenario()

    def upgrade_test_mixed(self):
        """Only upgrade part of the cluster, so we have mixed versions part way through."""
        self.upgrade_scenario(mixed_version=True)

    def upgrade_scenario(self, mixed_version=False):
        self.num_rows = 2000
        self.counter_val = 0
        cluster = self.cluster

        # Create a ring
        debug('Creating cluster (%s)' % versions[0])
        cluster.populate(3)
        cluster.start()
        node1, node2, node3 = cluster.nodelist()
        self.node2 = node2

        node1.watch_log_for('Listening for thrift clients...')
        conn = ThriftConnection(node1)
        conn.create_ks()
        conn.create_cf()
        self._create_counter_cf()
        
        time.sleep(.5)
        self._write_values()
        self._increment_counter_value()

        # upgrade through versions
        for version in versions[1:]:
            if mixed_version:
                self.upgrade_to_version(version, mixed_version=True, nodes=(node1,))
                self.upgrade_to_version(version, mixed_version=True, nodes=(node2,node3)) 
                node1.nodetool('upgradesstables')
                node2.nodetool('upgradesstables')
                node3.nodetool('upgradesstables')
            else:
                self.upgrade_to_version(version)
        cluster.stop()

    def upgrade_to_version(self, version, mixed_version=False, nodes=None):
        """Upgrade Nodes - if *mixed_version* is True, only upgrade those nodes
        that are specified by *nodes*, otherwise ignore *nodes* specified
        and upgrade all nodes.
        """
        debug('Upgrading to ' + version)
        if not mixed_version:
            nodes = self.cluster.nodelist()

        for node in nodes:
            debug('Prepping node for shutdown: ' + node.name)
            node.flush()
            self._check_values()
        self._check_counter_values()
        
        for node in nodes:
            debug('Shutting down node: ' + node.name)
            time.sleep(.5)<commit_msg>Only upgrade to the version set by CASSANDRA_VERSION, else upgrade through all version<commit_after>from dtest import Tester, debug
from tools import *
from assertions import *
from ccmlib.cluster import Cluster
from ccmlib.node import TimeoutError
import random
import time
import os

from tools import ThriftConnection

versions = (
    'git:cassandra-1.1', 'git:cassandra-1.2', 'git:cassandra-2.0', 'git:trunk'
)

try:
    current_version = os.environ['CASSANDRA_VERSION']
except KeyError:
    current_version = versions[-1]
    
class TestUpgradeThroughVersions(Tester):
    """
    upgrades a 3-node cluster through each of the above versions.
    if the CASSANDRA_VERSION variable is set then upgrade to that version.
    otherwise upgrade all the way to trunk.
    """

    def __init__(self, *args, **kwargs):
        # Forcing cluster version on purpose
        os.environ['CASSANDRA_VERSION'] = versions[0]
        # Force cluster options that are common among versions:
        kwargs['cluster_options'] = {'partitioner':'org.apache.cassandra.dht.RandomPartitioner'}
        Tester.__init__(self, *args, **kwargs)

    def upgrade_test(self):
        self.upgrade_scenario()

    def upgrade_test_mixed(self):
        """Only upgrade part of the cluster, so we have mixed versions part way through."""
        self.upgrade_scenario(mixed_version=True)

    def upgrade_scenario(self, mixed_version=False):
        self.num_rows = 2000
        self.counter_val = 0
        cluster = self.cluster

        # Create a ring
        debug('Creating cluster (%s)' % versions[0])
        cluster.populate(3)
        cluster.start()
        node1, node2, node3 = cluster.nodelist()
        self.node2 = node2

        node1.watch_log_for('Listening for thrift clients...')
        conn = ThriftConnection(node1)
        conn.create_ks()
        conn.create_cf()
        self._create_counter_cf()
        
        time.sleep(.5)
        self._write_values()
        self._increment_counter_value()

        test_versions = [v for v in versions if v <= current_version ]
       
        # upgrade through versions
        for version in test_versions[1:]:
            if mixed_version:
                self.upgrade_to_version(version, mixed_version=True, nodes=(node1,))
                self.upgrade_to_version(version, mixed_version=True, nodes=(node2,node3)) 
                node1.nodetool('upgradesstables')
                node2.nodetool('upgradesstables')
                node3.nodetool('upgradesstables')
            else:
                self.upgrade_to_version(version)
        cluster.stop()

    def upgrade_to_version(self, version, mixed_version=False, nodes=None):
        """Upgrade Nodes - if *mixed_version* is True, only upgrade those nodes
        that are specified by *nodes*, otherwise ignore *nodes* specified
        and upgrade all nodes.
        """
        debug('Upgrading to ' + version)
        if not mixed_version:
            nodes = self.cluster.nodelist()

        for node in nodes:
            debug('Prepping node for shutdown: ' + node.name)
            node.flush()
            self._check_values()
        self._check_counter_values()
        
        for node in nodes:
            debug('Shutting down node: ' + node.name)
            time.sleep(.5)
{'fraction_non_alphanumeric': 0.09525347110106555, 'fraction_numerical': 0.010171133354859542, 'mean_word_length': 2.486212718064153, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '342876', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1728, 'n_words': 453}