summaryrefslogtreecommitdiff
path: root/cpp/test/IcePack/deployer/AllTests.cpp
blob: 93fccb76f43a7d82d6ee16cfa04c557a7238e9f3 (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
// **********************************************************************
//
// Copyright (c) 2001
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/Ice.h>
#include <Ice/BuiltinSequences.h>
#include <Ice/IdentityUtil.h>
#include <IcePack/Admin.h>
#include <Yellow/Yellow.h>
#include <TestCommon.h>
#include <Test.h>

using namespace std;

struct ProxyIdentityEqual : public std::binary_function<Ice::ObjectPrx,string,bool>
{

public:

    bool 
    operator()(const Ice::ObjectPrx& p1, const string& id) const
    {
	return p1->ice_getIdentity() == Ice::stringToIdentity(id);
    }
};

void
allCommonTests(const Ice::CommunicatorPtr& communicator)
{
    IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(
	communicator->stringToProxy("IcePack/Admin@IcePack.Registry.Admin"));
    test(admin);

    cout << "test server registration..." << flush;
    Ice::StringSeq serverNames = admin->getAllServerNames();
    test(find(serverNames.begin(), serverNames.end(), "Server1") != serverNames.end());
    test(find(serverNames.begin(), serverNames.end(), "Server2") != serverNames.end());
    test(find(serverNames.begin(), serverNames.end(), "IceBox1") != serverNames.end());
    test(find(serverNames.begin(), serverNames.end(), "IceBox2") != serverNames.end());
    cout << "ok" << endl;

    cout << "testing adapter registration... " << flush;
    Ice::StringSeq adapterNames = admin->getAllAdapterNames();
    test(find(adapterNames.begin(), adapterNames.end(), "Server-Server1") != adapterNames.end());
    test(find(adapterNames.begin(), adapterNames.end(), "Server-Server2") != adapterNames.end());
    test(find(adapterNames.begin(), adapterNames.end(), "Service1-IceBox1.Service1") != adapterNames.end());
    test(find(adapterNames.begin(), adapterNames.end(), "IceBox1Service2Adapter") != adapterNames.end());
    test(find(adapterNames.begin(), adapterNames.end(), "Service1-IceBox2.Service1") != adapterNames.end());
    test(find(adapterNames.begin(), adapterNames.end(), "IceBox2Service2Adapter") != adapterNames.end());
    cout << "ok" << endl;

    Yellow::QueryPrx yellow = Yellow::QueryPrx::checkedCast(
	communicator->stringToProxy("Yellow/Query@Yellow.Query"));
    test(yellow);

    cout << "testing offer registration... " << flush;
    Ice::ObjectProxySeq offers = yellow->lookupAll("::Test");
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"Server1")) != offers.end());
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"Server2")) != offers.end());
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"IceBox1-Service1")) != offers.end());
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"IceBox1-Service2")) != offers.end());
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"IceBox2-Service1")) != offers.end());
    test(find_if(offers.begin(), offers.end(), bind2nd(ProxyIdentityEqual(),"IceBox2-Service2")) != offers.end());

    cout << "ok" << endl;
}

void 
allTests(const Ice::CommunicatorPtr& communicator)
{
    allCommonTests(communicator);

    //
    // Ensure that all server and service objects are reachable.
    //
    // The identity for the test object in deployed server or services
    // is the name of the service or server. The object adapter name
    // is Adapter prefixed with the name of the service or
    // server. Ensure we can reach each object.
    //
    cout << "pinging server objects... " << flush;

    TestPrx obj;

    obj = TestPrx::checkedCast(communicator->stringToProxy("Server1@Server-Server1"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("Server2@Server-Server2"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox1-Service1@Service1-IceBox1.Service1"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox2-Service1@Service1-IceBox2.Service1"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter"));
    
    cout << "ok" << endl;

    cout << "testing server configuration... " << flush;

    obj = TestPrx::checkedCast(communicator->stringToProxy("Server1@Server-Server1"));
    test(obj->getProperty("Type") == "Server");
    test(obj->getProperty("Name") == "Server1");

    obj = TestPrx::checkedCast(communicator->stringToProxy("Server2@Server-Server2"));
    test(obj->getProperty("Target1") == "1");
    test(obj->getProperty("Target2") == "1");

    cout << "ok" << endl;

    cout << "testing service configuration... " << flush;

    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox1-Service1@Service1-IceBox1.Service1"));
    test(obj->getProperty("Service1.Type") == "standard");
    test(obj->getProperty("Service1.ServiceName") == "Service1");
    
    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter"));
    test(obj->getProperty("Service2.Type") == "freeze");
    test(obj->getProperty("Service2.ServiceName") == "Service2");

    test(obj->getProperty("Service2.DebugProperty") == "");
    test(obj->getProperty("Service1.DebugProperty") == "");
    
    IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(
	communicator->stringToProxy("IcePack/Admin@IcePack.Registry.Admin"));
    test(admin);

    //
    // Ping the icebox service manager to avoid terminating the icebox
    // too soon (before the icebox is fully initialized) and some
    // connection warnings message (caused by the fact the termination
    // handler is not yet installed and communicator not properly
    // shutdown).
    //
    IcePack::ServerDescription desc;

    desc = admin->getServerDescription("IceBox1");
    desc.serviceManager->ice_ping();

    desc = admin->getServerDescription("IceBox2");
    desc.serviceManager->ice_ping();

    cout << "ok" << endl;
}

void
allTestsWithTarget(const Ice::CommunicatorPtr& communicator)
{
    allCommonTests(communicator);

    IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(
	communicator->stringToProxy("IcePack/Admin@IcePack.Registry.Admin"));
    test(admin);

    cout << "pinging server objects... " << flush;

    TestPrx obj;

    admin->setServerActivation("Server1", IcePack::Manual);
    try
    {
	obj = TestPrx::checkedCast(communicator->stringToProxy("Server1@Server-Server1"));
	test(false);
    }
    catch(const Ice::LocalException&)
    {
    }
    admin->startServer("Server1");
    
    obj = TestPrx::checkedCast(communicator->stringToProxy("Server1@Server-Server1"));
    obj = TestPrx::checkedCast(communicator->stringToProxy("Server2@Server-Server2"));

    cout << "ok" << endl;

    cout << "testing service configuration... " << flush;

    obj = TestPrx::checkedCast(communicator->stringToProxy("IceBox1-Service1@Service1-IceBox1.Service1"));
    test(obj->getProperty("Service1.DebugProperty") == "debug");

    //
    // Ping the icebox service manager to avoid terminating the icebox
    // too soon (before the icebox is fully initialized) and some
    // connection warnings message (caused by the fact the termination
    // handler is not yet installed and communicator not properly
    // shutdown).
    //
    IcePack::ServerDescription desc = admin->getServerDescription("IceBox1");
    desc.serviceManager->ice_ping();

    cout << "ok" << endl;
}