<commit_before>from distutils import dir_util
import os
import subprocess
import time

from dtest import Tester, debug
from ccmlib import common as ccmcommon


class TestSSTableGenerationAndLoading(Tester):

    def __init__(self, *argv, **kwargs):
        kwargs['cluster_options'] = {'start_rpc': 'true'}
        super(TestSSTableGenerationAndLoading, self).__init__(*argv, **kwargs)
        self.allow_log_errors = True

    def incompressible_data_in_compressed_table_test(self):
        """
        tests for the bug that caused #3370:
        https://issues.apache.org/jira/browse/CASSANDRA-3370

        inserts random data into a compressed table. The compressed SSTable was
        compared to the uncompressed and was found to indeed be larger then
        uncompressed.
        """
        cluster = self.cluster
        cluster.populate(1).start()
        node1 = cluster.nodelist()[0]
        time.sleep(.5)

        session = self.patient_cql_connection(node1)
        self.create_ks(session, 'ks', 1)
        self.create_cf(session, 'cf', compression="Deflate")

        # make unique column names, and values that are incompressible
        rnd = open('/dev/urandom', 'rb')
        for col in xrange(10):
            col_name = str(col)
            col_val = rnd.read(5000)
            col_val = col_val.encode('hex')
            cql = "UPDATE cf SET v='%s' WHERE KEY='0' AND c='%s'" % (col_val, col_name)
            # print cql
            session.execute(cql)
        rnd.close()

        node1.flush()
        time.sleep(2)
        rows = session.execute("SELECT * FROM cf WHERE KEY = '0' AND c < '8'")<commit_msg>Use platform portable urandom access<commit_after>from distutils import dir_util
import os
import subprocess
import time

from dtest import Tester, debug
from ccmlib import common as ccmcommon


class TestSSTableGenerationAndLoading(Tester):

    def __init__(self, *argv, **kwargs):
        kwargs['cluster_options'] = {'start_rpc': 'true'}
        super(TestSSTableGenerationAndLoading, self).__init__(*argv, **kwargs)
        self.allow_log_errors = True

    def incompressible_data_in_compressed_table_test(self):
        """
        tests for the bug that caused #3370:
        https://issues.apache.org/jira/browse/CASSANDRA-3370

        inserts random data into a compressed table. The compressed SSTable was
        compared to the uncompressed and was found to indeed be larger then
        uncompressed.
        """
        cluster = self.cluster
        cluster.populate(1).start()
        node1 = cluster.nodelist()[0]
        time.sleep(.5)

        session = self.patient_cql_connection(node1)
        self.create_ks(session, 'ks', 1)
        self.create_cf(session, 'cf', compression="Deflate")

        # make unique column names, and values that are incompressible
        for col in xrange(10):
            col_name = str(col)
            col_val = os.urandom(5000)
            col_val = col_val.encode('hex')
            cql = "UPDATE cf SET v='%s' WHERE KEY='0' AND c='%s'" % (col_val, col_name)
            # print cql
            session.execute(cql)

        node1.flush()
        time.sleep(2)
        rows = session.execute("SELECT * FROM cf WHERE KEY = '0' AND c < '8'")
{'fraction_non_alphanumeric': 0.10241336633663366, 'fraction_numerical': 0.01547029702970297, 'mean_word_length': 2.5802879291251384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6182494', 'n_tokens_mistral': 1000, 'n_tokens_neox': 957, 'n_words': 263}