summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/ImplRepo/locked/run_test.pl
blob: 8b49865299cb5feb2f5bc014dd9c0b5c6603e201 (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
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

$status = 0;
$debug_level = '0';

foreach $i (@ARGV) {
    if ($i eq '-debug') {
        $debug_level = '10';
    }
}

my $imr = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
my $ti = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";

################################################################################
# Program locations

$imriorfile = "imr_locator.ior";
$imrpfile = "persistence.dat";

my $imr_imriorfile = $imr->LocalFile ($imriorfile);
my $ti_imriorfile = $ti->LocalFile ($imriorfile);
my $imr_imrpfile = $imr->LocalFile ($imrpfile);

$imr->DeleteFile ($imriorfile);
$ti->DeleteFile ($imriorfile);
$imr->DeleteFile ($imrpfile);


$IMR = $imr->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_locator");
$TI = $ti->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_imr");

# We want the tao_imr executable to be found exactly in the path
# given, without being modified by the value of -ExeSubDir.
# So, we tell its Process object to ignore the setting of -ExeSubDir.

$TI->IgnoreExeSubDir (1);

################################################################################

$imr->DeleteFile ($imriorfile);
$ti->DeleteFile ($imriorfile);
$imr->DeleteFile ($imrpfile);

################################################################################
## Start the implementation Repository Locator

$IMR->Arguments ("-p $imr_imrpfile -o $imr_imriorfile -d 2 -ORBDebugLevel = $debug_level");
$IMR_status = $IMR->Spawn ();
if ($IMR_status != 0) {
    print STDERR "ERROR: ImplRepo Service returned $IMR_status\n";
    exit 1;
}
if ($imr->WaitForFileTimed ($imriorfile,$imr->ProcessStartWaitInterval()) == -1) {
    print STDERR "ERROR: cannot find file <$imr_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}
if ($imr->GetFile ($imriorfile) == -1) {
    print STDERR "ERROR: cannot retrieve file <$imr_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}
if ($ti->PutFile ($imriorfile) == -1) {
    print STDERR "ERROR: cannot set file <$ti_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}

################################################################################
## Test out commands on the IMR

print "===== Adding a server\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile ".
               " add Foo -c foobarbaz");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
if ($TI_status != 0) {
    print STDERR "ERROR: tao_imr (add) returned $TI_status\n";
    $status = 1;
}

print "===== Updating a server\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " update Foo -w foodir" );

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
if ($TI_status != 0) {
    print STDERR "ERROR: tao_imr (update) returned $TI_status\n";
    $status = 1;
}

print "===== Removing a server\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " remove Foo");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
if ($TI_status != 0) {
    print STDERR "ERROR: tao_imr (remove) returned $TI_status\n";
    $status = 1;
}

print "===== Re-adding a server\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " add Foo -c foobarbaz");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
if ($TI_status != 0) {
    print STDERR "ERROR: tao_imr (add) returned $TI_status\n";
    $status = 1;
}

################################################################################
## Kill the IMR
print "===== Killing the ImR and restarting in locked mode.\n";

$IMR_status = $IMR->TerminateWaitKill ($imr->ProcessStopWaitInterval());
if ($IMR_status != 0) {
    print STDERR "ERROR: IMR returned $IMR_status\n";
    $status = 1;
}

$imr->DeleteFile ($imriorfile);
$ti->DeleteFile ($imriorfile);

################################################################################
## Restart the Implementation Repository in locked mode.

$IMR->Arguments ("-l -p $imr_imrpfile -o $imr_imriorfile -d 2");
$IMR_status = $IMR->Spawn ();
if ($IMR_status != 0) {
    print STDERR "ERROR: ImplRepo Service returned $IMR_status\n";
    exit 1;
}
if ($imr->WaitForFileTimed ($imriorfile,$imr->ProcessStartWaitInterval()) == -1) {
    print STDERR "ERROR: cannot find file <$imr_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}
if ($imr->GetFile ($imriorfile) == -1) {
    print STDERR "ERROR: cannot retrieve file <$imr_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}
if ($ti->PutFile ($imriorfile) == -1) {
    print STDERR "ERROR: cannot set file <$ti_imriorfile>\n";
    $IMR->Kill (); $IMR->TimedWait (1);
    exit 1;
}

################################################################################
## Test out commands on the IMR

print "===== Listing registered servers.\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " list");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
if ($TI_status != 0) {
    print STDERR "ERROR: tao_imr (list) returned $TI_status\n";
    $status = 1;
}

print "===== Adding a server (should fail)\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " add Foo2 -c foobarbaz");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());

## Note : If you receive a 5 (NOT_FOUND) then it's likely that
## persistence isn't working correctly.
if ($TI_status != 2) { # NO_PERMISSION
    print STDERR "ERROR: tao_imr (add) returned $TI_status\n";
    $status = 1;
}

print "===== Updating a server (should fail)\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " update Foo -w foodir");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());

if ($TI_status != 2) { # NO_PERMISSION
    print STDERR "ERROR: tao_imr (update) returned $TI_status\n";
    $status = 1;
}

print "===== Removing a server (should fail)\n";

$TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile"
                    . " remove Foo");

$TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());

if ($TI_status != 2) { # NO_PERMISSION
    print STDERR "ERROR: tao_imr (remove) returned $TI_status\n";
    $status = 1;
}

################################################################################
## Kill the IMR

$IMR_status = $IMR->TerminateWaitKill ($imr->ProcessStopWaitInterval());
if ($IMR_status != 0) {
    print STDERR "ERROR: IMR returned $IMR_status\n";
    $status = 1;
}

$imr->DeleteFile ($imriorfile);
$ti->DeleteFile ($imriorfile);
$imr->DeleteFile ($imrpfile);

exit $status;