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
prefix = 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 = "./read-" + prefix + ".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
iter_count = 0
47

    
48
debug("************************************************** ")
49
debug("Starting read-load-test for ") 
50
debug("       letter: $letter ") 
51
debug("       iterations: $iterations ")
52
debug("       interval: $interval ")
53
debug("       host: $host ")
54
debug("************************************************** ")
55

    
56
# Initialize a metacat client connection and log in as test user
57
t1 = time()
58
mc = metacat.MetacatClient(host,'/metacat/metacat')
59
debug("[test] -- Processing Login")
60
response = mc.login('test', 'test', 'NCEAS')
61
t2 = time()
62

    
63
if (response):
64
	debug("[test] -- SUCCESS: elapsed time: %.5f seconds" %  (t2-t1))
65
else:
66
	debug("[test] -- ERROR: could not log in")
67

    
68
# Insert a document
69
insert_template_file = open('insert.xml.tmpl', 'r')
70
insert_template = insert_template_file.read()
71
insert_template_file.close
72

    
73
t1 = time()
74
docid = 'readtest-' + prefix + run_time + '.1.1'
75
doc = insert_template.replace("@!docid!@", docid)
76
debug("[%s] -- Processing Insert" % (docid))
77
response = mc.insert(docid, doc)
78
t2 = time()
79

    
80
if (response.lower().find('<error>') == -1):
81
	debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (docid, t2-t1))
82
else:
83
	debug("[%s] -- ERROR: %s" % (docid, response))
84
t2 = time()
85

    
86
for i in range(0,iterations):
87
	t1 = time()
88

    
89
	debug("[%s] -- Processing Read" % (docid))
90
	response = mc.read(docid)
91
	t2 = time()
92

    
93
	if (response.lower().find('<error>') == -1):
94
		debug("[%s] -- SUCCESS: elapsed time: %.5f seconds" % (docid, t2-t1))
95
	else:
96
		debug("[%s] -- ERROR: %s" % (docid, response))
97
		
98
	iter_count = iter_count + 1
99
	debug2("iter_count: %d, iterations: %d" % (iter_count, iterations))
100
			
101
	sleep(interval)
102
	
103
output_file.close()
(6-6/8)