summaryrefslogtreecommitdiff
path: root/cpp/test/IceStorm/stress/run.py
blob: 0bf39f16d9c18db2a33f16ab6d0a52717369dbac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import os, sys, time, threading, re

for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
    toplevel = os.path.normpath(toplevel)
    if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")):
        break
else:
    raise "can't find toplevel directory!"

sys.path.append(os.path.join(toplevel, "config"))
import TestUtil

name = os.path.join("IceStorm", "stress")
testdir = os.path.join(toplevel, "test", name)

exedir = os.path.join(toplevel, "test", "IceStorm", "stress")

iceBox = TestUtil.getIceBox(exedir)
iceBoxAdmin = os.path.join(toplevel, "bin", "iceboxadmin")
iceStormAdmin = os.path.join(toplevel, "bin", "icestormadmin")

iceBoxEndpoints = ' --Ice.OA.IceBox.ServiceManager.Endpoints="default -p 12010" --Ice.Default.Locator='

iceStormService = " --IceBox.Service.IceStorm=IceStormService," + TestUtil.getIceSoVersion() + ":createIceStorm" + \
                  ' --Ice.OA.IceStorm.TopicManager.Endpoints="default -p 12011"' + \
                  ' --Ice.OA.IceStorm.Publish.Endpoints="default -p 12012"' + \
                  ' --IceStorm.InstanceName=TestIceStorm1 ' + \
                  ' --IceStorm.Discard.Interval=2' + \
                  ' --IceBox.PrintServicesReady=IceStorm' + \
                  " --IceBox.InheritContainerProperties=1"
iceStormReference = ' --IceStorm.TopicManager.Proxy="TestIceStorm1/TopicManager: default -p 12011"'

iceBoxEndpoints2 = ' --Ice.OA.IceBox.ServiceManager.Endpoints="default -p 12020" --Ice.Default.Locator='

iceStormService2 = " --IceBox.Service.IceStorm=IceStormService," + TestUtil.getIceSoVersion() + ":createIceStorm" + \
                  ' --Ice.OA.IceStorm.TopicManager.Endpoints="default -p 12021"' + \
                  ' --Ice.OA.IceStorm.Publish.Endpoints="default -p 12022"' + \
                  ' --IceStorm.InstanceName=TestIceStorm2 ' + \
                  ' --IceStorm.Discard.Interval=2' + \
                  ' --IceBox.PrintServicesReady=IceStorm' + \
                  " --IceBox.InheritContainerProperties=1"
iceStormReference2 = ' --IceStorm.TopicManager.Proxy="TestIceStorm2/TopicManager: default -p 12021"'

adminIceStormReference = ' --IceStormAdmin.TopicManager.Proxy="TestIceStorm1/TopicManager: default -p 12011" ' + \
    '--IceStormAdmin.TopicManager.Proxy2="TestIceStorm2/TopicManager: default -p 12021"'

def doTest(subOpts, pubOpts):
    global testdir
    global iceStormReference
    global iceStormReference2

    publisher = os.path.join(toplevel, "test", "IceStorm", "stress", "publisher")
    subscriber = os.path.join(toplevel, "test", "IceStorm", "stress", "subscriber")

    subscriberPipes = []
    if type(subOpts) != type([]):
        subOpts = [ subOpts ]
    for opts in subOpts:
        command = subscriber + TestUtil.clientServerOptions + r' ' + opts
        if TestUtil.debug:
            print "(" + command + ")",
            sys.stdout.flush()
        pipe = os.popen(command + " 2>&1")
        TestUtil.getServerPid(pipe)
        TestUtil.getAdapterReady(pipe)
        subscriberPipes.append(pipe)

    command = publisher + TestUtil.clientOptions + iceStormReference + r' ' + pubOpts
    if TestUtil.debug:
        print "(" + command + ")",
        sys.stdout.flush()
    publisherPipe = os.popen(command + " 2>&1")

    TestUtil.printOutputFromPipe(publisherPipe)

    publisherStatus = TestUtil.closePipe(publisherPipe)
    if publisherStatus:
        print "(publisher failed)",
        return publisherStatus
    for p in subscriberPipes:
        try:
            sys.stdout.flush()
            subscriberStatus = TestUtil.specificServerStatus(p, 30)
        except:
            print "(subscriber failed)",
            return 1
        if subscriberStatus:
            print "(subscriber failed)",
            return subscriberStatus

    return 0

def startServers():
    global iceBox
    global iceBoxEndpoints
    global iceBoxEndpoints2
    global iceStormService
    global iceStormService2
    global iceStormDBEnv
    global iceStormDBEnv2
    print "starting icestorm services...",
    sys.stdout.flush()
    # Clear the idle timeout otherwise the IceBox ThreadPool will timeout.
    command = iceBox + TestUtil.clientServerOptions + iceBoxEndpoints + iceStormService + iceStormDBEnv + ' --Ice.ServerIdleTime=0'
    if TestUtil.debug:
        print "(" + command + ")",
        sys.stdout.flush()
    iceBoxPipe = os.popen(command + " 2>&1")
    TestUtil.getServerPid(iceBoxPipe)
    TestUtil.waitServiceReady(iceBoxPipe, "IceStorm")
    command = iceBox + TestUtil.clientServerOptions + iceBoxEndpoints2 + iceStormService2 + iceStormDBEnv2 + ' --Ice.ServerIdleTime=0'
    if TestUtil.debug:
        print "(" + command + ")",
        sys.stdout.flush()
    iceBoxPipe2 = os.popen(command + " 2>&1")
    TestUtil.getServerPid(iceBoxPipe2)
    TestUtil.waitServiceReady(iceBoxPipe2, "IceStorm")
    print "ok"

    return iceBoxPipe, iceBoxPipe2

