summaryrefslogtreecommitdiff
path: root/cpp/test/IceStorm/stress/run.py
blob: 5ba7d81fd2cbaa9d7664dcebf687a54e520b690a (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
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2013 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

path = [ ".", "..", "../..", "../../..", "../../../.." ]
head = os.path.dirname(sys.argv[0])
if len(head) > 0:
    path = [os.path.join(head, p) for p in path]
path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
if len(path) == 0:
    raise RuntimeError("can't find toplevel directory!")
sys.path.append(os.path.join(path[0], "scripts"))
import TestUtil, IceStormUtil

iceStormAdmin = TestUtil.getIceStormAdmin()

publisher = os.path.join(os.getcwd(), "publisher")
subscriber = os.path.join(os.getcwd(), "subscriber")

targets = []
if TestUtil.appverifier:
    targets = [TestUtil.getIceBox(), publisher, subscriber, TestUtil.getIceBoxAdmin(), \
               TestUtil.getIceStormAdmin()]
    TestUtil.setAppVerifierSettings(targets, cwd = os.getcwd())

def doTest(server1, server2, subOpts, pubOpts):

    subscriberProcs = []
    if type(subOpts) != type([]):
        subOpts = [ subOpts ]
    for opts in subOpts:
        # We don't want the subscribers to time out.
        proc = TestUtil.startServer(subscriber, ' --Ice.ServerIdleTime=0 ' + opts)
        subscriberProcs.append(proc)

    publisherProc = TestUtil.startClient(publisher, server1.reference() + r' ' + pubOpts)
    publisherProc.waitTestSuccess()
    for p in subscriberProcs:
        sys.stdout.flush()
        p.waitTestSuccess()

    return 0

def runAdmin(cmd, desc = None):
    global iceStormAdmin
    global iceStormAdminReference
    if desc:
        sys.stdout.write(desc + " ")
        sys.stdout.flush()
    proc = TestUtil.startClient(iceStormAdmin, adminIceStormReference + r' -e "%s"' % cmd, startReader = True)
    proc.waitTestSuccess()
    if desc:
        print("ok")

def runtest(type):
    # Clear the idle timeout otherwise the IceBox ThreadPool will timeout.
    server1 = IceStormUtil.init(TestUtil.toplevel, os.getcwd(), type, dbDir = "db", instanceName = "TestIceStorm1",
                                port = 12000)
    server2 = IceStormUtil.init(TestUtil.toplevel, os.getcwd(), type, dbDir = "db2", instanceName = "TestIceStorm2",
                                port = 12500)
    global adminIceStormReference
    adminIceStormReference = ' --IceStormAdmin.TopicManager.Proxy="%s" --IceStormAdmin.TopicManager.Proxy2="%s"' % (
        server1.proxy(), server2.proxy())

    sys.stdout.write("starting icestorm services... ")
    sys.stdout.flush()
    server1.start(echo=False)
    server2.start(echo=False)
    print("ok")

    runAdmin("create TestIceStorm1/fed1 TestIceStorm2/fed1", "setting up the topics...")

    sys.stdout.write("Sending 5000 ordered events... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 5000 --qos "reliability,ordered" ' + server1.reference(), '--events 5000')
    print("ok")

    runAdmin("link TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 5000 ordered events across a link... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 5000 --qos "reliability,ordered" ' + server2.reference(), '--events 5000')
    print("ok")

    runAdmin("unlink TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered events... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 20000 ' + server1.reference(), '--events 20000 --oneway')
    print("ok")

    runAdmin("link TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered events across a link... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 20000 ' + server2.reference(), '--events 20000 --oneway')
    print("ok")

    runAdmin("unlink TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered batch events... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 20000 --qos "reliability,batch" ' + server1.reference(), '--events 20000 --oneway')
    print("ok")

    runAdmin("link TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered batch events across a link... ")
    sys.stdout.flush()
    doTest(server1, server2, '--events 20000 --qos "reliability,batch" ' + server2.reference(), '--events 20000 --oneway')
    print("ok")

    runAdmin("unlink TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered events with slow subscriber... ")
    sys.stdout.flush()
    doTest(server1, server2, ['--events 2 --slow ' + server1.reference(), '--events 20000 ' + server1.reference()], '--events 20000 --oneway')
    print("ok")

    runAdmin("link TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered events with slow subscriber & link... ")
    sys.stdout.flush()
    doTest(server1, server2, ['--events 2 --slow' + server1.reference(), '--events 20000' + server1.reference(), '--events 2 --slow' + server2.reference(), '--events 20000' + server2.reference()], '--events 20000 --oneway')
    print("ok")

    sys.stdout.write("shutting down icestorm services... ")
    sys.stdout.flush()
    server1.stop()
    server2.stop()
    print("ok")

    sys.stdout.write("starting icestorm services... ")
    sys.stdout.flush()
    #
    # 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.
    #
    server1.start(echo=False, additionalOptions = ' --Ice.Warn.Connections=0')
    server2.start(echo=False, additionalOptions = ' --Ice.Warn.Connections=0')
    print("ok")

    runAdmin("unlink TestIceStorm1/fed1 TestIceStorm2/fed1")

    sys.stdout.write("Sending 20000 unordered events with erratic subscriber... ")
    sys.stdout.flush()
    doTest(server1, server2,
        [ '--erratic 5 --qos "reliability,ordered" --events 20000' + server1.reference(),
          '--erratic 5 --events 20000' + server1.reference(),
          '--events 20000' + server1.reference()],
          '--events 20000 --oneway')
    print("ok")

    runAdmin("link TestIceStorm1/fed1 TestIceStorm2/fed1")
    sys.stdout.write("Sending 20000 unordered events with erratic subscriber across a link... ")
    sys.stdout.flush()
    doTest(server1, server2, 
         [ '--events 20000' + server1.reference(),
           '--erratic 5 --qos "reliability,ordered" --events 20000 ' + server1.reference(),
           '--erratic 5 --events 20000 ' + server1.reference(),
           '--events 20000' + server2.reference(),
           '--erratic 5 --qos "reliability,ordered" --events 20000 ' + server2.reference(),
           '--erratic 5 --events 20000 ' + server2.reference()],
           '--events 20000 --oneway ')
    print("ok")

    #
    # Shutdown icestorm.
    #
    sys.stdout.write("shutting down icestorm services... ")
    sys.stdout.flush()
    server1.stop()
    server2.stop()
    print("ok")

runtest("persistent")
runtest("replicated")

if TestUtil.appverifier:
    TestUtil.appVerifierAfterTestEnd(targets, cwd = os.getcwd())