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
|
// **********************************************************************
//
// Copyright (c) 2001
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include <Yellow/Yellow.h>
#include <TestCommon.h>
using namespace std;
using namespace Ice;
using namespace Yellow;
class StressThread : public IceUtil::Thread
{
public:
StressThread(const QueryPrx& query) :
_query(query)
{
}
virtual void
run()
{
string intf = "::Test";
for (int i = 0; i < 100; ++i)
{
Ice::ObjectPrx result = _query->lookup(intf);
}
}
private:
QueryPrx _query;
};
static int
run(int argc, char* argv[], const CommunicatorPtr& communicator)
{
QueryPrx query = QueryPrx::checkedCast(
communicator->stringToProxy("Yellow/Query:default -p 12346"));
AdminPrx admin = AdminPrx::checkedCast(
communicator->stringToProxy("Yellow/Admin:default -p 12347"));
cout << "testing add... ";
ObjectAdapterPtr adapter = communicator->createObjectAdapter("dummy");
ObjectPrx test1 = adapter->createProxy(stringToIdentity("test"));
ObjectPrx test2 = adapter->createProxy(stringToIdentity("test2"));
ObjectPrx test3 = adapter->createProxy(stringToIdentity("test3"));
ObjectPrx test4 = adapter->createProxy(stringToIdentity("test4"));
admin->add("::Test", test1);
admin->add("::Test", test2);
ObjectProxySeq seq = query->lookupAll("::Test");
test(seq.size() == 2);
Identity ident = seq[0]->ice_getIdentity();
test(ident == stringToIdentity("test") || ident == stringToIdentity("test2"));
if(ident == stringToIdentity("test"))
{
test(seq[1]->ice_getIdentity() == stringToIdentity("test2"));
}
else
{
test(seq[1]->ice_getIdentity() == stringToIdentity("test"));
}
admin->add("::Test2", test3);
admin->add("::Test2", test4);
seq = query->lookupAll("::Test2");
test(seq.size() == 2);
ident = seq[0]->ice_getIdentity();
test(ident == stringToIdentity("test3") || ident == stringToIdentity("test4"));
if(ident == stringToIdentity("test3"))
{
test(seq[1]->ice_getIdentity() == stringToIdentity("test4"));
}
else
{
test(seq[1]->ice_getIdentity() == stringToIdentity("test3"));
}
cout << "ok" << endl;
cout << "testing lookup... ";
try
{
query->lookup("::Foo");
test(false);
}
catch(const NoSuchOfferException&)
{
// Expected
}
ObjectPrx obj = query->lookup("::Test");
ident = obj->ice_getIdentity();
test(ident == stringToIdentity("test") || ident == stringToIdentity("test2"));
obj = query->lookup("::Test2");
ident = obj->ice_getIdentity();
test(ident == stringToIdentity("test3") || ident == stringToIdentity("test4"));
cout << "ok" << endl;
cout << "testing remove... ";
try
{
admin->remove("::Test2", test1);
test(false);
}
catch(const NoSuchOfferException&)
{
// Expected
}
admin->remove("::Test2", test3);
obj = query->lookup("::Test2");
ident = obj->ice_getIdentity();
test(ident == stringToIdentity("test4"));
admin->remove("::Test2", test4);
try
{
query->lookup("::Test2");
test(false);
}
catch(const NoSuchOfferException&)
{
// Expected
}
cout << "ok" << endl;
cout << "testing concurrent queries... " << flush;
vector<IceUtil::ThreadControl> controls;
for(int i = 0; i < 10; ++i)
{
IceUtil::ThreadPtr t = new StressThread(query);
controls.push_back(t->start());
}
for(vector<IceUtil::ThreadControl>::iterator p = controls.begin(); p != controls.end(); ++p)
{
p->join();
}
cout << "ok" << endl;
return EXIT_SUCCESS;
}
int
main(int argc, char* argv[])
{
int status;
Ice::CommunicatorPtr communicator;
try
{
communicator = Ice::initialize(argc, argv);
status = run(argc, argv, communicator);
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
try
{
communicator->destroy();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
return status;
}
|