1 |
4902
|
daigle
|
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import metacat
|
4 |
|
|
import sys
|
5 |
|
|
|
6 |
|
|
from time import time
|
7 |
|
|
from time import sleep
|
8 |
|
|
|
9 |
|
|
letter = sys.argv[1]
|
10 |
|
|
iterations = int(sys.argv[2])
|
11 |
|
|
interval = int(sys.argv[3])
|
12 |
|
|
host = sys.argv[4]
|
13 |
|
|
|
14 |
4906
|
daigle
|
# set debug_level=0 for no debugging. Set it to 0 - 3 for increasing amounts of debug.
|
15 |
|
|
debug_level=2
|
16 |
4902
|
daigle
|
|
17 |
4906
|
daigle
|
output_file_name = "./squery-" + letter + ".out"
|
18 |
|
|
output_file = open(output_file_name, 'w')
|
19 |
|
|
output_file.close()
|
20 |
4902
|
daigle
|
|
21 |
|
|
def debug (message):
|
22 |
4906
|
daigle
|
output_file = open(output_file_name, 'a')
|
23 |
4902
|
daigle
|
output_file.write(message + '\n')
|
24 |
4906
|
daigle
|
output_file.close()
|
25 |
4902
|
daigle
|
|
26 |
|
|
def debug1 (message):
|
27 |
4906
|
daigle
|
if debug_level > 0:
|
28 |
|
|
output_file = open(output_file_name, 'a')
|
29 |
4902
|
daigle
|
output_file.write(message + '\n')
|
30 |
4906
|
daigle
|
output_file.close()
|
31 |
4902
|
daigle
|
|
32 |
|
|
def debug2 (message):
|
33 |
4906
|
daigle
|
if debug_level > 1:
|
34 |
|
|
output_file = open(output_file_name, 'a')
|
35 |
4902
|
daigle
|
output_file.write(message + '\n')
|
36 |
4906
|
daigle
|
output_file.close()
|
37 |
4902
|
daigle
|
|
38 |
|
|
def debug3 (message):
|
39 |
4906
|
daigle
|
if debug_level > 2:
|
40 |
|
|
output_file = open(output_file_name, 'a')
|
41 |
4902
|
daigle
|
output_file.write(message + '\n')
|
42 |
4906
|
daigle
|
output_file.close()
|
43 |
4902
|
daigle
|
|
44 |
4906
|
daigle
|
dictionary_file_name = './dictionary-' + letter + '.txt'
|
45 |
|
|
dictionary_file = open(dictionary_file_name, 'r')
|
46 |
4902
|
daigle
|
|
47 |
|
|
iter_count = 0
|
48 |
|
|
|
49 |
|
|
debug("************************************************** ")
|
50 |
|
|
debug("Starting squery-load-test for ")
|
51 |
|
|
debug(" letter: $letter ")
|
52 |
|
|
debug(" iterations: $iterations ")
|
53 |
|
|
debug(" interval: $interval ")
|
54 |
4906
|
daigle
|
debug(" host: $host ")
|
55 |
4902
|
daigle
|
debug("************************************************** ")
|
56 |
|
|
|
57 |
8265
|
leinfelder
|
mc = metacat.MetacatClient(host,'/metacat/metacat')
|
58 |
4902
|
daigle
|
|
59 |
|
|
query_template_file = open('squery.xml.tmpl', 'r')
|
60 |
|
|
query_template = query_template_file.read()
|
61 |
|
|
query_template_file.close
|
62 |
|
|
|
63 |
|
|
for line in dictionary_file:
|
64 |
4906
|
daigle
|
word = line.strip()
|
65 |
|
|
debug("[%s] -- Processing Search" % (word))
|
66 |
|
|
query = query_template.replace("@!search-word!@", word)
|
67 |
|
|
t1 = time()
|
68 |
|
|
response = mc.squery(query)
|
69 |
|
|
t2 = time()
|
70 |
4902
|
daigle
|
|
71 |
4906
|
daigle
|
if response.find("<resultset>") != -1:
|
72 |
|
|
debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (word, t2-t1))
|
73 |
|
|
else:
|
74 |
4910
|
daigle
|
debug("[%s] -- ERROR: %s " % (word, response))
|
75 |
4902
|
daigle
|
|
76 |
4906
|
daigle
|
iter_count = iter_count + 1
|
77 |
|
|
debug2("iter_count: %d, iterations: %d" % (iter_count, iterations))
|
78 |
|
|
if iter_count >= iterations:
|
79 |
|
|
sys.exit()
|
80 |
4902
|
daigle
|
|
81 |
4906
|
daigle
|
sleep(interval)
|
82 |
4902
|
daigle
|
|
83 |
|
|
dictionary_file.close()
|
84 |
|
|
output_file.close()
|