<commit_before>#!/usr/bin/env python
# Copyright 2010-2014 RethinkDB, all rights reserved.

from __future__ import print_function

import os, sys, time

startTime = time.time()

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'common')))
import driver, rdb_workload_common, utils

r = utils.import_python_driver()
dbName, tableName = utils.get_test_db_table()

numNodes = 2
numReplicas = 2

print("Starting cluster of %d servers (%.2fs)" % (numNodes, time.time() - startTime))
with driver.Cluster(initial_servers=numNodes, output_folder='.', wait_until_ready=True) as cluster:
    
    print("Establishing ReQL Connection (%.2fs)" % (time.time() - startTime))
    
    server = cluster[0]
    conn = r.connect(host=server.host, port=server.driver_port)
    
    print("Creating db/table %s/%s (%.2fs)" % (dbName, tableName, time.time() - startTime))
    
    if dbName not in r.db_list().run(conn):
        r.db_create(dbName).run(conn)
    
    if tableName in r.db(dbName).table_list().run(conn):
        r.db(dbName).table_drop(tableName).run(conn)
    r.db(dbName).table_create(tableName).run(conn)

    print("Increasing replication factor (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=numReplicas).run(conn)
    r.db(dbName).wait().run(conn)
    cluster.check()

    print("Inserting some data (%.2fs)" % (time.time() - startTime))
    rdb_workload_common.insert_many(host=server.host, port=server.driver_port, database=dbName, table=tableName, count=20000)
    cluster.check()

    print("Decreasing replication factor (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=1).run(conn)
    r.db(dbName).wait().run(conn)
    cluster.check()

    print("Increasing replication factor again (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=numReplicas).run(conn)
    
    print("Confirming that the progress meter indicates a backfill happening (%.2fs)" % (time.time() - startTime))
    # ToDo: replace this with ReQL command once issue is done: https://github.com/rethinkdb/rethinkdb/issues/3115
    raise NotImplementedError('Waiting for process table: https://github.com/rethinkdb/rethinkdb/issues/3115')
    
    cluster.check()
    
    print("Cleaning up (%.2fs)" % (time.time() - startTime))
    
    # The large backfill might take time, and for this test we don't care about it succeeding
    for server in cluster[:]:
        server.kill()

print("Done. (%.2fs)" % (time.time() - startTime))
<commit_msg>Updates the regression test for issue 659 to use the `rethinkdb.jobs` table<commit_after>#!/usr/bin/env python
# Copyright 2010-2014 RethinkDB, all rights reserved.

from __future__ import print_function

import os, sys, time

startTime = time.time()

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'common')))
import driver, rdb_workload_common, utils

r = utils.import_python_driver()
dbName, tableName = utils.get_test_db_table()

numNodes = 2
numReplicas = 2

print("Starting cluster of %d servers (%.2fs)" % (numNodes, time.time() - startTime))
with driver.Cluster(initial_servers=numNodes, output_folder='.', wait_until_ready=True) as cluster:
    
    print("Establishing ReQL Connection (%.2fs)" % (time.time() - startTime))
    
    server = cluster[0]
    conn = r.connect(host=server.host, port=server.driver_port)
    
    print("Creating db/table %s/%s (%.2fs)" % (dbName, tableName, time.time() - startTime))
    
    if dbName not in r.db_list().run(conn):
        r.db_create(dbName).run(conn)
    
    if tableName in r.db(dbName).table_list().run(conn):
        r.db(dbName).table_drop(tableName).run(conn)
    r.db(dbName).table_create(tableName).run(conn)

    print("Increasing replication factor (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=numReplicas).run(conn)
    r.db(dbName).wait().run(conn)
    cluster.check()

    print("Inserting some data (%.2fs)" % (time.time() - startTime))
    rdb_workload_common.insert_many(host=server.host, port=server.driver_port, database=dbName, table=tableName, count=20000)
    cluster.check()

    print("Decreasing replication factor (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=1).run(conn)
    r.db(dbName).wait().run(conn)
    cluster.check()

    print("Increasing replication factor again (%.2fs)" % (time.time() - startTime))
    r.db(dbName).table(tableName).reconfigure(shards=1, replicas=numReplicas).run(conn)
    
    print("Confirming that the progress meter indicates a backfill happening (%.2fs)" % (time.time() - startTime))
    time.sleep(0.5)
    assert r.db("rethinkdb") \
            .table("jobs") \
            .filter({"type": "backfill", "info": {"table": tableName}}) \
            .count() \
            .run(conn) == 1, "No backfill job found in `rethinkdb.jobs`."

    cluster.check()
    
    print("Cleaning up (%.2fs)" % (time.time() - startTime))
    
    # The large backfill might take time, and for this test we don't care about it succeeding
    for server in cluster[:]:
        server.kill()

print("Done. (%.2fs)" % (time.time() - startTime))

{'fraction_non_alphanumeric': 0.15620300751879698, 'fraction_numerical': 0.013909774436090226, 'mean_word_length': 3.931417979610751, 'pattern_counts': {'":': 3, '<': 3, '<?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': '1335390', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1798, 'n_words': 374}