summaryrefslogtreecommitdiff
path: root/TAO/DevGuideExamples/Multithreading/GracefulShutdown/run_test.pl
blob: 7e96b25efeb3c60502b53727dd62f71742523461 (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
# $Id$

eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

use Env (ACE_ROOT);
use lib "$ACE_ROOT/bin";
use PerlACE::Run_Test;

$ior = PerlACE::LocalFile ("Messenger.ior");
unlink $ior;

$server_args = "-ORBEndpoint iiop://localhost";

# -------------------------------------------------------------------
# Test 1: Shutdown on client invocation
# -------------------------------------------------------------------

# start MessengerServer

print STDOUT "\n\nTest 1: Shutdown on client invocation.\n";
print STDOUT "Running MessengerServer...\n";
$S1 = new PerlACE::Process("MessengerServer", $server_args . " -x");
$S1->Spawn();

if (PerlACE::waitforfile_timed ($ior, $PerlACE::wait_interval_for_process_creation) == -1) {
    print STDERR "ERROR: cannot find file <$ior>\n";
    $S1->Kill(); 
    unlink $ior;
    exit 1;
}

# start MessengerClient

$C1 = new PerlACE::Process("MessengerClient", "-x");  
$C1->Spawn();

$C1RET = $C1->WaitKill(15);
$S1->Kill();

# clean-up 

unlink $ior;

if ($C1RET != 0) {
    print STDERR "ERROR: Client returned <$C1RET>\n";
    exit 1 ;
}  

# -------------------------------------------------------------------
# Test 2: Shutdown after <n> iterations through polling loop
# -------------------------------------------------------------------

# start MessengerServer

$iter = 10;
print STDOUT "\n\nTest 2: Shutdown after <$iter> iterations through polling loop.\n";
print STDOUT "Running MessengerServer...\n";
$S2 = new PerlACE::Process("MessengerServer", $server_args . " -p " . $iter);
$S2->Spawn();

if (PerlACE::waitforfile_timed ($ior, $PerlACE::wait_interval_for_process_creation) == -1) {
    print STDERR "ERROR: cannot find file <$ior>\n";
    $S2->Kill(); 
    unlink $ior;
    exit 1;
}

# start MessengerClient

$C2 = new PerlACE::Process("MessengerClient");  
$C2->Spawn();

$C2RET = $C2->WaitKill(15);
$S2->WaitKill($iter+5);

# clean-up 

unlink $ior;

if ($C2RET != 0) {
    print STDERR "ERROR: Client returned <$C2RET>\n";
    exit 1 ;
}  

# -------------------------------------------------------------------
# Test 3: Schedule a timer with the ORB's reactor to shutdown 
#         in <n> seconds
# -------------------------------------------------------------------

# start MessengerServer

$sec = 10;
print STDOUT "\n\nTest 3: Schedule a timer with the ORB's reactor to shutdown in <$sec> seconds.\n";
print STDOUT "Running MessengerServer...\n";
$S3 = new PerlACE::Process("MessengerServer", $server_args . " -t " . $sec);
$S3->Spawn();

if (PerlACE::waitforfile_timed ($ior, $PerlACE::wait_interval_for_process_creation) == -1) {
    print STDERR "ERROR: cannot find file <$ior>\n";
    $S3->Kill(); 
    unlink $ior;
    exit 1;
}

# start MessengerClient

$C3 = new PerlACE::Process("MessengerClient");  
$C3->Spawn();

$C3RET = $C3->WaitKill(15);
$S3->WaitKill($sec+5);

# clean-up 

unlink $ior;

if ($C3RET != 0) {
    print STDERR "ERROR: Client returned <$C3RET>\n";
    exit 1 ;
}  

# -------------------------------------------------------------------
# Test 4: Use the overloaded version of CORBA::ORB::run() that takes
#         an ACE_Time_Value parameter indicating how long run()
#         should process events before returning.
# -------------------------------------------------------------------

# start MessengerServer

print STDOUT "\n\nTest 4: Use the overloaded version of CORBA::ORB::run()\n";
print STDOUT "that takes an ACE_Time_Value parameter indicating how long\n";
print STDOUT "run() should process events before returning (<$sec> seconds).\n";
print STDOUT "Running MessengerServer...\n";
$S4 = new PerlACE::Process("MessengerServer", $server_args . " -r " . $sec);
$S4->Spawn();

if (PerlACE::waitforfile_timed ($ior, $PerlACE::wait_interval_for_process_creation) == -1) {
    print STDERR "ERROR: cannot find file <$ior>\n";
    $S4->Kill(); 
    unlink $ior;
    exit 1;
}

# start MessengerClient

$C4 = new PerlACE::Process("MessengerClient");  
$C4->Spawn();

$C4RET = $C4->WaitKill(15);
$S4->WaitKill($sec+5);

# clean-up 

unlink $ior;

if ($C4RET != 0) {
    print STDERR "ERROR: Client returned <$C4RET>\n";
    exit 1 ;
}  


# -------------------------------------------------------------------
# Test 5: Spawn a separate thread to shutdown the ORB on any
#         input from the console (terminal)
# -------------------------------------------------------------------

# start MessengerServer

print STDOUT "\n\nTest 5: Spawn a separate thread to shutdown the ORB on any input from the console (terminal).\n";
print STDOUT "Running MessengerServer...\n";
$S5 = new PerlACE::Process("MessengerServer", $server_args . " -c");
$S5->Spawn();

if (PerlACE::waitforfile_timed ($ior, $PerlACE::wait_interval_for_process_creation) == -1) {
    print STDERR "ERROR: cannot find file <$ior>\n";
    $S5->Kill(); 
    unlink $ior;
    exit 1;
}

# start MessengerClient

$C5 = new PerlACE::Process("MessengerClient");  
$C5->Spawn();

$C5RET = $C5->WaitKill(15);
print STDOUT "Enter any input to shutdown MessengerServer...\n";
$S5->WaitKill(15);

# clean-up 

unlink $ior;

if ($C5RET != 0) {
    print STDERR "ERROR: Client returned <$C5RET>\n";
    exit 1 ;
}  


exit 0;