Project

General

Profile

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
run_time = str(time()).replace('.','')
18
19 4906 daigle
output_file_name = "./insert-" + letter + ".out"
20
output_file = open(output_file_name, 'w')
21
output_file.close()
22 4902 daigle
23
def debug (message):
24 4906 daigle
	output_file = open(output_file_name, 'a')
25 4902 daigle
	output_file.write(message + '\n')
26 4906 daigle
	output_file.close()
27 4902 daigle
28
def debug1 (message):
29 4906 daigle
	if debug_level > 0:
30
		output_file = open(output_file_name, 'a')
31 4902 daigle
		output_file.write(message + '\n')
32 4906 daigle
		output_file.close()
33 4902 daigle
34
def debug2 (message):
35 4906 daigle
	if debug_level > 1:
36
		output_file = open(output_file_name, 'a')
37 4902 daigle
		output_file.write(message + '\n')
38 4906 daigle
		output_file.close()
39 4902 daigle
40
def debug3 (message):
41 4906 daigle
	if debug_level > 2:
42
		output_file = open(output_file_name, 'a')
43 4902 daigle
		output_file.write(message + '\n')
44 4906 daigle
		output_file.close()
45 4902 daigle
46 4906 daigle
dictionary_file_name = './dictionary-' + letter + '.txt'
47
dictionary_file = open(dictionary_file_name, 'r')
48 4902 daigle
49
iter_count = 0
50
51
debug("************************************************** ")
52 4906 daigle
debug("Starting insert-load-test for ")
53 4902 daigle
debug("       letter: $letter ")
54
debug("       iterations: $iterations ")
55
debug("       interval: $interval ")
56 4906 daigle
debug("       host: $host ")
57 4902 daigle
debug("************************************************** ")
58
59
# Initialize a metacat client connection and log in as test user
60
t1 = time()
61 8265 leinfelder
mc = metacat.MetacatClient(host,'/metacat/metacat')
62 4902 daigle
debug("[test] -- Processing Login")
63
response = mc.login('test', 'test', 'NCEAS')
64
t2 = time()
65
66
if (response):
67
	debug("[test] -- SUCCESS: elapsed time: %.5f seconds" %  (t2-t1))
68
else:
69
	debug("[test] -- ERROR: could not log in")
70
71
insert_template_file = open('insert.xml.tmpl', 'r')
72
insert_template = insert_template_file.read()
73
insert_template_file.close
74
75
for line in dictionary_file:
76 4906 daigle
	word = line.strip()
77 4902 daigle
78 4906 daigle
	debug3("word: " + word)
79
	debug3("run time: " + run_time)
80
	debug3("iter count: " + str(iter_count))
81
	docid = word + run_time + '.' + str(iter_count) + '.1'
82
	doc = insert_template.replace("@!docid!@", docid)
83
	t1 = time()
84 4902 daigle
85 4906 daigle
	debug("[%s] -- Processing Insert" % (docid))
86
	response = mc.insert(docid, doc)
87
	t2 = time()
88 4902 daigle
89 4906 daigle
	if (response.lower().find('<error>') == -1):
90
		debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (docid, t2-t1))
91
	else:
92
		debug("[%s] -- ERROR: %s" % (docid, response))
93 4902 daigle
94 4906 daigle
	iter_count = iter_count + 1
95
	debug2("iter_count: %d, iterations: %d" % (iter_count, iterations))
96
	if iter_count >= iterations:
97
		sys.exit()
98 4902 daigle
99 4906 daigle
	sleep(interval)
100 4902 daigle
101
dictionary_file.close()
102
output_file.close()