diff options
Diffstat (limited to 'cpp/test/Ice/acm')
-rwxr-xr-x | cpp/test/Ice/acm/.depend.mak | 34 | ||||
-rw-r--r-- | cpp/test/Ice/acm/AllTests.cpp | 504 | ||||
-rw-r--r-- | cpp/test/Ice/acm/Server.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/acm/TestI.cpp | 20 | ||||
-rw-r--r-- | cpp/test/Ice/acm/TestI.h | 6 |
5 files changed, 306 insertions, 260 deletions
diff --git a/cpp/test/Ice/acm/.depend.mak b/cpp/test/Ice/acm/.depend.mak index 80524069778..fc201e5e491 100755 --- a/cpp/test/Ice/acm/.depend.mak +++ b/cpp/test/Ice/acm/.depend.mak @@ -16,6 +16,7 @@ Test.obj: \ "$(includedir)\IceUtil\Exception.h" \ "$(includedir)\Ice\ObjectF.h" \ "$(includedir)\Ice\Handle.h" \ + "$(includedir)\Ice\ValueF.h" \ "$(includedir)\Ice\Exception.h" \ "$(includedir)\Ice\Format.h" \ "$(includedir)\Ice\StreamF.h" \ @@ -24,6 +25,7 @@ Test.obj: \ "$(includedir)\Ice\StreamHelpers.h" \ "$(includedir)\IceUtil\ScopedArray.h" \ "$(includedir)\IceUtil\Iterator.h" \ + "$(includedir)\Ice\Traits.h" \ "$(includedir)\Ice\Proxy.h" \ "$(includedir)\IceUtil\Mutex.h" \ "$(includedir)\IceUtil\Lock.h" \ @@ -58,7 +60,7 @@ Test.obj: \ "$(includedir)\IceUtil\StringConverter.h" \ "$(includedir)\Ice\Object.h" \ "$(includedir)\Ice\IncomingAsyncF.h" \ - "$(includedir)\Ice\ObjectFactoryF.h" \ + "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\ObjectFactoryManagerF.h" \ "$(includedir)\Ice\Buffer.h" \ "$(includedir)\Ice\Protocol.h" \ @@ -67,13 +69,13 @@ Test.obj: \ "$(includedir)\Ice\FactoryTable.h" \ "$(includedir)\Ice\GCObject.h" \ "$(includedir)\IceUtil\MutexPtrLock.h" \ + "$(includedir)\Ice\Value.h" \ "$(includedir)\Ice\Incoming.h" \ "$(includedir)\Ice\ServantLocatorF.h" \ "$(includedir)\Ice\ServantManagerF.h" \ "$(includedir)\Ice\ResponseHandlerF.h" \ "$(includedir)\Ice\LocalException.h" \ "$(includedir)\Ice\BuiltinSequences.h" \ - "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\Outgoing.h" \ "$(includedir)\Ice\OutgoingAsync.h" \ "$(includedir)\IceUtil\Timer.h" \ @@ -96,6 +98,7 @@ Client.obj: \ "$(includedir)\IceUtil\Exception.h" \ "$(includedir)\Ice\ObjectF.h" \ "$(includedir)\Ice\Handle.h" \ + "$(includedir)\Ice\ValueF.h" \ "$(includedir)\Ice\Exception.h" \ "$(includedir)\Ice\Format.h" \ "$(includedir)\Ice\StreamF.h" \ @@ -104,6 +107,7 @@ Client.obj: \ "$(includedir)\Ice\StreamHelpers.h" \ "$(includedir)\IceUtil\ScopedArray.h" \ "$(includedir)\IceUtil\Iterator.h" \ + "$(includedir)\Ice\Traits.h" \ "$(includedir)\IceUtil\Optional.h" \ "$(includedir)\IceUtil\UndefSysMacros.h" \ "$(includedir)\IceUtil\PopDisableWarnings.h" \ @@ -144,7 +148,7 @@ Client.obj: \ "$(includedir)\Ice\BasicStream.h" \ "$(includedir)\Ice\Object.h" \ "$(includedir)\Ice\IncomingAsyncF.h" \ - "$(includedir)\Ice\ObjectFactoryF.h" \ + "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\ObjectFactoryManagerF.h" \ "$(includedir)\Ice\Buffer.h" \ "$(includedir)\Ice\Protocol.h" \ @@ -158,6 +162,7 @@ Client.obj: \ "$(includedir)\Ice\PropertiesAdmin.h" \ "$(includedir)\Ice\GCObject.h" \ "$(includedir)\IceUtil\MutexPtrLock.h" \ + "$(includedir)\Ice\Value.h" \ "$(includedir)\Ice\Incoming.h" \ "$(includedir)\Ice\ServantLocatorF.h" \ "$(includedir)\Ice\ServantManagerF.h" \ @@ -169,7 +174,6 @@ Client.obj: \ "$(includedir)\Ice\RemoteLogger.h" \ "$(includedir)\Ice\FactoryTableInit.h" \ "$(includedir)\Ice\DefaultObjectFactory.h" \ - "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\Communicator.h" \ "$(includedir)\Ice\RouterF.h" \ "$(includedir)\Ice\LocatorF.h" \ @@ -192,7 +196,6 @@ Client.obj: \ "$(includedir)\Ice\Stream.h" \ "$(includedir)\Ice\ImplicitContext.h" \ "$(includedir)\Ice\Locator.h" \ - "$(includedir)\Ice\ProcessF.h" \ "$(includedir)\Ice\Router.h" \ "$(includedir)\Ice\DispatchInterceptor.h" \ "$(includedir)\Ice\NativePropertiesAdmin.h" \ @@ -224,6 +227,7 @@ AllTests.obj: \ "$(includedir)\IceUtil\Exception.h" \ "$(includedir)\Ice\ObjectF.h" \ "$(includedir)\Ice\Handle.h" \ + "$(includedir)\Ice\ValueF.h" \ "$(includedir)\Ice\Exception.h" \ "$(includedir)\Ice\Format.h" \ "$(includedir)\Ice\StreamF.h" \ @@ -232,6 +236,7 @@ AllTests.obj: \ "$(includedir)\Ice\StreamHelpers.h" \ "$(includedir)\IceUtil\ScopedArray.h" \ "$(includedir)\IceUtil\Iterator.h" \ + "$(includedir)\Ice\Traits.h" \ "$(includedir)\IceUtil\Optional.h" \ "$(includedir)\IceUtil\UndefSysMacros.h" \ "$(includedir)\IceUtil\PopDisableWarnings.h" \ @@ -272,7 +277,7 @@ AllTests.obj: \ "$(includedir)\Ice\BasicStream.h" \ "$(includedir)\Ice\Object.h" \ "$(includedir)\Ice\IncomingAsyncF.h" \ - "$(includedir)\Ice\ObjectFactoryF.h" \ + "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\ObjectFactoryManagerF.h" \ "$(includedir)\Ice\Buffer.h" \ "$(includedir)\Ice\Protocol.h" \ @@ -286,6 +291,7 @@ AllTests.obj: \ "$(includedir)\Ice\PropertiesAdmin.h" \ "$(includedir)\Ice\GCObject.h" \ "$(includedir)\IceUtil\MutexPtrLock.h" \ + "$(includedir)\Ice\Value.h" \ "$(includedir)\Ice\Incoming.h" \ "$(includedir)\Ice\ServantLocatorF.h" \ "$(includedir)\Ice\ServantManagerF.h" \ @@ -297,7 +303,6 @@ AllTests.obj: \ "$(includedir)\Ice\RemoteLogger.h" \ "$(includedir)\Ice\FactoryTableInit.h" \ "$(includedir)\Ice\DefaultObjectFactory.h" \ - "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\Communicator.h" \ "$(includedir)\Ice\RouterF.h" \ "$(includedir)\Ice\LocatorF.h" \ @@ -320,7 +325,6 @@ AllTests.obj: \ "$(includedir)\Ice\Stream.h" \ "$(includedir)\Ice\ImplicitContext.h" \ "$(includedir)\Ice\Locator.h" \ - "$(includedir)\Ice\ProcessF.h" \ "$(includedir)\Ice\Router.h" \ "$(includedir)\Ice\DispatchInterceptor.h" \ "$(includedir)\Ice\NativePropertiesAdmin.h" \ @@ -371,6 +375,7 @@ TestI.obj: \ "$(includedir)\Ice\ProxyHandle.h" \ "$(includedir)\Ice\ObjectF.h" \ "$(includedir)\Ice\Handle.h" \ + "$(includedir)\Ice\ValueF.h" \ "$(includedir)\Ice\Exception.h" \ "$(includedir)\Ice\Format.h" \ "$(includedir)\Ice\StreamF.h" \ @@ -378,6 +383,7 @@ TestI.obj: \ "$(includedir)\Ice\LocalObjectF.h" \ "$(includedir)\Ice\StreamHelpers.h" \ "$(includedir)\IceUtil\Iterator.h" \ + "$(includedir)\Ice\Traits.h" \ "$(includedir)\IceUtil\Optional.h" \ "$(includedir)\IceUtil\UndefSysMacros.h" \ "$(includedir)\Ice\Plugin.h" \ @@ -406,7 +412,7 @@ TestI.obj: \ "$(includedir)\Ice\BasicStream.h" \ "$(includedir)\Ice\Object.h" \ "$(includedir)\Ice\IncomingAsyncF.h" \ - "$(includedir)\Ice\ObjectFactoryF.h" \ + "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\ObjectFactoryManagerF.h" \ "$(includedir)\Ice\Buffer.h" \ "$(includedir)\Ice\Protocol.h" \ @@ -419,6 +425,7 @@ TestI.obj: \ "$(includedir)\Ice\LocalException.h" \ "$(includedir)\Ice\PropertiesAdmin.h" \ "$(includedir)\Ice\GCObject.h" \ + "$(includedir)\Ice\Value.h" \ "$(includedir)\Ice\Incoming.h" \ "$(includedir)\Ice\ServantLocatorF.h" \ "$(includedir)\Ice\ServantManagerF.h" \ @@ -430,7 +437,6 @@ TestI.obj: \ "$(includedir)\Ice\RemoteLogger.h" \ "$(includedir)\Ice\FactoryTableInit.h" \ "$(includedir)\Ice\DefaultObjectFactory.h" \ - "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\Communicator.h" \ "$(includedir)\Ice\RouterF.h" \ "$(includedir)\Ice\LocatorF.h" \ @@ -452,7 +458,6 @@ TestI.obj: \ "$(includedir)\Ice\Stream.h" \ "$(includedir)\Ice\ImplicitContext.h" \ "$(includedir)\Ice\Locator.h" \ - "$(includedir)\Ice\ProcessF.h" \ "$(includedir)\Ice\Router.h" \ "$(includedir)\Ice\DispatchInterceptor.h" \ "$(includedir)\Ice\NativePropertiesAdmin.h" \ @@ -480,6 +485,7 @@ Server.obj: \ "$(includedir)\IceUtil\Exception.h" \ "$(includedir)\Ice\ObjectF.h" \ "$(includedir)\Ice\Handle.h" \ + "$(includedir)\Ice\ValueF.h" \ "$(includedir)\Ice\Exception.h" \ "$(includedir)\Ice\Format.h" \ "$(includedir)\Ice\StreamF.h" \ @@ -488,6 +494,7 @@ Server.obj: \ "$(includedir)\Ice\StreamHelpers.h" \ "$(includedir)\IceUtil\ScopedArray.h" \ "$(includedir)\IceUtil\Iterator.h" \ + "$(includedir)\Ice\Traits.h" \ "$(includedir)\IceUtil\Optional.h" \ "$(includedir)\IceUtil\UndefSysMacros.h" \ "$(includedir)\IceUtil\PopDisableWarnings.h" \ @@ -528,7 +535,7 @@ Server.obj: \ "$(includedir)\Ice\BasicStream.h" \ "$(includedir)\Ice\Object.h" \ "$(includedir)\Ice\IncomingAsyncF.h" \ - "$(includedir)\Ice\ObjectFactoryF.h" \ + "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\ObjectFactoryManagerF.h" \ "$(includedir)\Ice\Buffer.h" \ "$(includedir)\Ice\Protocol.h" \ @@ -542,6 +549,7 @@ Server.obj: \ "$(includedir)\Ice\PropertiesAdmin.h" \ "$(includedir)\Ice\GCObject.h" \ "$(includedir)\IceUtil\MutexPtrLock.h" \ + "$(includedir)\Ice\Value.h" \ "$(includedir)\Ice\Incoming.h" \ "$(includedir)\Ice\ServantLocatorF.h" \ "$(includedir)\Ice\ServantManagerF.h" \ @@ -553,7 +561,6 @@ Server.obj: \ "$(includedir)\Ice\RemoteLogger.h" \ "$(includedir)\Ice\FactoryTableInit.h" \ "$(includedir)\Ice\DefaultObjectFactory.h" \ - "$(includedir)\Ice\ObjectFactory.h" \ "$(includedir)\Ice\Communicator.h" \ "$(includedir)\Ice\RouterF.h" \ "$(includedir)\Ice\LocatorF.h" \ @@ -576,7 +583,6 @@ Server.obj: \ "$(includedir)\Ice\Stream.h" \ "$(includedir)\Ice\ImplicitContext.h" \ "$(includedir)\Ice\Locator.h" \ - "$(includedir)\Ice\ProcessF.h" \ "$(includedir)\Ice\Router.h" \ "$(includedir)\Ice\DispatchInterceptor.h" \ "$(includedir)\Ice\NativePropertiesAdmin.h" \ diff --git a/cpp/test/Ice/acm/AllTests.cpp b/cpp/test/Ice/acm/AllTests.cpp index e1855fea2d4..d89c6827296 100644 --- a/cpp/test/Ice/acm/AllTests.cpp +++ b/cpp/test/Ice/acm/AllTests.cpp @@ -24,7 +24,9 @@ toString(int value) return os.str(); } -class LoggerI : public Ice::Logger, private IceUtil::Mutex +class LoggerI : public ICE_ENABLE_SHARED_FROM_THIS(LoggerI), + public Ice::Logger, + private IceUtil::Mutex { public: @@ -93,7 +95,7 @@ public: virtual Ice::LoggerPtr cloneWithPrefix(const std::string&) { - return this; + return ICE_SHARED_FROM_THIS; } private: @@ -111,13 +113,20 @@ private: bool _started; vector<string> _messages; }; -typedef IceUtil::Handle<LoggerI> LoggerIPtr; - -class TestCase : public IceUtil::Thread, protected Ice::ConnectionCallback, protected IceUtil::Monitor<IceUtil::Mutex> +ICE_DEFINE_PTR(LoggerIPtr, LoggerI); + +class TestCase : +#ifdef ICE_CPP11_MAPPING + public enable_shared_from_this<Ice::ConnectionCallback>, +#else + public IceUtil::Thread, +#endif + public Ice::ConnectionCallback, + protected IceUtil::Monitor<IceUtil::Mutex> { public: - TestCase(const string& name, const RemoteCommunicatorPrx& com) : + TestCase(const string& name, const RemoteCommunicatorPrxPtr& com) : _name(name), _com(com), _logger(new LoggerI()), _clientACMTimeout(-1), _clientACMClose(-1), _clientACMHeartbeat(-1), _serverACMTimeout(-1), _serverACMClose(-1), _serverACMHeartbeat(-1), @@ -158,12 +167,19 @@ public: _communicator->destroy(); } - void - join() +#ifdef ICE_CPP11_MAPPING + void join(thread& t) +#else + void join() +#endif { cout << "testing " << _name << "... " << flush; _logger->start(); +#ifdef ICE_CPP11_MAPPING + t.join(); +#else getThreadControl().join(); +#endif if(_msg.empty()) { cout << "ok" << endl; @@ -178,11 +194,11 @@ public: virtual void run() { - TestIntfPrx proxy = TestIntfPrx::uncheckedCast(_communicator->stringToProxy( + TestIntfPrxPtr proxy = ICE_UNCHECKED_CAST(TestIntfPrx, _communicator->stringToProxy( _adapter->getTestIntf()->ice_toString())); try { - proxy->ice_getConnection()->setCallback(this); + proxy->ice_getConnection()->setCallback(ICE_SHARED_FROM_THIS); runTestCase(_adapter, proxy); } catch(const std::exception& ex) @@ -225,7 +241,7 @@ public: } } - virtual void runTestCase(const RemoteObjectAdapterPrx&, const TestIntfPrx&) = 0; + virtual void runTestCase(const RemoteObjectAdapterPrxPtr&, const TestIntfPrxPtr&) = 0; void setClientACM(int timeout, int close, int heartbeat) @@ -246,12 +262,12 @@ public: protected: const string _name; - const RemoteCommunicatorPrx _com; + const RemoteCommunicatorPrxPtr _com; string _msg; LoggerIPtr _logger; Ice::CommunicatorPtr _communicator; - RemoteObjectAdapterPrx _adapter; + RemoteObjectAdapterPrxPtr _adapter; int _clientACMTimeout; int _clientACMClose; @@ -263,306 +279,323 @@ protected: int _heartbeat; bool _closed; }; -typedef IceUtil::Handle<TestCase> TestCasePtr; - -} +ICE_DEFINE_PTR(TestCasePtr, TestCase); -void -allTests(const Ice::CommunicatorPtr& communicator) +class InvocationHeartbeatTest : public TestCase { - string ref = "communicator:default -p 12010"; - RemoteCommunicatorPrx com = RemoteCommunicatorPrx::uncheckedCast(communicator->stringToProxy(ref)); - - vector<TestCasePtr> tests; +public: - class InvocationHeartbeatTest : public TestCase + InvocationHeartbeatTest(const RemoteCommunicatorPrxPtr& com) : + TestCase("invocation heartbeat", com) { - public: + } - InvocationHeartbeatTest(const RemoteCommunicatorPrx& com) : - TestCase("invocation heartbeat", com) - { - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + proxy->sleep(2); - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - proxy->sleep(2); + Lock sync(*this); + test(_heartbeat >= 2); + } +}; - Lock sync(*this); - test(_heartbeat >= 2); - } - }; +class InvocationHeartbeatOnHoldTest : public TestCase +{ +public: - class InvocationHeartbeatOnHoldTest : public TestCase + InvocationHeartbeatOnHoldTest(const RemoteCommunicatorPrxPtr& com) : + TestCase("invocation with heartbeat on hold", com) { - public: + // Use default ACM configuration. + } - InvocationHeartbeatOnHoldTest(const RemoteCommunicatorPrx& com) : - TestCase("invocation with heartbeat on hold", com) + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + try { - // Use default ACM configuration. + // When the OA is put on hold, connections shouldn't + // send heartbeats, the invocation should therefore + // fail. + proxy->sleepAndHold(10); + test(false); } - - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) + catch(const Ice::ConnectionTimeoutException&) { - try - { - // When the OA is put on hold, connections shouldn't - // send heartbeats, the invocation should therefore - // fail. - proxy->sleepAndHold(10); - test(false); - } - catch(const Ice::ConnectionTimeoutException&) - { - adapter->activate(); - proxy->interruptSleep(); + adapter->activate(); + proxy->interruptSleep(); - waitForClosed(); - } + waitForClosed(); } - }; + } +}; + +class InvocationNoHeartbeatTest : public TestCase +{ +public: - class InvocationNoHeartbeatTest : public TestCase + InvocationNoHeartbeatTest(const RemoteCommunicatorPrxPtr& com) : + TestCase("invocation with no heartbeat", com) { - public: + setServerACM(1, 2, 0); // Disable heartbeat on invocations + } - InvocationNoHeartbeatTest(const RemoteCommunicatorPrx& com) : - TestCase("invocation with no heartbeat", com) + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + try { - setServerACM(1, 2, 0); // Disable heartbeat on invocations + // Heartbeats are disabled on the server, the + // invocation should fail since heartbeats are + // expected. + proxy->sleep(10); + test(false); } - - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) + catch(const Ice::ConnectionTimeoutException&) { - try - { - // Heartbeats are disabled on the server, the - // invocation should fail since heartbeats are - // expected. - proxy->sleep(10); - test(false); - } - catch(const Ice::ConnectionTimeoutException&) - { - proxy->interruptSleep(); + proxy->interruptSleep(); - waitForClosed(); + waitForClosed(); - Lock sync(*this); - test(_heartbeat == 0); - } + Lock sync(*this); + test(_heartbeat == 0); } - }; + } +}; + +class InvocationHeartbeatCloseOnIdleTest : public TestCase +{ +public: - class InvocationHeartbeatCloseOnIdleTest : public TestCase + InvocationHeartbeatCloseOnIdleTest(const RemoteCommunicatorPrxPtr& com) : + TestCase("invocation with no heartbeat and close on idle", com) { - public: + setClientACM(1, 1, 0); // Only close on idle. + setServerACM(1, 2, 0); // Disable heartbeat on invocations + } - InvocationHeartbeatCloseOnIdleTest(const RemoteCommunicatorPrx& com) : - TestCase("invocation with no heartbeat and close on idle", com) - { - setClientACM(1, 1, 0); // Only close on idle. - setServerACM(1, 2, 0); // Disable heartbeat on invocations - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + // No close on invocation, the call should succeed this + // time. + proxy->sleep(2); - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - // No close on invocation, the call should succeed this - // time. - proxy->sleep(2); + Lock sync(*this); + test(_heartbeat == 0); + test(!_closed); + } +}; - Lock sync(*this); - test(_heartbeat == 0); - test(!_closed); - } - }; +class CloseOnIdleTest : public TestCase +{ +public: - class CloseOnIdleTest : public TestCase + CloseOnIdleTest(const RemoteCommunicatorPrxPtr& com) : TestCase("close on idle", com) { - public: + setClientACM(1, 1, 0); // Only close on idle + } - CloseOnIdleTest(const RemoteCommunicatorPrx& com) : TestCase("close on idle", com) - { - setClientACM(1, 1, 0); // Only close on idle - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds + waitForClosed(); - waitForClosed(); + Lock sync(*this); + test(_heartbeat == 0); + } +}; - Lock sync(*this); - test(_heartbeat == 0); - } - }; +class CloseOnInvocationTest : public TestCase +{ +public: - class CloseOnInvocationTest : public TestCase + CloseOnInvocationTest(const RemoteCommunicatorPrxPtr& com) : TestCase("close on invocation", com) { - public: + setClientACM(1, 2, 0); // Only close on invocation + } - CloseOnInvocationTest(const RemoteCommunicatorPrx& com) : TestCase("close on invocation", com) - { - setClientACM(1, 2, 0); // Only close on invocation - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds + Lock sync(*this); + test(_heartbeat == 0); + test(!_closed); + } +}; - Lock sync(*this); - test(_heartbeat == 0); - test(!_closed); - } - }; +class CloseOnIdleAndInvocationTest : public TestCase +{ +public: - class CloseOnIdleAndInvocationTest : public TestCase + CloseOnIdleAndInvocationTest(const RemoteCommunicatorPrxPtr& com) : TestCase("close on idle and invocation", com) { - public: + setClientACM(1, 3, 0); // Only close on idle and invocation + } - CloseOnIdleAndInvocationTest(const RemoteCommunicatorPrx& com) : TestCase("close on idle and invocation", com) - { - setClientACM(1, 3, 0); // Only close on idle and invocation - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + // + // Put the adapter on hold. The server will not respond to + // the graceful close. This allows to test whether or not + // the close is graceful or forceful. + // + adapter->hold(); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) { - // - // Put the adapter on hold. The server will not respond to - // the graceful close. This allows to test whether or not - // the close is graceful or forceful. - // - adapter->hold(); - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds + Lock sync(*this); + test(_heartbeat == 0); + test(!_closed); // Not closed yet because of graceful close. + } - { - Lock sync(*this); - test(_heartbeat == 0); - test(!_closed); // Not closed yet because of graceful close. - } + adapter->activate(); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); - adapter->activate(); - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); + waitForClosed(); + } +}; - waitForClosed(); - } - }; +class ForcefulCloseOnIdleAndInvocationTest : public TestCase +{ +public: - class ForcefulCloseOnIdleAndInvocationTest : public TestCase + ForcefulCloseOnIdleAndInvocationTest(const RemoteCommunicatorPrxPtr& com) : + TestCase("forceful close on idle and invocation", com) { - public: + setClientACM(1, 4, 0); // Only close on idle and invocation + } - ForcefulCloseOnIdleAndInvocationTest(const RemoteCommunicatorPrx& com) : - TestCase("forceful close on idle and invocation", com) - { - setClientACM(1, 4, 0); // Only close on idle and invocation - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + adapter->hold(); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - adapter->hold(); - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1500)); // Idle for 1.5 seconds + waitForClosed(); - waitForClosed(); + Lock sync(*this); + test(_heartbeat == 0); + } +}; - Lock sync(*this); - test(_heartbeat == 0); - } - }; +class HeartbeatOnIdleTest : public TestCase +{ +public: - class HeartbeatOnIdleTest : public TestCase + HeartbeatOnIdleTest(const RemoteCommunicatorPrxPtr& com) : TestCase("heartbeat on idle", com) { - public: + setServerACM(1, -1, 2); // Enable server heartbeats. + } - HeartbeatOnIdleTest(const RemoteCommunicatorPrx& com) : TestCase("heartbeat on idle", com) - { - setServerACM(1, -1, 2); // Enable server heartbeats. - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(2000)); - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(2000)); + Lock sync(*this); + test(_heartbeat >= 3); + } +}; - Lock sync(*this); - test(_heartbeat >= 3); - } - }; +class HeartbeatAlwaysTest : public TestCase +{ +public: - class HeartbeatAlwaysTest : public TestCase + HeartbeatAlwaysTest(const RemoteCommunicatorPrxPtr& com) : TestCase("heartbeat always", com) { - public: + setServerACM(1, -1, 3); // Enable server heartbeats. + } - HeartbeatAlwaysTest(const RemoteCommunicatorPrx& com) : TestCase("heartbeat always", com) + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + for(int i = 0; i < 12; ++i) { - setServerACM(1, -1, 3); // Enable server heartbeats. + proxy->ice_ping(); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - for(int i = 0; i < 12; ++i) - { - proxy->ice_ping(); - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); - } + Lock sync(*this); + test(_heartbeat >= 3); + } +}; - Lock sync(*this); - test(_heartbeat >= 3); - } - }; +class SetACMTest : public TestCase +{ +public: - class SetACMTest : public TestCase + SetACMTest(const RemoteCommunicatorPrxPtr& com) : TestCase("setACM/getACM", com) { - public: + setClientACM(15, 4, 0); + } - SetACMTest(const RemoteCommunicatorPrx& com) : TestCase("setACM/getACM", com) - { - setClientACM(15, 4, 0); - } + virtual void runTestCase(const RemoteObjectAdapterPrxPtr& adapter, const TestIntfPrxPtr& proxy) + { + Ice::ACM acm; + acm = proxy->ice_getCachedConnection()->getACM(); + test(acm.timeout == 15); + test(acm.close == Ice::CloseOnIdleForceful); + test(acm.heartbeat == Ice::HeartbeatOff); - virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) - { - Ice::ACM acm; - acm = proxy->ice_getCachedConnection()->getACM(); - test(acm.timeout == 15); - test(acm.close == Ice::CloseOnIdleForceful); - test(acm.heartbeat == Ice::HeartbeatOff); - - proxy->ice_getCachedConnection()->setACM(IceUtil::None, IceUtil::None, IceUtil::None); - acm = proxy->ice_getCachedConnection()->getACM(); - test(acm.timeout == 15); - test(acm.close == Ice::CloseOnIdleForceful); - test(acm.heartbeat == Ice::HeartbeatOff); - - proxy->ice_getCachedConnection()->setACM(1, Ice::CloseOnInvocationAndIdle, Ice::HeartbeatAlways); - acm = proxy->ice_getCachedConnection()->getACM(); - test(acm.timeout == 1); - test(acm.close == Ice::CloseOnInvocationAndIdle); - test(acm.heartbeat == Ice::HeartbeatAlways); - - // Make sure the client sends few heartbeats to the server - proxy->waitForHeartbeat(2); - } - }; + proxy->ice_getCachedConnection()->setACM(IceUtil::None, IceUtil::None, IceUtil::None); + acm = proxy->ice_getCachedConnection()->getACM(); + test(acm.timeout == 15); + test(acm.close == Ice::CloseOnIdleForceful); + test(acm.heartbeat == Ice::HeartbeatOff); - tests.push_back(new InvocationHeartbeatTest(com)); - tests.push_back(new InvocationHeartbeatOnHoldTest(com)); - tests.push_back(new InvocationNoHeartbeatTest(com)); - tests.push_back(new InvocationHeartbeatCloseOnIdleTest(com)); + proxy->ice_getCachedConnection()->setACM(1, Ice::CloseOnInvocationAndIdle, Ice::HeartbeatAlways); + acm = proxy->ice_getCachedConnection()->getACM(); + test(acm.timeout == 1); + test(acm.close == Ice::CloseOnInvocationAndIdle); + test(acm.heartbeat == Ice::HeartbeatAlways); - tests.push_back(new CloseOnIdleTest(com)); - tests.push_back(new CloseOnInvocationTest(com)); - tests.push_back(new CloseOnIdleAndInvocationTest(com)); - tests.push_back(new ForcefulCloseOnIdleAndInvocationTest(com)); + // Make sure the client sends few heartbeats to the server + proxy->waitForHeartbeat(2); + } +}; - tests.push_back(new HeartbeatOnIdleTest(com)); - tests.push_back(new HeartbeatAlwaysTest(com)); - tests.push_back(new SetACMTest(com)); +} + +void +allTests(const Ice::CommunicatorPtr& communicator) +{ + string ref = "communicator:default -p 12010"; + RemoteCommunicatorPrxPtr com = ICE_UNCHECKED_CAST(RemoteCommunicatorPrx, communicator->stringToProxy(ref)); + + vector<TestCasePtr> tests; + + tests.push_back(ICE_MAKE_SHARED(InvocationHeartbeatTest, com)); + tests.push_back(ICE_MAKE_SHARED(InvocationHeartbeatOnHoldTest, com)); + tests.push_back(ICE_MAKE_SHARED(InvocationNoHeartbeatTest, com)); + tests.push_back(ICE_MAKE_SHARED(InvocationHeartbeatCloseOnIdleTest, com)); + + tests.push_back(ICE_MAKE_SHARED(CloseOnIdleTest, com)); + tests.push_back(ICE_MAKE_SHARED(CloseOnInvocationTest, com)); + tests.push_back(ICE_MAKE_SHARED(CloseOnIdleAndInvocationTest, com)); + tests.push_back(ICE_MAKE_SHARED(ForcefulCloseOnIdleAndInvocationTest, com)); + + tests.push_back(ICE_MAKE_SHARED(HeartbeatOnIdleTest, com)); + tests.push_back(ICE_MAKE_SHARED(HeartbeatAlwaysTest, com)); + tests.push_back(ICE_MAKE_SHARED(SetACMTest, com)); for(vector<TestCasePtr>::const_iterator p = tests.begin(); p != tests.end(); ++p) { (*p)->init(); } + +#ifdef ICE_CPP11_MAPPING + vector<pair<thread, TestCasePtr>> threads; + for(auto p = tests.begin(); p != tests.end(); ++p) + { + TestCasePtr testCase = *p; + thread t([testCase]() + { + testCase->run(); + }); + threads.push_back(make_pair(move(t), testCase)); + } + for(auto p = threads.begin(); p != threads.end(); ++p) + { + p->second->join(p->first); + } +#else for(vector<TestCasePtr>::const_iterator p = tests.begin(); p != tests.end(); ++p) { (*p)->start(); @@ -571,6 +604,7 @@ allTests(const Ice::CommunicatorPtr& communicator) { (*p)->join(); } +#endif for(vector<TestCasePtr>::const_iterator p = tests.begin(); p != tests.end(); ++p) { (*p)->destroy(); diff --git a/cpp/test/Ice/acm/Server.cpp b/cpp/test/Ice/acm/Server.cpp index a40af1f7b03..64abc193761 100644 --- a/cpp/test/Ice/acm/Server.cpp +++ b/cpp/test/Ice/acm/Server.cpp @@ -22,7 +22,7 @@ run(int, char**, const Ice::CommunicatorPtr& communicator) communicator->getProperties()->setProperty("TestAdapter.ACM.Timeout", "0"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); Ice::Identity id = communicator->stringToIdentity("communicator"); - adapter->add(new RemoteCommunicatorI(), id); + adapter->add(ICE_MAKE_SHARED(RemoteCommunicatorI), id); adapter->activate(); TEST_READY diff --git a/cpp/test/Ice/acm/TestI.cpp b/cpp/test/Ice/acm/TestI.cpp index 493221b57a6..fb554bca5d1 100644 --- a/cpp/test/Ice/acm/TestI.cpp +++ b/cpp/test/Ice/acm/TestI.cpp @@ -26,7 +26,11 @@ toString(int value) return os.str(); } -class ConnectionCallbackI : public Ice::ConnectionCallback, private IceUtil::Monitor<IceUtil::Mutex> +class ConnectionCallbackI : public Ice::ConnectionCallback, +#ifdef ICE_CPP11_MAPPING + public enable_shared_from_this<Ice::ConnectionCallback>, +#endif + private IceUtil::Monitor<IceUtil::Mutex> { public: @@ -58,11 +62,11 @@ private: int _count; }; -typedef IceUtil::Handle<ConnectionCallbackI> ConnectionCallbackIPtr; +ICE_DEFINE_PTR(ConnectionCallbackIPtr, ConnectionCallbackI); } -RemoteObjectAdapterPrx +RemoteObjectAdapterPrxPtr RemoteCommunicatorI::createObjectAdapter(int timeout, int close, int heartbeat, const Current& current) { Ice::CommunicatorPtr com = current.adapter->getCommunicator(); @@ -85,7 +89,9 @@ RemoteCommunicatorI::createObjectAdapter(int timeout, int close, int heartbeat, } properties->setProperty(name + ".ThreadPool.Size", "2"); ObjectAdapterPtr adapter = com->createObjectAdapterWithEndpoints(name, protocol + " -h \"" + host + "\""); - return RemoteObjectAdapterPrx::uncheckedCast(current.adapter->addWithUUID(new RemoteObjectAdapterI(adapter))); + + return ICE_UNCHECKED_CAST(RemoteObjectAdapterPrx, current.adapter->addWithUUID( + ICE_MAKE_SHARED(RemoteObjectAdapterI, adapter))); } void @@ -96,13 +102,13 @@ RemoteCommunicatorI::shutdown(const Ice::Current& current) RemoteObjectAdapterI::RemoteObjectAdapterI(const Ice::ObjectAdapterPtr& adapter) : _adapter(adapter), - _testIntf(TestIntfPrx::uncheckedCast(_adapter->add(new TestI(), + _testIntf(ICE_UNCHECKED_CAST(TestIntfPrx, _adapter->add(ICE_MAKE_SHARED(TestI), adapter->getCommunicator()->stringToIdentity("test")))) { _adapter->activate(); } -TestIntfPrx +TestIntfPrxPtr RemoteObjectAdapterI::getTestIntf(const Ice::Current&) { return _testIntf; @@ -157,7 +163,7 @@ TestI::interruptSleep(const Ice::Current& current) void TestI::waitForHeartbeat(int count, const Ice::Current& current) { - ConnectionCallbackIPtr callback = new ConnectionCallbackI(); + ConnectionCallbackIPtr callback = ICE_MAKE_SHARED(ConnectionCallbackI); current.con->setCallback(callback); callback->waitForCount(count); } diff --git a/cpp/test/Ice/acm/TestI.h b/cpp/test/Ice/acm/TestI.h index c72d7b6a6b5..3a9a591083a 100644 --- a/cpp/test/Ice/acm/TestI.h +++ b/cpp/test/Ice/acm/TestI.h @@ -16,7 +16,7 @@ class RemoteCommunicatorI : public Test::RemoteCommunicator { public: - virtual Test::RemoteObjectAdapterPrx createObjectAdapter(int, int, int, const Ice::Current&); + virtual Test::RemoteObjectAdapterPrxPtr createObjectAdapter(int, int, int, const Ice::Current&); virtual void shutdown(const Ice::Current&); }; @@ -26,7 +26,7 @@ public: RemoteObjectAdapterI(const Ice::ObjectAdapterPtr&); - virtual Test::TestIntfPrx getTestIntf(const Ice::Current&); + virtual Test::TestIntfPrxPtr getTestIntf(const Ice::Current&); virtual void activate(const Ice::Current&); virtual void hold(const Ice::Current&); virtual void deactivate(const Ice::Current&); @@ -34,7 +34,7 @@ public: private: const Ice::ObjectAdapterPtr _adapter; - const Test::TestIntfPrx _testIntf; + const Test::TestIntfPrxPtr _testIntf; }; class TestI : public Test::TestIntf, private IceUtil::Monitor<IceUtil::Mutex> |