Project

General

Profile

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=0 for no debugging.  Set it to 0 - 3 for increasing amounts of debug.
15
debug=0
16

    
17
output_file = "./squery-" + letter + ".out"
18
output_file = open(output_file, 'w')
19

    
20
def debug (message):
21
	output_file.write(message + '\n')
22
	
23
def debug1 (message):
24
	if debug > 0:
25
		output_file.write(message + '\n')
26

    
27
def debug2 (message):
28
	if debug > 1:
29
		output_file.write(message + '\n')
30

    
31
def debug3 (message):
32
	if debug > 2:
33
		output_file.write(message + '\n')
34

    
35
dictionary_file = open('./dictionary.txt', 'r')
36

    
37
iter_count = 0
38

    
39
debug("************************************************** ")
40
debug("Starting squery-load-test for ") 
41
debug("       letter: $letter ") 
42
debug("       iterations: $iterations ")
43
debug("       interval: $interval ")
44
debug("************************************************** ")
45

    
46
mc = metacat.MetacatClient(host,'/knb/metacat')
47

    
48
query_template_file = open('squery.xml.tmpl', 'r')
49
query_template = query_template_file.read()
50
query_template_file.close
51

    
52
for line in dictionary_file:
53
	if line.lower().startswith(letter.lower()):
54
		word = line.strip()
55
		debug("[%s] -- Processing Search" % (word))
56
		query = query_template.replace("@!search-word!@", word)
57
		t1 = time()
58
		response = mc.squery(query)
59
		t2 = time()
60

    
61
		if response.find("<resultset>") != -1:
62
			debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (word, t2-t1))
63
		else:
64
			debug("[%s] -- ERROR: " % (word), response)
65
			
66
		iter_count = iter_count + 1
67
		debug3("iter_count: %d, iterations: %d" % (iter_count, iterations))
68
		if iter_count >= iterations:		
69
			sys.exit()
70
			
71
		sleep(interval)
72
	
73
dictionary_file.close()
74
output_file.close()
75

    
(6-6/7)