-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
70 lines (51 loc) · 1.87 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import subprocess
from shutil import rmtree
from time import sleep
import multiprocessing
"""
create table t (id int);
insert into t values (1);
"""
N = 1000 # 数据量
n = 4 # 线程数
try:
rmtree('test')
except:
print('failed to rmdir test')
with subprocess.Popen(['./build/bin/rmdb', 'test']) as rmdb:
print(f'@@@ Open rmdb, pid: {rmdb.pid}')
sleep(0.5)
client = []
for i in range(n):
client.append(subprocess.Popen(['./build/bin/rmdb_client'], stdin=subprocess.PIPE, text=True))
print(f'@@@ Open client{i}, pid: {client[-1].pid}')
client[0].stdin.write('create table t (id int);\n')
sleep(0.2)
for i in range(N):
for c in client:
c.stdin.write(f'insert into t values ({i});\n')
for i in range(N, N * 2):
for c in client:
c.stdin.write(f'insert into t values ({i});\n')
for i in range(N):
for c in client:
c.stdin.write(f'delete from t where id={i};\n')
client[0].stdin.write(f'select count(*) as cnt_id from t;\n')
client[0].stdin.write(f'select min(*) as min_id from t;\n')
client[0].stdin.write(f'select max(*) as max_id from t;\n')
for i, c in enumerate(client):
c.communicate('exit;\n')
c.terminate()
print(f'@@@ terminate client{i}')
print('@@@ terminate rmdb')
rmdb.kill()
with subprocess.Popen(['./build/bin/rmdb', 'test']) as rmdb:
print(f'@@@ Open rmdb, pid: {rmdb.pid}')
sleep(1)
with subprocess.Popen(['./build/bin/rmdb_client'], stdin=subprocess.PIPE, text=True) as client:
print(f'@@@ Open client{i}, pid: {client.pid}')
client.stdin.write(f'select count(*) as cnt_id from t;\n')
client.stdin.write(f'select min(*) as min_id from t;\n')
client.stdin.write(f'select max(*) as max_id from t;\n')
client.communicate('exit;\n')
rmdb.terminate()