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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#include <IceUtil/IceUtil.h>
#include <Ice/Ice.h>
#include <Glacier2/Glacier2.h>
#include <TestHelper.h>
#include <iostream>
#include <iomanip>
#include <list>
#include <Callback.h>
using namespace std;
using namespace Test;
namespace
{
class CallbackReceiverI : public Test::CallbackReceiver
{
public:
CallbackReceiverI() : _received(false)
{
}
virtual void callback(const Ice::Current&)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor);
_received = true;
_monitor.notify();
}
void waitForCallback()
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor);
while(!_received)
{
_monitor.wait();
}
_received = false;
}
IceUtil::Monitor<IceUtil::Mutex> _monitor;
bool _received;
};
ICE_DEFINE_PTR(CallbackReceiverIPtr, CallbackReceiverI);
class Application : public Glacier2::Application
{
public:
Application() : _restart(0), _destroyed(false), _receiver(ICE_MAKE_SHARED(CallbackReceiverI))
{
}
virtual Glacier2::SessionPrxPtr
createSession()
{
return ICE_UNCHECKED_CAST(Glacier2::SessionPrx, router()->createSession("userid", "abc123"));
}
virtual int
runWithSession(int, char*[])
{
test(router());
test(!categoryForClient().empty());
test(objectAdapter());
if(_restart == 0)
{
cout << "testing Glacier2::Application restart... " << flush;
}
Ice::ObjectPrxPtr base = communicator()->stringToProxy(
"callback:" + TestHelper::getTestEndpoint(communicator()->getProperties()));
CallbackPrxPtr callback = ICE_UNCHECKED_CAST(CallbackPrx, base);
if(++_restart < 5)
{
CallbackReceiverPrxPtr receiver = ICE_UNCHECKED_CAST(CallbackReceiverPrx, addWithUUID(_receiver));
callback->initiateCallback(receiver);
_receiver->waitForCallback();
restart();
}
cout << "ok" << endl;
cout << "testing server shutdown... " << flush;
callback->shutdown();
cout << "ok" << endl;
return 0;
}
virtual void sessionDestroyed()
{
_destroyed = true;
}
int _restart;
bool _destroyed;
CallbackReceiverIPtr _receiver;
};
} // anonymous namespace end
class Client : public Test::TestHelper
{
public:
void run(int, char**);
};
void
Client::run(int argc, char** argv)
{
Application app;
Ice::InitializationData initData;
initData.properties = createTestProperties(argc, argv);
initData.properties->setProperty("Ice.Warn.Connections", "0");
initData.properties->setProperty("Ice.Default.Router",
"Glacier2/router:" + TestHelper::getTestEndpoint(initData.properties, 50));
int status = app.main(argc, argv, initData);
if(status != 0)
{
test(false);
}
initData.properties->setProperty("Ice.Default.Router", "");
Ice::CommunicatorHolder communicator = initialize(argc, argv, initData);
cout << "testing stringToProxy for process object... " << flush;
Ice::ObjectPrxPtr processBase = communicator->stringToProxy("Glacier2/admin -f Process:" + getTestEndpoint(51));
cout << "ok" << endl;
cout << "testing checked cast for admin object... " << flush;
Ice::ProcessPrxPtr process = ICE_CHECKED_CAST(Ice::ProcessPrx, processBase);
test(process != 0);
cout << "ok" << endl;
cout << "testing Glacier2 shutdown... " << flush;
process->shutdown();
try
{
process->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
cout << "ok" << endl;
}
test(app._restart == 5);
test(app._destroyed);
}
DEFINE_TEST(Client)
|