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
run_time = str(time()).replace('.','')
18

    
19
output_file = "./insert-" + letter + ".out"
20
output_file = open(output_file, 'w')
21

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

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

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

    
37
dictionary_file = open('./dictionary.txt', 'r')
38

    
39
iter_count = 0
40

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

    
48
# Initialize a metacat client connection and log in as test user
49
t1 = time()
50
mc = metacat.MetacatClient(host,'/knb/metacat')
51
debug("[test] -- Processing Login")
52
response = mc.login('test', 'test', 'NCEAS')
53
t2 = time()
54

    
55
if (response):
56
	debug("[test] -- SUCCESS: elapsed time: %.5f seconds" %  (t2-t1))
57
else:
58
	debug("[test] -- ERROR: could not log in")
59

    
60
insert_template_file = open('insert.xml.tmpl', 'r')
61
insert_template = insert_template_file.read()
62
insert_template_file.close
63

    
64
for line in dictionary_file:
65
	if line.lower().startswith(letter.lower()):
66
		word = line.strip()
67
		
68
		debug3("word: " + word)
69
		debug3("run time: " + run_time)
70
		debug3("iter count: " + str(iter_count))
71
		docid = word + run_time + '.' + str(iter_count) + '.1'
72
		doc = insert_template.replace("@!docid!@", docid)
73
		t1 = time()
74

    
75
		debug("[%s] -- Processing Insert" % (docid))
76
		response = mc.insert(docid, doc)
77
		t2 = time()
78

    
79
		if (response.lower().find('<error>') == -1):
80
			debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (docid, t2-t1))
81
		else:
82
			debug("[%s] -- ERROR: %s" % (docid, response))
83
		
84
		iter_count = iter_count + 1
85
		debug3("iter_count: %d, iterations: %d" % (iter_count, iterations))
86
		if iter_count >= iterations:		
87
			sys.exit()
88
			
89
		sleep(interval)
90
	
91
dictionary_file.close()
92
output_file.close()
(2-2/7)