1
// **********************************************************************
3
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
5
// This copy of Ice is licensed to you under the terms described in the
6
// ICE_LICENSE file included in this distribution.
8
// **********************************************************************
10
#include <IceUtil/Thread.h>
12
#include <IceGrid/Observer.h>
13
#include <IceGrid/Admin.h>
14
#include <IceGrid/Registry.h>
15
#include <TestCommon.h>
22
using namespace IceGrid;
24
class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
28
SessionKeepAliveThread(const IceGrid::AdminSessionPrx& session, long timeout) :
30
_timeout(IceUtil::Time::seconds(timeout)),
48
_session->keepAlive();
50
catch(const Ice::Exception&)
67
IceGrid::AdminSessionPrx _session;
68
const IceUtil::Time _timeout;
71
typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr;
74
allTests(const Ice::CommunicatorPtr& communicator)
76
RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(communicator->stringToProxy("IceGrid/Registry"));
78
AdminSessionPrx session = registry->createAdminSession("foo", "bar");
80
SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout()/2);
83
AdminPrx admin = session->getAdmin();
86
admin->startServer("Test.IcePatch2");
87
admin->startServer("IcePatch2-Direct");
89
cout << "testing distributions... " << flush;
92
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all"));
93
test(test->getServerFile("rootfile") == "");
97
admin->patchServer("server-all", true);
99
catch(const PatchException& ex)
101
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
105
test(test->getServerFile("rootfile") == "rootfile");
106
test(test->getServerFile("dir1/file1") == "dummy-file1");
107
test(test->getServerFile("dir1/file2") == "dummy-file2");
108
test(test->getServerFile("dir2/file3") == "dummy-file3");
110
test(test->getApplicationFile("rootfile") == "");
111
test(test->getApplicationFile("dir1/file1") == "");
112
test(test->getApplicationFile("dir1/file2") == "");
113
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
117
admin->patchServer("server-all-direct", true);
119
catch(const PatchException& ex)
121
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
124
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct"));
126
test(test->getServerFile("rootfile") == "rootfile");
127
test(test->getServerFile("dir1/file1") == "dummy-file1");
128
test(test->getServerFile("dir1/file2") == "dummy-file2");
129
test(test->getServerFile("dir2/file3") == "dummy-file3");
131
test(test->getApplicationFile("rootfile") == "");
132
test(test->getApplicationFile("dir1/file1") == "");
133
test(test->getApplicationFile("dir1/file2") == "");
134
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
138
admin->patchApplication("Test", true);
140
catch(const PatchException& ex)
142
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
145
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1"));
147
test(test->getServerFile("rootfile") == "");
148
test(test->getServerFile("dir1/file1") == "dummy-file1");
149
test(test->getServerFile("dir1/file2") == "dummy-file2");
150
test(test->getServerFile("dir2/file3") == "");
152
test(test->getApplicationFile("rootfile") == "");
153
test(test->getApplicationFile("dir1/file1") == "");
154
test(test->getApplicationFile("dir1/file2") == "");
155
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
157
cout << "ok" << endl;
159
admin->stopServer("Test.IcePatch2");
160
admin->stopServer("IcePatch2-Direct");
162
ApplicationUpdateDescriptor update;
163
update.name = "Test";
164
update.variables["icepatch.directory"] = "${test.dir}/data/updated";
165
admin->updateApplication(update);
167
admin->startServer("Test.IcePatch2");
168
admin->startServer("IcePatch2-Direct");
170
cout << "testing distributions after update... " << flush;
173
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all"));
174
test(test->getServerFile("rootfile") == "rootfile");
178
admin->patchServer("server-all", true);
180
catch(const PatchException& ex)
182
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
186
test(test->getServerFile("rootfile") == "rootfile-updated!");
187
test(test->getServerFile("dir1/file1") == "");
188
test(test->getServerFile("dir1/file2") == "dummy-file2-updated!");
189
test(test->getServerFile("dir2/file3") == "dummy-file3");
190
test(test->getServerFile("dir2/file4") == "dummy-file4");
192
test(test->getApplicationFile("rootfile") == "");
193
test(test->getApplicationFile("dir1/file1") == "");
194
test(test->getApplicationFile("dir1/file2") == "");
195
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
196
test(test->getApplicationFile("dir2/file4") == "dummy-file4");
200
admin->patchServer("server-all-direct", true);
202
catch(const PatchException& ex)
204
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
207
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct"));
209
test(test->getServerFile("rootfile") == "rootfile-updated!");
210
test(test->getServerFile("dir1/file1") == "");
211
test(test->getServerFile("dir1/file2") == "dummy-file2-updated!");
212
test(test->getServerFile("dir2/file3") == "dummy-file3");
213
test(test->getServerFile("dir2/file4") == "dummy-file4");
215
test(test->getApplicationFile("rootfile") == "");
216
test(test->getApplicationFile("dir1/file1") == "");
217
test(test->getApplicationFile("dir1/file2") == "");
218
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
219
test(test->getApplicationFile("dir2/file4") == "dummy-file4");
223
admin->patchApplication("Test", true);
225
catch(const PatchException& ex)
227
copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
230
test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1"));
232
test(test->getServerFile("rootfile") == "");
233
test(test->getServerFile("dir1/file1") == "");
234
test(test->getServerFile("dir1/file2") == "dummy-file2-updated!");
235
test(test->getServerFile("dir2/file3") == "");
236
test(test->getServerFile("dir2/file4") == "");
238
test(test->getApplicationFile("rootfile") == "");
239
test(test->getApplicationFile("dir1/file1") == "");
240
test(test->getApplicationFile("dir1/file2") == "");
241
test(test->getApplicationFile("dir2/file3") == "dummy-file3");
242
test(test->getApplicationFile("dir2/file4") == "dummy-file4");
244
cout << "ok" << endl;
246
admin->stopServer("Test.IcePatch2");
247
admin->stopServer("IcePatch2-Direct");
249
keepAlive->destroy();
250
keepAlive->getThreadControl().join();