def stopServers(p1, p2 = None):
    global iceBox
    global iceBoxAdmin
    global iceBoxEndpoints
    global iceBoxEndpoints2
    print "shutting down icestorm services...",
    sys.stdout.flush()
    command = iceBoxAdmin + TestUtil.clientOptions + iceBoxEndpoints + r' shutdown'
    if TestUtil.debug:
        print "(" + command + ")",
        sys.stdout.flush()
    pipe = os.popen(command + " 2>&1")
    status = TestUtil.closePipe(pipe)
    if status or TestUtil.specificServerStatus(p1):
        TestUtil.killServers()
        sys.exit(1)
    if p2:
        command = iceBoxAdmin + TestUtil.clientOptions + iceBoxEndpoints2 + r' shutdown'
        if TestUtil.debug:
            print "(" + command + ")",
            sys.stdout.flush()
        pipe = os.popen(command + " 2>&1")
        status = TestUtil.closePipe(pipe)
        if status or TestUtil.specificServerStatus(p2):
            TestUtil.killServers()
            sys.exit(1)
    print "ok"

dbHome = os.path.join(testdir, "db")
TestUtil.cleanDbDir(dbHome)
iceStormDBEnv=" --Freeze.DbEnv.IceStorm.DbHome=" + dbHome

dbHome2 = os.path.join(testdir, "db2")
TestUtil.cleanDbDir(dbHome2)
iceStormDBEnv2=" --Freeze.DbEnv.IceStorm.DbHome=" + dbHome2

server1, server2 = startServers()

print "setting up the topics...",
sys.stdout.flush()
command = iceStormAdmin + TestUtil.clientOptions + adminIceStormReference + \
    r' -e "create TestIceStorm1/fed1 TestIceStorm2/fed1; link TestIceStorm1/fed1 TestIceStorm2/fed1"'
if TestUtil.debug:
    print "(" + command + ")",
    sys.stdout.flush()
iceStormAdminPipe = os.popen(command + " 2>&1")
iceStormAdminStatus = TestUtil.closePipe(iceStormAdminPipe)
if iceStormAdminStatus:
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 5000 ordered events... ",
sys.stdout.flush()
status = doTest('--events 5000 --qos "reliability,ordered" ' + iceStormReference, '--events 5000')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 5000 ordered events across a link... ",
sys.stdout.flush()
status = doTest('--events 5000 --qos "reliability,ordered" ' + iceStormReference2, '--events 5000')
if status:
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered events... ",
sys.stdout.flush()
status = doTest('--events 20000 ' + iceStormReference, '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered events across a link... ",
sys.stdout.flush()
status = doTest('--events 20000 ' + iceStormReference2, '--events 20000 --oneway')
if status:
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered batch events... ",
sys.stdout.flush()
status = doTest('--events 20000 --qos "reliability,batch" ' + iceStormReference, '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered batch events across a link... ",
sys.stdout.flush()
status = doTest('--events 20000 --qos "reliability,batch" ' + iceStormReference2, '--events 20000 --oneway')
if status:
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered events with slow subscriber... ",
status = doTest(['--events 2 --slow ' + iceStormReference, '--events 20000 ' + iceStormReference], '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered events with slow subscriber & link... ",
status = doTest(['--events 2 --slow' + iceStormReference, '--events 20000' + iceStormReference, '--events 2 --slow' + iceStormReference2, '--events 20000' + iceStormReference2], '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

#
# The erratic tests emit lots of connection warnings so they are
# disabled here. The IceStorm servers are stopped and restarted so the
# settings will take effect.
#
TestUtil.clientOptions = TestUtil.clientOptions + ' --Ice.Warn.Connections=0'
TestUtil.serverOptions = TestUtil.serverOptions + ' --Ice.Warn.Connections=0'
TestUtil.clientServerOptions = TestUtil.clientServerOptions + ' --Ice.Warn.Connections=0'
TestUtil.collocatedOptions = TestUtil.collocatedOptions + ' --Ice.Warn.Connections=0'

stopServers(server1, server2)
server1, server2 = startServers()

print "Sending 20000 unordered events with erratic subscriber... ",
status = doTest(['--erratic 10 --events 20000' + iceStormReference, '--events 20000 ' + iceStormReference], '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

print "Sending 20000 unordered events with erratic subscriber across a link... ",
status = doTest(['--erratic 10 --events 20000' + iceStormReference, '--events 20000 ' + iceStormReference, \
                 '--erratic 10 --events 20000' + iceStormReference2, '--events 20000 ' + iceStormReference2], \
                '--events 20000 --oneway')
if status:
    print "failed!"
    TestUtil.killServers()
    sys.exit(1)
print "ok"

#
# Shutdown icestorm.
#
stopServers(server1, server2)
if TestUtil.serverStatus():
    TestUtil.killServers()
    sys.exit(1)

sys.exit(0)