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
|
run_time = str(time()).replace('.','')
|
18
|
|
19
|
output_file_name = "./insert-" + letter + ".out"
|
20
|
output_file = open(output_file_name, 'w')
|
21
|
output_file.close()
|
22
|
|
23
|
def debug (message):
|
24
|
output_file = open(output_file_name, 'a')
|
25
|
output_file.write(message + '\n')
|
26
|
output_file.close()
|
27
|
|
28
|
def debug1 (message):
|
29
|
if debug_level > 0:
|
30
|
output_file = open(output_file_name, 'a')
|
31
|
output_file.write(message + '\n')
|
32
|
output_file.close()
|
33
|
|
34
|
def debug2 (message):
|
35
|
if debug_level > 1:
|
36
|
output_file = open(output_file_name, 'a')
|
37
|
output_file.write(message + '\n')
|
38
|
output_file.close()
|
39
|
|
40
|
def debug3 (message):
|
41
|
if debug_level > 2:
|
42
|
output_file = open(output_file_name, 'a')
|
43
|
output_file.write(message + '\n')
|
44
|
output_file.close()
|
45
|
|
46
|
dictionary_file_name = './dictionary-' + letter + '.txt'
|
47
|
dictionary_file = open(dictionary_file_name, 'r')
|
48
|
|
49
|
iter_count = 0
|
50
|
|
51
|
debug("************************************************** ")
|
52
|
debug("Starting insert-load-test for ")
|
53
|
debug(" letter: $letter ")
|
54
|
debug(" iterations: $iterations ")
|
55
|
debug(" interval: $interval ")
|
56
|
debug(" host: $host ")
|
57
|
debug("************************************************** ")
|
58
|
|
59
|
# Initialize a metacat client connection and log in as test user
|
60
|
t1 = time()
|
61
|
mc = metacat.MetacatClient(host,'/knb/metacat')
|
62
|
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
|
word = line.strip()
|
77
|
|
78
|
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
|
|
85
|
debug("[%s] -- Processing Insert" % (docid))
|
86
|
response = mc.insert(docid, doc)
|
87
|
t2 = time()
|
88
|
|
89
|
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
|
|
94
|
iter_count = iter_count + 1
|
95
|
debug2("iter_count: %d, iterations: %d" % (iter_count, iterations))
|
96
|
if iter_count >= iterations:
|
97
|
sys.exit()
|
98
|
|
99
|
sleep(interval)
|
100
|
|
101
|
dictionary_file.close()
|
102
|
output_file.close()
|