<commit_before>#!/usr/bin/python

import pylibmc as memcache
from random import shuffle, randint
from time import sleep
import os

NUM_INTS = 8000
NUM_THREADS = 1
bin = True

def rethinkdb_insert(mc, ints, clone):
    for i in ints:
        print "Inserting %d" % i
        if (0 == mc.set(str(i), str(i))):
            raise ValueError("Insert of %d failed" % i)
        clone[str(i)] = str(i)

def rethinkdb_delete(mc, ints, clone):
    for i in ints:
        print "Deleting %d" % i
        if (0 == mc.delete(str(i))):
            raise ValueError("Delete of %d failed" % i)
        del clone[str(i)]
        if (randint(1,1000)==1):
            print "Verifying"
            rethinkdb_verify(mc, ints, clone)

def rethinkdb_verify(mc, ints, clone):
    for i in ints:
        key = str(i)
        stored_value = mc.get(key)
        clone_value = clone.get(key)
        if clone_value != stored_value:
            raise ValueError("Error, incorrent value in the database! (%s=>%s, should be %s)" % \
                (key, stored_value, clone_value))

def split_list(alist, parts):
    length = len(alist)
    return [alist[i * length // parts: (i + 1) * length // parts]
            for i in range(parts)]

def test_against_server_at(port):

    mc = memcache.Client(["localhost:%d" % port], binary = bin)
    clone = {}

    print "Shuffling numbers"
    ints = range(0, NUM_INTS)
    shuffle(ints)

    print "Inserting numbers"
    rethinkdb_insert(mc, ints, clone)

    print "Verifying"
    rethinkdb_verify(mc, ints, clone)

    print "Deleting numbers"
    rethinkdb_delete(mc, ints, clone)
    
    print "Done"

from test_common import RethinkDBTester<commit_msg>Updates binary test to test for binary pipelining, (by way of multi_{get, set, delete}). And everything fails. The test does however pass on memcached.<commit_after>#!/usr/bin/python

import pylibmc as memcache
from random import shuffle, randint
from time import sleep
import os

NUM_INTS = 80
NUM_THREADS = 1
bin = True

def rethinkdb_insert(mc, ints, clone):
    for i in ints:
        print "Inserting %d" % i
        if (0 == mc.set(str(i), str(i))):
            raise ValueError("Insert of %d failed" % i)
        clone[str(i)] = str(i)

def rethinkdb_multi_insert(mc, ints, clone):
    insert_dict = {}
    for i in ints:
        insert_dict[str(i)] = str(i)
        clone[str(i)] = str(i)
    if (0 == mc.set_multi(insert_dict)):
        raise ValueError("Multi insert failed")

def rethinkdb_delete(mc, ints, clone):
    for i in ints:
        print "Deleting %d" % i
        if (0 == mc.delete(str(i))):
            raise ValueError("Delete of %d failed" % i)
        del clone[str(i)]
        if (randint(1,1000)==1):
            print "Verifying"
            rethinkdb_verify(mc, ints, clone)

def rethinkdb_multi_delete(mc, ints, clone):
    deletes = []
    for i in ints:
        deletes.append(str(i))

    deletes_lists = split_list(deletes, randint(NUM_INTS // 40, NUM_INTS // 5))

    for list in deletes_lists:
        mc.delete_multi(list)
        for i in list:
            del clone[str(i)]

    print "Verifying"
    rethinkdb_multi_verify(mc, ints, clone)

def rethinkdb_verify(mc, ints, clone):
    for i in ints:
        key = str(i)
        stored_value = mc.get(key)
        clone_value = clone.get(key)
        if clone_value != stored_value:
            raise ValueError("Error, incorrent value in the database! (%s=>%s, should be %s)" % \
                (key, stored_value, clone_value))

def rethinkdb_multi_verify(mc, ints, clone):
    get_response = mc.get_multi(map(str, ints))
    for key, stored_value in zip(ints, get_response):
        if stored_value != clone.get(key):
            raise ValueError("Error, incorrent value in the database! (%s=>%s, should be %s)" % (key, stored_value, clone_value))

def split_list(alist, parts):
    length = len(alist)
    return [alist[i * length // parts: (i + 1) * length // parts]
            for i in range(parts)]

def test_against_server_at(port):

    mc = memcache.Client(["localhost:%d" % port], binary = bin)
    clone = {}

    print "====Testing singular operations===="

    ints = range(0, NUM_INTS)
    shuffle(ints)

    print "Inserting numbers"
    rethinkdb_insert(mc, ints, clone)

    print "Verifying"
    rethinkdb_verify(mc, ints, clone)

    print "Deleting numbers"
    rethinkdb_delete(mc, ints, clone)

    print "====Testing multi operations===="

    ints = range(0, NUM_INTS)
    shuffle(ints)

    print "Inserting numbers (multi)"
    rethinkdb_multi_insert(mc, ints, clone)

    print "Verifying (multi)"
    rethinkdb_multi_verify(mc, ints, clone)

    print "Deleting numbers (multi)"
    rethinkdb_multi_delete(mc, ints, clone)
    
    print "Done"

from test_common import RethinkDBTester
{'fraction_non_alphanumeric': 0.12107904642409034, 'fraction_numerical': 0.006900878293601004, 'mean_word_length': 2.7930214115781125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5294626', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1624, 'n_words': 457}