~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to test/IceGrid/distribution/AllTests.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francisco Moya
  • Date: 2008-02-12 16:28:20 UTC
  • mfrom: (4.1.5 hardy)
  • Revision ID: james.westby@ubuntu.com-20080212162820-x3e046s7nmabeswv
Tags: 3.2.1-8
Added -g to global compilation flags (Closes: #465074).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// **********************************************************************
 
2
//
 
3
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
 
4
//
 
5
// This copy of Ice is licensed to you under the terms described in the
 
6
// ICE_LICENSE file included in this distribution.
 
7
//
 
8
// **********************************************************************
 
9
 
 
10
#include <IceUtil/Thread.h>
 
11
#include <Ice/Ice.h>
 
12
#include <IceGrid/Observer.h>
 
13
#include <IceGrid/Admin.h>
 
14
#include <IceGrid/Registry.h>
 
15
#include <TestCommon.h>
 
16
#include <Test.h>
 
17
 
 
18
#include <iterator>
 
19
 
 
20
using namespace std;
 
21
using namespace Test;
 
22
using namespace IceGrid;
 
23
 
 
24
class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
 
25
{
 
26
public:
 
27
 
 
28
    SessionKeepAliveThread(const IceGrid::AdminSessionPrx& session, long timeout) :
 
29
        _session(session),
 
30
        _timeout(IceUtil::Time::seconds(timeout)),
 
31
        _destroy(false)
 
32
    {
 
33
    }
 
34
 
 
35
    virtual void
 
36
    run()
 
37
    {
 
38
        Lock sync(*this);
 
39
        while(!_destroy)
 
40
        {
 
41
            timedWait(_timeout);
 
42
            if(_destroy)
 
43
            {
 
44
                break;
 
45
            }
 
46
            try
 
47
            {
 
48
                _session->keepAlive();
 
49
            }
 
50
            catch(const Ice::Exception&)
 
51
            {
 
52
                break;
 
53
            }
 
54
        }
 
55
    }
 
56
 
 
57
    void
 
58
    destroy()
 
59
    {
 
60
        Lock sync(*this);
 
61
        _destroy = true;
 
62
        notify();
 
63
    }
 
64
 
 
65
private:
 
66
 
 
67
    IceGrid::AdminSessionPrx _session;
 
68
    const IceUtil::Time _timeout;
 
69
    bool _destroy;
 
70
};
 
71
typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr;
 
72
 
 
73
void 
 
74
allTests(const Ice::CommunicatorPtr& communicator)
 
75
{
 
76
    RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(communicator->stringToProxy("IceGrid/Registry"));
 
77
    test(registry);
 
78
    AdminSessionPrx session = registry->createAdminSession("foo", "bar");
 
79
 
 
80
    SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout()/2);
 
81
    keepAlive->start();
 
82
 
 
83
    AdminPrx admin = session->getAdmin();
 
84
    test(admin);
 
85
    
 
86
    admin->startServer("Test.IcePatch2");
 
87
    admin->startServer("IcePatch2-Direct");
 
88
 
 
89
    cout << "testing distributions... " << flush;
 
90
    {
 
91
        TestIntfPrx test;
 
92
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all"));
 
93
        test(test->getServerFile("rootfile") == "");
 
94
 
 
95
        try
 
96
        {
 
97
            admin->patchServer("server-all", true);
 
98
        }
 
99
        catch(const PatchException& ex)
 
100
        {
 
101
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
102
            test(false);
 
103
        }
 
104
 
 
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");
 
109
 
 
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");
 
114
 
 
115
        try
 
116
        {
 
117
            admin->patchServer("server-all-direct", true);
 
118
        }
 
119
        catch(const PatchException& ex)
 
120
        {
 
121
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
122
            test(false);
 
123
        }
 
124
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct"));
 
125
 
 
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");
 
130
 
 
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");
 
135
 
 
136
        try
 
137
        {
 
138
            admin->patchApplication("Test", true);
 
139
        }
 
140
        catch(const PatchException& ex)
 
141
        {
 
142
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
143
            test(false);
 
144
        }
 
145
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1"));
 
146
 
 
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") == "");
 
151
 
 
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");
 
156
    }
 
157
    cout << "ok" << endl;
 
158
 
 
159
    admin->stopServer("Test.IcePatch2");
 
160
    admin->stopServer("IcePatch2-Direct");
 
161
 
 
162
    ApplicationUpdateDescriptor update;
 
163
    update.name = "Test";
 
164
    update.variables["icepatch.directory"] = "${test.dir}/data/updated";
 
165
    admin->updateApplication(update);
 
166
 
 
167
    admin->startServer("Test.IcePatch2");
 
168
    admin->startServer("IcePatch2-Direct");
 
169
 
 
170
    cout << "testing distributions after update... " << flush;
 
171
    {
 
172
        TestIntfPrx test;
 
173
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all"));
 
174
        test(test->getServerFile("rootfile") == "rootfile");
 
175
 
 
176
        try
 
177
        {
 
178
            admin->patchServer("server-all", true);
 
179
        }
 
180
        catch(const PatchException& ex)
 
181
        {
 
182
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
183
            test(false);
 
184
        }
 
185
 
 
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");
 
191
 
 
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");
 
197
 
 
198
        try
 
199
        {
 
200
            admin->patchServer("server-all-direct", true);
 
201
        }
 
202
        catch(const PatchException& ex)
 
203
        {
 
204
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
205
            test(false);
 
206
        }
 
207
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct"));
 
208
 
 
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");
 
214
 
 
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");
 
220
 
 
221
        try
 
222
        {
 
223
            admin->patchApplication("Test", true);
 
224
        }
 
225
        catch(const PatchException& ex)
 
226
        {
 
227
            copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n"));
 
228
            test(false);
 
229
        }
 
230
        test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1"));
 
231
 
 
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") == "");
 
237
 
 
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");
 
243
    }
 
244
    cout << "ok" << endl;
 
245
 
 
246
    admin->stopServer("Test.IcePatch2");
 
247
    admin->stopServer("IcePatch2-Direct");
 
248
 
 
249
    keepAlive->destroy();
 
250
    keepAlive->getThreadControl().join();
 
251
    keepAlive = 0;
 
252
 
 
253
    session->destroy();
 
254
}