1
|
#!/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
|
# set debug_level=0 for no debugging. Set it to 0 - 3 for increasing amounts of debug.
|
15
|
debug_level=2
|
16
|
|
17
|
output_file_name = "./squery-" + letter + ".out"
|
18
|
output_file = open(output_file_name, 'w')
|
19
|
output_file.close()
|
20
|
|
21
|
def debug (message):
|
22
|
output_file = open(output_file_name, 'a')
|
23
|
output_file.write(message + '\n')
|
24
|
output_file.close()
|
25
|
|
26
|
def debug1 (message):
|
27
|
if debug_level > 0:
|
28
|
output_file = open(output_file_name, 'a')
|
29
|
output_file.write(message + '\n')
|
30
|
output_file.close()
|
31
|
|
32
|
def debug2 (message):
|
33
|
if debug_level > 1:
|
34
|
output_file = open(output_file_name, 'a')
|
35
|
output_file.write(message + '\n')
|
36
|
output_file.close()
|
37
|
|
38
|
def debug3 (message):
|
39
|
if debug_level > 2:
|
40
|
output_file = open(output_file_name, 'a')
|
41
|
output_file.write(message + '\n')
|
42
|
output_file.close()
|
43
|
|
44
|
dictionary_file_name = './dictionary-' + letter + '.txt'
|
45
|
dictionary_file = open(dictionary_file_name, 'r')
|
46
|
|
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
|
debug(" host: $host ")
|
55
|
debug("************************************************** ")
|
56
|
|
57
|
mc = metacat.MetacatClient(host,'/metacat/metacat')
|
58
|
|
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
|
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
|
|
71
|
if response.find("<resultset>") != -1:
|
72
|
debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (word, t2-t1))
|
73
|
else:
|
74
|
debug("[%s] -- ERROR: %s " % (word, response))
|
75
|
|
76
|
iter_count = iter_count + 1
|
77
|
debug2("iter_count: %d, iterations: %d" % (iter_count, iterations))
|
78
|
if iter_count >= iterations:
|
79
|
sys.exit()
|
80
|
|
81
|
sleep(interval)
|
82
|
|
83
|
dictionary_file.close()
|
84
|
output_file.close()
|
85
|
|