{"action":"created","comment":{"url":"https://api.github.com/repos/baidu/tera/pulls/comments/48935230","id":48935230,"diff_hunk":"@@ -0,0 +1,223 @@\n+\"\"\"\n+Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved\n+Use of this source code is governed by a BSD-style license that can be\n+found in the LICENSE file.\n+\"\"\"\n+\n+import subprocess\n+import filecmp\n+import os\n+import nose.tools\n+import json\n+import time\n+import sys\n+\n+from conf import const\n+\n+def cleanup():                                                                                             \n+    ret = subprocess.Popen(const.teracli_binary + ' disable test',                                         \n+                           stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)                     \n+    print ''.join(ret.stdout.readlines())                                                                  \n+    print ''.join(ret.stderr.readlines())                                                                  \n+    time.sleep(2)                                                                                          \n+    ret = subprocess.Popen(const.teracli_binary + ' drop test',                                            \n+                           stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)                     \n+    print ''.join(ret.stdout.readlines())                                                                  \n+    print ''.join(ret.stderr.readlines())\n+\n+    files = os.listdir('.')\n+    for f in files:\n+        if f.endswith('.out'):\n+            os.remove(f)  \n+\n+\n+def createbyfile(schema, deli=''):                                                                         \n+    \"\"\"                                                                                                    \n+    This function creates a table according to a specified schema                                          \n+    :param schema: schema file path                                                                        \n+    :param deli: deli file path                                                                            \n+    :return: None                                                                                          \n+    \"\"\"\n+    cleanup()                                                                                              \n+    create_cmd = '{teracli} createbyfile {schema} {deli}'.format(teracli=const.teracli_binary, \n+                                                                 schema=schema, deli=deli)\n+    print create_cmd\n+    ret = subprocess.Popen(create_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\n+    print ''.join(ret.stdout.readlines())\n+    print ''.join(ret.stderr.readlines()) \n+\n+\n+def run_tera_mark(file_path, op, table_name, random, value_size, num, key_size, cf='', key_seed=1, value_seed=1,\n+                  key_step=1, entry_limit=0):  \n+    \"\"\"                                                                                                    \n+    This function provide means to write data into Tera and dump a copy into a specified file at the same time.\n+    :param file_path: a copy of data will be dumped into file_path for future use                          \n+    :param op: ['w' | 'd'], 'w' indicates write and 'd' indicates delete                                   \n+    :param table_name: table name                                                                          \n+    :param random: ['random' | 'seq']                                                                      \n+    :param value_size: value size in Bytes                                                                 \n+    :param num: entry number                                                                               \n+    :param key_size: key size in Bytes                                                                     \n+    :param cf: cf list, e.g. 'cf0:qual,cf1:flag'. Empty cf list for kv mode. Notice: no space in between   \n+    :param key_seed: seed for random key generator                                                         \n+    :param value_seed: seed for random value generator                                                     \n+    :param key_step: interval for key values\n+    :param entry_limit: the writing speed for limitation\n+    :return: None                                                                                          \n+    \"\"\"   \n+    # write data into Tera                                                                                 \n+    tera_bench_args = \"\"\n+    awk_args = \"\"\n+\n+    if cf == '':  # kv mode\n+        tera_bench_args += \"\"\"--compression_ratio=1 --key_seed={kseed} --value_seed={vseed} \"\"\"\\\n+                           \"\"\" --value_size={vsize} --num={num} --benchmarks={random} \"\"\"\\\n+                           \"\"\" --key_size={ksize} --key_step={kstep}\"\"\".format(kseed=key_seed,\n+                                                       vseed=value_seed, vsize=value_size, num=num,\n+                                                       random=random, ksize=key_size,\n+                                                       kstep=key_step) \n+\n+        if op == 'd':  # delete                                                                            \n+            awk_args += \"\"\"-F '\\t' '{print $1}'\"\"\"                                                         \n+        else:  # write\n+            awk_args += \"\"\"-F '\\t' '{print $1\"\\t\"$2}'\"\"\" \n+    else:  # table \n+        tera_bench_args += \"\"\"--cf={cf} --compression_ratio=1 --key_seed={kseed} --value_seed={vseed} \"\"\"\\\n+                           \"\"\" --value_size={vsize} --num={num} --benchmarks={random} \"\"\"\\\n+                           \"\"\" --key_size={ksize} --key_step={kstep}\"\"\".format(cf=cf,\n+                                                            kseed=key_seed, vseed=value_seed,\n+                                                            vsize=value_size, num=num, random=random, ksize=key_size,\n+                                                            kstep=key_step)\n+\n+        if op == 'd':  # delete                                                                            \n+            awk_args += \"\"\"-F '\\t' '{print $1\"\\t\"$3\"\\t\"$4}'\"\"\"                                             \n+        else:  # write                                                                                     \n+            awk_args += \"\"\"-F '\\t' '{print $1\"\\t\"$2\"\\t\"$3\"\\t\"$4}'\"\"\"  \n+\n+    tera_mark_args = \"\"\"--mode={op} --tablename={table_name} --type=async \"\"\"\\\n+                     \"\"\" --verify=false --entry_limit={elimit}\"\"\".format(op=op, table_name=table_name,     \n+                                                                   elimit=entry_limit) \n+\n+    cmd = '{tera_bench} {bench_args} | awk {awk_args} | {tera_mark} {mark_args}'.format(                   \n+           tera_bench=const.tera_bench_binary, bench_args=tera_bench_args, awk_args=awk_args,                 \n+           tera_mark=const.tera_mark_binary, mark_args=tera_mark_args)\n+\n+    print cmd                                                                                              \n+    ret = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)                \n+    print ''.join(ret.stdout.readlines())                                                                  \n+    print ''.join(ret.stderr.readlines()) \n+\n+    # write/append data to a file for comparison                                                           \n+    for path, is_append in file_path:   \n+        if cf == '':                                                                                       \n+            awk_args = \"\"\"-F '\\t' '{print $1\"::0:\"$2}'\"\"\"                                                  \n+        else:                                                                                              \n+            awk_args = \"\"\"-F '\\t' '{print $1\":\"$3\":\"$4\":\"$2}'\"\"\"   \n+\n+        redirect_op = ''                                                                                   \n+        if is_append is True:                                                                              \n+            redirect_op += '>>'                                                                            \n+        else:                                                                                              \n+            redirect_op += '>' \n+\n+        dump_cmd = '{tera_bench} {tera_bench_args} | awk {awk_args} {redirect_op} {out}'.format(           \n+                    tera_bench=const.tera_bench_binary, tera_bench_args=tera_bench_args,                           \n+                    redirect_op=redirect_op, awk_args=awk_args, out=path)                                          \n+        print dump_cmd \n+        ret = subprocess.Popen(dump_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)       \n+        print ''.join(ret.stdout.readlines())                                                              \n+        print ''.join(ret.stderr.readlines())\n+\n+","path":"test/testcaseForIntegration/common.py","position":131,"original_position":131,"commit_id":"88f928ce5f9e5eecbcf4a513724f431948b9e04e","original_commit_id":"88f928ce5f9e5eecbcf4a513724f431948b9e04e","user":{"login":"lylei","id":2767333,"avatar_url":"https://avatars.githubusercontent.com/u/2767333?v=3","gravatar_id":"","url":"https://api.github.com/users/lylei","html_url":"https://github.com/lylei","followers_url":"https://api.github.com/users/lylei/followers","following_url":"https://api.github.com/users/lylei/following{/other_user}","gists_url":"https://api.github.com/users/lylei/gists{/gist_id}","starred_url":"https://api.github.com/users/lylei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lylei/subscriptions","organizations_url":"https://api.github.com/users/lylei/orgs","repos_url":"https://api.github.com/users/lylei/repos","events_url":"https://api.github.com/users/lylei/events{/privacy}","received_events_url":"https://api.github.com/users/lylei/received_events","type":"User","site_admin":false},"body":"一样的最好复用吧","created_at":"2016-01-06T08:13:08Z","updated_at":"2016-01-06T08:13:08Z","html_url":"https://github.com/baidu/tera/pull/679#discussion_r48935230","pull_request_url":"https://api.github.com/repos/baidu/tera/pulls/679","_links":{"self":{"href":"https://api.github.com/repos/baidu/tera/pulls/comments/48935230"},"html":{"href":"https://github.com/baidu/tera/pull/679#discussion_r48935230"},"pull_request":{"href":"https://api.github.com/repos/baidu/tera/pulls/679"}}},"pull_request":{"url":"https://api.github.com/repos/baidu/tera/pulls/679","id":55185770,"html_url":"https://github.com/baidu/tera/pull/679","diff_url":"https://github.com/baidu/tera/pull/679.diff","patch_url":"https://github.com/baidu/tera/pull/679.patch","issue_url":"https://api.github.com/repos/baidu/tera/issues/679","number":679,"state":"open","locked":false,"title":"Integration","user":{"login":"MichelleZ","id":10205478,"avatar_url":"https://avatars.githubusercontent.com/u/10205478?v=3","gravatar_id":"","url":"https://api.github.com/users/MichelleZ","html_url":"https://github.com/MichelleZ","followers_url":"https://api.github.com/users/MichelleZ/followers","following_url":"https://api.github.com/users/MichelleZ/following{/other_user}","gists_url":"https://api.github.com/users/MichelleZ/gists{/gist_id}","starred_url":"https://api.github.com/users/MichelleZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichelleZ/subscriptions","organizations_url":"https://api.github.com/users/MichelleZ/orgs","repos_url":"https://api.github.com/users/MichelleZ/repos","events_url":"https://api.github.com/users/MichelleZ/events{/privacy}","received_events_url":"https://api.github.com/users/MichelleZ/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-06T07:46:28Z","updated_at":"2016-01-06T08:13:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11c2b7b062ab5c614b525215d4ae3f8c81f0d1ac","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/baidu/tera/pulls/679/commits","review_comments_url":"https://api.github.com/repos/baidu/tera/pulls/679/comments","review_comment_url":"https://api.github.com/repos/baidu/tera/pulls/comments{/number}","comments_url":"https://api.github.com/repos/baidu/tera/issues/679/comments","statuses_url":"https://api.github.com/repos/baidu/tera/statuses/88f928ce5f9e5eecbcf4a513724f431948b9e04e","head":{"label":"MichelleZ:integration","ref":"integration","sha":"88f928ce5f9e5eecbcf4a513724f431948b9e04e","user":{"login":"MichelleZ","id":10205478,"avatar_url":"https://avatars.githubusercontent.com/u/10205478?v=3","gravatar_id":"","url":"https://api.github.com/users/MichelleZ","html_url":"https://github.com/MichelleZ","followers_url":"https://api.github.com/users/MichelleZ/followers","following_url":"https://api.github.com/users/MichelleZ/following{/other_user}","gists_url":"https://api.github.com/users/MichelleZ/gists{/gist_id}","starred_url":"https://api.github.com/users/MichelleZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichelleZ/subscriptions","organizations_url":"https://api.github.com/users/MichelleZ/orgs","repos_url":"https://api.github.com/users/MichelleZ/repos","events_url":"https://api.github.com/users/MichelleZ/events{/privacy}","received_events_url":"https://api.github.com/users/MichelleZ/received_events","type":"User","site_admin":false},"repo":{"id":46267087,"name":"tera","full_name":"MichelleZ/tera","owner":{"login":"MichelleZ","id":10205478,"avatar_url":"https://avatars.githubusercontent.com/u/10205478?v=3","gravatar_id":"","url":"https://api.github.com/users/MichelleZ","html_url":"https://github.com/MichelleZ","followers_url":"https://api.github.com/users/MichelleZ/followers","following_url":"https://api.github.com/users/MichelleZ/following{/other_user}","gists_url":"https://api.github.com/users/MichelleZ/gists{/gist_id}","starred_url":"https://api.github.com/users/MichelleZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichelleZ/subscriptions","organizations_url":"https://api.github.com/users/MichelleZ/orgs","repos_url":"https://api.github.com/users/MichelleZ/repos","events_url":"https://api.github.com/users/MichelleZ/events{/privacy}","received_events_url":"https://api.github.com/users/MichelleZ/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MichelleZ/tera","description":"A distributed, elastic, structured database.","fork":true,"url":"https://api.github.com/repos/MichelleZ/tera","forks_url":"https://api.github.com/repos/MichelleZ/tera/forks","keys_url":"https://api.github.com/repos/MichelleZ/tera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MichelleZ/tera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MichelleZ/tera/teams","hooks_url":"https://api.github.com/repos/MichelleZ/tera/hooks","issue_events_url":"https://api.github.com/repos/MichelleZ/tera/issues/events{/number}","events_url":"https://api.github.com/repos/MichelleZ/tera/events","assignees_url":"https://api.github.com/repos/MichelleZ/tera/assignees{/user}","branches_url":"https://api.github.com/repos/MichelleZ/tera/branches{/branch}","tags_url":"https://api.github.com/repos/MichelleZ/tera/tags","blobs_url":"https://api.github.com/repos/MichelleZ/tera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MichelleZ/tera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MichelleZ/tera/git/refs{/sha}","trees_url":"https://api.github.com/repos/MichelleZ/tera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MichelleZ/tera/statuses/{sha}","languages_url":"https://api.github.com/repos/MichelleZ/tera/languages","stargazers_url":"https://api.github.com/repos/MichelleZ/tera/stargazers","contributors_url":"https://api.github.com/repos/MichelleZ/tera/contributors","subscribers_url":"https://api.github.com/repos/MichelleZ/tera/subscribers","subscription_url":"https://api.github.com/repos/MichelleZ/tera/subscription","commits_url":"https://api.github.com/repos/MichelleZ/tera/commits{/sha}","git_commits_url":"https://api.github.com/repos/MichelleZ/tera/git/commits{/sha}","comments_url":"https://api.github.com/repos/MichelleZ/tera/comments{/number}","issue_comment_url":"https://api.github.com/repos/MichelleZ/tera/issues/comments{/number}","contents_url":"https://api.github.com/repos/MichelleZ/tera/contents/{+path}","compare_url":"https://api.github.com/repos/MichelleZ/tera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MichelleZ/tera/merges","archive_url":"https://api.github.com/repos/MichelleZ/tera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MichelleZ/tera/downloads","issues_url":"https://api.github.com/repos/MichelleZ/tera/issues{/number}","pulls_url":"https://api.github.com/repos/MichelleZ/tera/pulls{/number}","milestones_url":"https://api.github.com/repos/MichelleZ/tera/milestones{/number}","notifications_url":"https://api.github.com/repos/MichelleZ/tera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MichelleZ/tera/labels{/name}","releases_url":"https://api.github.com/repos/MichelleZ/tera/releases{/id}","created_at":"2015-11-16T10:13:05Z","updated_at":"2015-11-16T10:13:08Z","pushed_at":"2016-01-06T07:41:39Z","git_url":"git://github.com/MichelleZ/tera.git","ssh_url":"git@github.com:MichelleZ/tera.git","clone_url":"https://github.com/MichelleZ/tera.git","svn_url":"https://github.com/MichelleZ/tera","homepage":"","size":12621,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"baidu:master","ref":"master","sha":"d6fa9e0bc7f7a987b4c6a1220a03de600b9a9daf","user":{"login":"baidu","id":13245940,"avatar_url":"https://avatars.githubusercontent.com/u/13245940?v=3","gravatar_id":"","url":"https://api.github.com/users/baidu","html_url":"https://github.com/baidu","followers_url":"https://api.github.com/users/baidu/followers","following_url":"https://api.github.com/users/baidu/following{/other_user}","gists_url":"https://api.github.com/users/baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baidu/subscriptions","organizations_url":"https://api.github.com/users/baidu/orgs","repos_url":"https://api.github.com/users/baidu/repos","events_url":"https://api.github.com/users/baidu/events{/privacy}","received_events_url":"https://api.github.com/users/baidu/received_events","type":"Organization","site_admin":false},"repo":{"id":18129915,"name":"tera","full_name":"baidu/tera","owner":{"login":"baidu","id":13245940,"avatar_url":"https://avatars.githubusercontent.com/u/13245940?v=3","gravatar_id":"","url":"https://api.github.com/users/baidu","html_url":"https://github.com/baidu","followers_url":"https://api.github.com/users/baidu/followers","following_url":"https://api.github.com/users/baidu/following{/other_user}","gists_url":"https://api.github.com/users/baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baidu/subscriptions","organizations_url":"https://api.github.com/users/baidu/orgs","repos_url":"https://api.github.com/users/baidu/repos","events_url":"https://api.github.com/users/baidu/events{/privacy}","received_events_url":"https://api.github.com/users/baidu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/baidu/tera","description":"A distributed, elastic, structured database.","fork":false,"url":"https://api.github.com/repos/baidu/tera","forks_url":"https://api.github.com/repos/baidu/tera/forks","keys_url":"https://api.github.com/repos/baidu/tera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/baidu/tera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/baidu/tera/teams","hooks_url":"https://api.github.com/repos/baidu/tera/hooks","issue_events_url":"https://api.github.com/repos/baidu/tera/issues/events{/number}","events_url":"https://api.github.com/repos/baidu/tera/events","assignees_url":"https://api.github.com/repos/baidu/tera/assignees{/user}","branches_url":"https://api.github.com/repos/baidu/tera/branches{/branch}","tags_url":"https://api.github.com/repos/baidu/tera/tags","blobs_url":"https://api.github.com/repos/baidu/tera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/baidu/tera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/baidu/tera/git/refs{/sha}","trees_url":"https://api.github.com/repos/baidu/tera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/baidu/tera/statuses/{sha}","languages_url":"https://api.github.com/repos/baidu/tera/languages","stargazers_url":"https://api.github.com/repos/baidu/tera/stargazers","contributors_url":"https://api.github.com/repos/baidu/tera/contributors","subscribers_url":"https://api.github.com/repos/baidu/tera/subscribers","subscription_url":"https://api.github.com/repos/baidu/tera/subscription","commits_url":"https://api.github.com/repos/baidu/tera/commits{/sha}","git_commits_url":"https://api.github.com/repos/baidu/tera/git/commits{/sha}","comments_url":"https://api.github.com/repos/baidu/tera/comments{/number}","issue_comment_url":"https://api.github.com/repos/baidu/tera/issues/comments{/number}","contents_url":"https://api.github.com/repos/baidu/tera/contents/{+path}","compare_url":"https://api.github.com/repos/baidu/tera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/baidu/tera/merges","archive_url":"https://api.github.com/repos/baidu/tera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/baidu/tera/downloads","issues_url":"https://api.github.com/repos/baidu/tera/issues{/number}","pulls_url":"https://api.github.com/repos/baidu/tera/pulls{/number}","milestones_url":"https://api.github.com/repos/baidu/tera/milestones{/number}","notifications_url":"https://api.github.com/repos/baidu/tera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/baidu/tera/labels{/name}","releases_url":"https://api.github.com/repos/baidu/tera/releases{/id}","created_at":"2014-03-26T07:22:05Z","updated_at":"2016-01-04T15:12:52Z","pushed_at":"2016-01-06T07:46:31Z","git_url":"git://github.com/baidu/tera.git","ssh_url":"git@github.com:baidu/tera.git","clone_url":"https://github.com/baidu/tera.git","svn_url":"https://github.com/baidu/tera","homepage":"","size":16002,"stargazers_count":338,"watchers_count":338,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":109,"mirror_url":null,"open_issues_count":115,"forks":109,"open_issues":115,"watchers":338,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/baidu/tera/pulls/679"},"html":{"href":"https://github.com/baidu/tera/pull/679"},"issue":{"href":"https://api.github.com/repos/baidu/tera/issues/679"},"comments":{"href":"https://api.github.com/repos/baidu/tera/issues/679/comments"},"review_comments":{"href":"https://api.github.com/repos/baidu/tera/pulls/679/comments"},"review_comment":{"href":"https://api.github.com/repos/baidu/tera/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/baidu/tera/pulls/679/commits"},"statuses":{"href":"https://api.github.com/repos/baidu/tera/statuses/88f928ce5f9e5eecbcf4a513724f431948b9e04e"}}}}