summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/background/AllTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/test/Ice/background/AllTests.cpp')
-rw-r--r--cpp/test/Ice/background/AllTests.cpp606
1 files changed, 538 insertions, 68 deletions
diff --git a/cpp/test/Ice/background/AllTests.cpp b/cpp/test/Ice/background/AllTests.cpp
index bca60ec6bae..73b505e5c2d 100644
--- a/cpp/test/Ice/background/AllTests.cpp
+++ b/cpp/test/Ice/background/AllTests.cpp
@@ -143,9 +143,9 @@ class OpThread : public IceUtil::Thread, public IceUtil::Mutex
{
public:
- OpThread(const BackgroundPrx& background) :
+ OpThread(const BackgroundPrxPtr& background) :
_destroyed(false),
- _background(BackgroundPrx::uncheckedCast(background->ice_oneway()))
+ _background(ICE_UNCHECKED_CAST(BackgroundPrx, background->ice_oneway()))
{
start();
}
@@ -171,7 +171,11 @@ public:
count = 0;
_background->ice_twoway()->ice_ping();
}
+#ifdef ICE_CPP11_MAPPING
+ _background->opAsync();
+#else
_background->begin_op();
+#endif
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1));
}
catch(const Ice::LocalException&)
@@ -190,31 +194,36 @@ public:
private:
bool _destroyed;
- BackgroundPrx _background;
+ BackgroundPrxPtr _background;
};
typedef IceUtil::Handle<OpThread> OpThreadPtr;
-void connectTests(const ConfigurationPtr&, const Test::BackgroundPrx&);
-void initializeTests(const ConfigurationPtr&, const Test::BackgroundPrx&, const Test::BackgroundControllerPrx&);
-void validationTests(const ConfigurationPtr&, const Test::BackgroundPrx&, const Test::BackgroundControllerPrx&);
-void readWriteTests(const ConfigurationPtr&, const Test::BackgroundPrx&, const Test::BackgroundControllerPrx&);
+void connectTests(const ConfigurationPtr&, const Test::BackgroundPrxPtr&);
+void initializeTests(const ConfigurationPtr&, const Test::BackgroundPrxPtr&, const Test::BackgroundControllerPrxPtr&);
+void validationTests(const ConfigurationPtr&, const Test::BackgroundPrxPtr&, const Test::BackgroundControllerPrxPtr&);
+void readWriteTests(const ConfigurationPtr&, const Test::BackgroundPrxPtr&, const Test::BackgroundControllerPrxPtr&);
-BackgroundPrx
+BackgroundPrxPtr
allTests(const Ice::CommunicatorPtr& communicator)
{
- string sref = "background:default -p 12010";
- Ice::ObjectPrx obj = communicator->stringToProxy(sref);
+ const string endp = getTestEndpoint(communicator, 0);
+ string sref = "background:" + endp;
+ Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref);
test(obj);
- BackgroundPrx background = BackgroundPrx::uncheckedCast(obj);
+ BackgroundPrxPtr background = ICE_UNCHECKED_CAST(BackgroundPrx, obj);
- sref = "backgroundController:tcp -p 12011";
+ sref = "backgroundController:" + getTestEndpoint(communicator, 1, "tcp");
obj = communicator->stringToProxy(sref);
test(obj);
- BackgroundControllerPrx backgroundController = BackgroundControllerPrx::uncheckedCast(obj);
+ BackgroundControllerPrxPtr backgroundController = ICE_UNCHECKED_CAST(BackgroundControllerPrx, obj);
+#ifdef ICE_CPP11_MAPPING
+ auto plugin = dynamic_pointer_cast<PluginI>(communicator->getPluginManager()->getPlugin("Test"));
+#else
PluginI* plugin = dynamic_cast<PluginI*>(communicator->getPluginManager()->getPlugin("Test").get());
+#endif
assert(plugin);
ConfigurationPtr configuration = plugin->getConfiguration();
@@ -244,9 +253,9 @@ allTests(const Ice::CommunicatorPtr& communicator)
cout << "testing locator... " << flush;
{
- Ice::LocatorPrx locator;
- obj = communicator->stringToProxy("locator:default -p 12010")->ice_invocationTimeout(250);
- locator = Ice::LocatorPrx::uncheckedCast(obj);
+ Ice::LocatorPrxPtr locator;
+ obj = communicator->stringToProxy("locator:" + endp)->ice_invocationTimeout(250);
+ locator = ICE_UNCHECKED_CAST(Ice::LocatorPrx, obj);
obj = communicator->stringToProxy("background@Test")->ice_locator(locator)->ice_oneway();
backgroundController->pauseCall("findAdapterById");
@@ -260,14 +269,33 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
backgroundController->resumeCall("findAdapterById");
- obj = communicator->stringToProxy("locator:default -p 12010");
- locator = Ice::LocatorPrx::uncheckedCast(obj);
+ obj = communicator->stringToProxy("locator:" + endp);
+ locator = ICE_UNCHECKED_CAST(Ice::LocatorPrx, obj);
obj = obj->ice_locator(locator);
obj->ice_ping();
-
obj = communicator->stringToProxy("background@Test")->ice_locator(locator);
- BackgroundPrx bg = BackgroundPrx::uncheckedCast(obj);
+ BackgroundPrxPtr bg = ICE_UNCHECKED_CAST(BackgroundPrx, obj);
+#ifdef ICE_CPP11_MAPPING
+ backgroundController->pauseCall("findAdapterById");
+
+ promise<void> p1;
+ promise<void> p2;
+
+ bg->opAsync([&p1](){ p1.set_value(); }, [&p1](exception_ptr e){ p1.set_exception(e); });
+ bg->opAsync([&p2](){ p2.set_value(); }, [&p2](exception_ptr e){ p2.set_exception(e); });
+
+ auto f1 = p1.get_future();
+ auto f2 = p2.get_future();
+
+ test(f1.wait_for(chrono::milliseconds(0)) != future_status::ready);
+ test(f2.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ backgroundController->resumeCall("findAdapterById");
+
+ f1.get();
+ f2.get();
+#else
backgroundController->pauseCall("findAdapterById");
Ice::AsyncResultPtr r1 = bg->begin_op();
Ice::AsyncResultPtr r2 = bg->begin_op();
@@ -278,15 +306,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
bg->end_op(r2);
test(r1->isCompleted());
test(r2->isCompleted());
+#endif
}
cout << "ok" << endl;
cout << "testing router... " << flush;
{
- Ice::RouterPrx router;
-
- obj = communicator->stringToProxy("router:default -p 12010")->ice_invocationTimeout(250);
- router = Ice::RouterPrx::uncheckedCast(obj);
+ Ice::RouterPrxPtr router;
+ obj = communicator->stringToProxy("router:" + endp)->ice_invocationTimeout(250);
+ router = ICE_UNCHECKED_CAST(Ice::RouterPrx, obj);
obj = communicator->stringToProxy("background@Test")->ice_router(router)->ice_oneway();
backgroundController->pauseCall("getClientProxy");
@@ -300,12 +328,32 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
backgroundController->resumeCall("getClientProxy");
- obj = communicator->stringToProxy("router:default -p 12010");
- router = Ice::RouterPrx::uncheckedCast(obj);
+ obj = communicator->stringToProxy("router:" + endp);
+ router = ICE_UNCHECKED_CAST(Ice::RouterPrx, obj);
obj = communicator->stringToProxy("background@Test")->ice_router(router);
- BackgroundPrx bg = BackgroundPrx::uncheckedCast(obj);
+ BackgroundPrxPtr bg = ICE_UNCHECKED_CAST(BackgroundPrx, obj);
test(bg->ice_getRouter());
+#ifdef ICE_CPP11_MAPPING
+ backgroundController->pauseCall("getClientProxy");
+
+ promise<void> p1;
+ promise<void> p2;
+
+ bg->opAsync([&p1](){ p1.set_value(); }, [&p1](exception_ptr e){ p1.set_exception(e); });
+ bg->opAsync([&p2](){ p2.set_value(); }, [&p2](exception_ptr e){ p2.set_exception(e); });
+
+ auto f1 = p1.get_future();
+ auto f2 = p2.get_future();
+
+ test(f1.wait_for(chrono::milliseconds(0)) != future_status::ready);
+ test(f2.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ backgroundController->resumeCall("getClientProxy");
+
+ f1.get();
+ f2.get();
+#else
backgroundController->pauseCall("getClientProxy");
Ice::AsyncResultPtr r1 = bg->begin_op();
Ice::AsyncResultPtr r2 = bg->begin_op();
@@ -316,6 +364,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
bg->end_op(r2);
test(r1->isCompleted());
test(r2->isCompleted());
+#endif
}
cout << "ok" << endl;
@@ -327,8 +376,38 @@ allTests(const Ice::CommunicatorPtr& communicator)
configuration->buffered(true);
backgroundController->buffered(true);
+
+#ifdef ICE_CPP11_MAPPING
+ background->opAsync();
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
+ background->opAsync();
+
+ vector<future<void>> results;
+ for(int i = 0; i < 10000; ++i)
+ {
+ auto f = background->opAsync();
+ if(i % 50 == 0)
+ {
+ backgroundController->holdAdapter();
+ backgroundController->resumeAdapter();
+ }
+ if(i % 100 == 0)
+ {
+ f.get();
+ }
+ else
+ {
+ results.push_back(move(f));
+ }
+ }
+
+ for(auto& f : results)
+ {
+ f.get(); // Ensure all the calls are completed before destroying the communicator
+ }
+#else
background->begin_op();
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
background->begin_op();
vector<Ice::AsyncResultPtr> results;
@@ -355,7 +434,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
(*p)->waitForCompleted(); // Ensure all the calls are completed before destroying the communicator
}
-
+#endif
cout << "ok" << endl;
}
@@ -363,7 +442,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
void
-connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& background)
+connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrxPtr& background)
{
try
{
@@ -373,7 +452,7 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
{
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
int i;
for(i = 0; i < 4; ++i)
@@ -386,7 +465,7 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
{
configuration->connectException(new Ice::SocketException(__FILE__, __LINE__));
}
- BackgroundPrx prx = (i == 1 || i == 3) ? background : background->ice_oneway();
+ BackgroundPrxPtr prx = (i == 1 || i == 3) ? background : background->ice_oneway();
try
{
@@ -396,7 +475,48 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
catch(const Ice::Exception&)
{
}
+#ifdef ICE_CPP11_MAPPING
+ {
+ promise<void> completed;
+ promise<bool> sent;
+ prx->opAsync(
+ [&completed]()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr)
+ {
+ completed.set_value();
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+ }
+
+ {
+ promise<void> completed;
+ promise<bool> sent;
+ prx->opAsync(
+ [&completed]()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr)
+ {
+ completed.set_value();
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+ }
+#else
Ice::AsyncResultPtr r = prx->begin_op();
test(!r->sentSynchronously());
try
@@ -414,7 +534,7 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
test(!r->sentSynchronously());
cbEx->checkException();
test(r->isCompleted());
-
+#endif
if(i == 0 || i == 2)
{
configuration->connectorsException(0);
@@ -440,7 +560,7 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
}
configuration->connectException(new Ice::SocketException(__FILE__, __LINE__));
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
configuration->connectException(0);
try
@@ -461,8 +581,8 @@ connectTests(const ConfigurationPtr& configuration, const Test::BackgroundPrx& b
void
initializeTests(const ConfigurationPtr& configuration,
- const Test::BackgroundPrx& background,
- const Test::BackgroundControllerPrx& ctl)
+ const Test::BackgroundPrxPtr& background,
+ const Test::BackgroundControllerPrxPtr& ctl)
{
try
{
@@ -472,7 +592,7 @@ initializeTests(const ConfigurationPtr& configuration,
{
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
int i;
for(i = 0; i < 4; i++)
@@ -490,7 +610,7 @@ initializeTests(const ConfigurationPtr& configuration,
configuration->initializeException(new Ice::SocketException(__FILE__, __LINE__));
#endif
}
- BackgroundPrx prx = (i == 1 || i == 3) ? background : background->ice_oneway();
+ BackgroundPrxPtr prx = (i == 1 || i == 3) ? background : background->ice_oneway();
try
{
@@ -501,6 +621,26 @@ initializeTests(const ConfigurationPtr& configuration,
{
}
+#ifdef ICE_CPP11_MAPPING
+ promise<bool> sent;
+ promise<void> completed;
+
+ prx->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr)
+ {
+ completed.set_value();
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = prx->begin_op();
test(!r->sentSynchronously());
try
@@ -518,7 +658,7 @@ initializeTests(const ConfigurationPtr& configuration,
test(!r->sentSynchronously());
cbEx->checkException();
test(r->isCompleted());
-
+#endif
if(i == 0 || i == 2)
{
configuration->initializeException(0);
@@ -537,11 +677,12 @@ initializeTests(const ConfigurationPtr& configuration,
background->op();
configuration->initializeSocketOperation(IceInternal::SocketOperationNone);
}
- catch(const Ice::LocalException&)
+ catch(const Ice::LocalException& ex)
{
+ cerr << ex << endl;
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -549,11 +690,12 @@ initializeTests(const ConfigurationPtr& configuration,
background->op();
configuration->initializeSocketOperation(IceInternal::SocketOperationNone);
}
- catch(const Ice::LocalException&)
+ catch(const Ice::LocalException& ex)
{
+ cerr << ex << endl;
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
#endif
//
@@ -586,7 +728,7 @@ initializeTests(const ConfigurationPtr& configuration,
{
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -622,7 +764,7 @@ initializeTests(const ConfigurationPtr& configuration,
}
configuration->initializeException(new Ice::SocketException(__FILE__, __LINE__));
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
configuration->initializeException(0);
try
@@ -642,12 +784,12 @@ initializeTests(const ConfigurationPtr& configuration,
}
configuration->initializeSocketOperation(IceInternal::SocketOperationWrite);
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
background->ice_ping();
configuration->initializeSocketOperation(IceInternal::SocketOperationNone);
ctl->initializeException(true);
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
ctl->initializeException(false);
try
@@ -670,11 +812,11 @@ initializeTests(const ConfigurationPtr& configuration,
{
#if !defined(ICE_USE_IOCP) && !defined(ICE_USE_CFSTREAM)
ctl->initializeSocketOperation(IceInternal::SocketOperationWrite);
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
background->op();
ctl->initializeSocketOperation(IceInternal::SocketOperationNone);
#else
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
background->op();
#endif
}
@@ -694,8 +836,8 @@ initializeTests(const ConfigurationPtr& configuration,
void
validationTests(const ConfigurationPtr& configuration,
- const Test::BackgroundPrx& background,
- const Test::BackgroundControllerPrx& ctl)
+ const Test::BackgroundPrxPtr& background,
+ const Test::BackgroundControllerPrxPtr& ctl)
{
try
{
@@ -705,7 +847,7 @@ validationTests(const ConfigurationPtr& configuration,
{
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -728,7 +870,27 @@ validationTests(const ConfigurationPtr& configuration,
for(i = 0; i < 2; i++)
{
configuration->readException(new Ice::SocketException(__FILE__, __LINE__));
- BackgroundPrx prx = i == 0 ? background : background->ice_oneway();
+ BackgroundPrxPtr prx = i == 0 ? background : background->ice_oneway();
+#ifdef ICE_CPP11_MAPPING
+ promise<bool> sent;
+ promise<void> completed;
+
+ prx->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr)
+ {
+ completed.set_value();
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = prx->begin_op();
test(!r->sentSynchronously());
try
@@ -740,6 +902,7 @@ validationTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->readException(0);
}
@@ -758,7 +921,7 @@ validationTests(const ConfigurationPtr& configuration,
cerr << ex << endl;
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -783,6 +946,30 @@ validationTests(const ConfigurationPtr& configuration,
{
configuration->readReady(false);
configuration->readException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<void> completed;
+ background->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr err)
+ {
+ try
+ {
+ rethrow_exception(err);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ });
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = background->begin_op();
test(!r->sentSynchronously());
try
@@ -794,12 +981,62 @@ validationTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->readException(0);
configuration->readReady(true);
}
}
ctl->holdAdapter(); // Hold to block in connection validation
+#ifdef ICE_CPP11_MAPPING
+ promise<void> p1;
+ promise<void> p2;
+
+ promise<bool> s1;
+ promise<bool> s2;
+
+ background->opAsync(
+ [&p1]()
+ {
+ p1.set_value();
+ },
+ [&p1](exception_ptr e)
+ {
+ p1.set_exception(e);
+ },
+ [&s1](bool value)
+ {
+ s1.set_value(value);
+ });
+
+ background->opAsync(
+ [&p2]()
+ {
+ p2.set_value();
+ },
+ [&p2](exception_ptr e)
+ {
+ p2.set_exception(e);
+ },
+ [&s2](bool value)
+ {
+ s2.set_value(value);
+ });
+
+ test(s1.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ test(s2.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ auto f1 = p1.get_future();
+ auto f2 = p2.get_future();
+
+ test(f1.wait_for(chrono::milliseconds(0)) != future_status::ready);
+ test(f2.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ ctl->resumeAdapter();
+
+ f1.get();
+ f2.get();
+#else
Ice::AsyncResultPtr r = background->begin_op();
Ice::AsyncResultPtr r2 = background->begin_op();
test(!r->sentSynchronously() && !r2->sentSynchronously());
@@ -808,6 +1045,7 @@ validationTests(const ConfigurationPtr& configuration,
background->end_op(r);
background->end_op(r2);
test(r->isCompleted() && r2->isCompleted());
+#endif
#if defined(ICE_USE_IOCP) || defined(ICE_USE_CFSTREAM)
if(background->ice_getCommunicator()->getProperties()->getProperty("Ice.Default.Protocol") != "test-ssl" &&
@@ -843,7 +1081,7 @@ validationTests(const ConfigurationPtr& configuration,
cerr << ex << endl;
test(false);
}
- background->ice_getConnection()->close(false);
+ background->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -870,7 +1108,7 @@ validationTests(const ConfigurationPtr& configuration,
Ice::ByteSeq seq;
seq.resize(512 * 1024);
- BackgroundPrx backgroundBatchOneway = BackgroundPrx::uncheckedCast(background->ice_batchOneway());
+ BackgroundPrxPtr backgroundBatchOneway = ICE_UNCHECKED_CAST(BackgroundPrx, background->ice_batchOneway());
//
// First send small requests to test without auto-flushing.
@@ -920,8 +1158,12 @@ validationTests(const ConfigurationPtr& configuration,
backgroundBatchOneway->op();
backgroundBatchOneway->op();
ctl->resumeAdapter();
+#ifdef ICE_CPP11_MAPPING
+ backgroundBatchOneway->ice_flushBatchRequestsAsync();
+#else
backgroundBatchOneway->begin_ice_flushBatchRequests();
- backgroundBatchOneway->ice_getConnection()->close(false);
+#endif
+ backgroundBatchOneway->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
ctl->holdAdapter();
backgroundBatchOneway->opWithPayload(seq);
@@ -929,6 +1171,9 @@ validationTests(const ConfigurationPtr& configuration,
backgroundBatchOneway->opWithPayload(seq);
backgroundBatchOneway->opWithPayload(seq);
ctl->resumeAdapter();
+#ifdef ICE_CPP11_MAPPING
+ backgroundBatchOneway->ice_flushBatchRequestsAsync().get();
+#else
r = backgroundBatchOneway->begin_ice_flushBatchRequests();
//
// We can't close the connection before ensuring all the batches
@@ -938,15 +1183,16 @@ validationTests(const ConfigurationPtr& configuration,
// in the flush to report a CloseConnectionException). Instead we
// wait for the first flush to complete.
//
- //backgroundBatchOneway->ice_getConnection()->close(false);
+ //backgroundBatchOneway->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
backgroundBatchOneway->end_ice_flushBatchRequests(r);
- backgroundBatchOneway->ice_getConnection()->close(false);
+#endif
+ backgroundBatchOneway->ice_getConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
}
void
readWriteTests(const ConfigurationPtr& configuration,
- const Test::BackgroundPrx& background,
- const Test::BackgroundControllerPrx& ctl)
+ const Test::BackgroundPrxPtr& background,
+ const Test::BackgroundControllerPrxPtr& ctl)
{
try
{
@@ -961,7 +1207,7 @@ readWriteTests(const ConfigurationPtr& configuration,
int i;
for(i = 0; i < 2; i++)
{
- BackgroundPrx prx = i == 0 ? background : background->ice_oneway();
+ BackgroundPrxPtr prx = i == 0 ? background : background->ice_oneway();
try
{
@@ -977,6 +1223,36 @@ readWriteTests(const ConfigurationPtr& configuration,
background->ice_ping();
configuration->writeException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<bool> sent;
+ promise<void> completed;
+ prx->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = prx->begin_op();
test(!r->sentSynchronously());
try
@@ -988,6 +1264,7 @@ readWriteTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->writeException(0);
}
@@ -1006,6 +1283,30 @@ readWriteTests(const ConfigurationPtr& configuration,
background->ice_ping();
configuration->readReady(false); // Required in C# to make sure beginRead() doesn't throw too soon.
configuration->readException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<void> completed;
+ background->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ });
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = background->begin_op();
try
{
@@ -1016,6 +1317,7 @@ readWriteTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->readException(0);
configuration->readReady(true);
@@ -1065,11 +1367,41 @@ readWriteTests(const ConfigurationPtr& configuration,
for(i = 0; i < 2; ++i)
{
- BackgroundPrx prx = i == 0 ? background : background->ice_oneway();
+ BackgroundPrxPtr prx = i == 0 ? background : background->ice_oneway();
background->ice_ping();
configuration->writeReady(false);
configuration->writeException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<void> completed;
+ promise<bool> sent;
+ prx->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ },
+ [&sent](bool value)
+ {
+ sent.set_value(value);
+ });
+ test(sent.get_future().wait_for(chrono::milliseconds(0)) != future_status::ready);
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = prx->begin_op();
test(!r->sentSynchronously());
try
@@ -1081,6 +1413,7 @@ readWriteTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->writeReady(true);
configuration->writeException(0);
}
@@ -1103,6 +1436,31 @@ readWriteTests(const ConfigurationPtr& configuration,
background->ice_ping();
configuration->readReady(false);
configuration->readException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<void> completed;
+ background->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&completed](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ });
+ completed.get_future().get();
+
+#else
Ice::AsyncResultPtr r = background->begin_op();
try
{
@@ -1113,6 +1471,7 @@ readWriteTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->readReady(true);
configuration->readException(0);
}
@@ -1122,11 +1481,35 @@ readWriteTests(const ConfigurationPtr& configuration,
configuration->readReady(false);
configuration->writeReady(false);
configuration->readException(new Ice::SocketException(__FILE__, __LINE__));
+#ifdef ICE_CPP11_MAPPING
+ promise<void> completed;
+ background->opAsync(
+ []()
+ {
+ test(false);
+ },
+ [&](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::SocketException&)
+ {
+ completed.set_value();
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ });
+ completed.get_future().get();
+#else
Ice::AsyncResultPtr r = background->begin_op();
// The read exception might propagate before the message send is seen as completed on IOCP.
-#ifndef ICE_USE_IOCP
+# ifndef ICE_USE_IOCP
r->waitForSent();
-#endif
+# endif
try
{
background->end_op(r);
@@ -1136,6 +1519,7 @@ readWriteTests(const ConfigurationPtr& configuration,
{
}
test(r->isCompleted());
+#endif
configuration->writeReady(true);
configuration->readReady(true);
configuration->readException(0);
@@ -1146,7 +1530,7 @@ readWriteTests(const ConfigurationPtr& configuration,
background->ice_ping(); // Establish the connection
- BackgroundPrx backgroundOneway = BackgroundPrx::uncheckedCast(background->ice_oneway());
+ BackgroundPrxPtr backgroundOneway = ICE_UNCHECKED_CAST(BackgroundPrx, background->ice_oneway());
test(backgroundOneway->ice_getConnection() == background->ice_getConnection());
ctl->holdAdapter(); // Hold to block in request send.
@@ -1157,6 +1541,91 @@ readWriteTests(const ConfigurationPtr& configuration,
{
*p = static_cast<Ice::Byte>(IceUtilInternal::random(255));
}
+
+#ifdef ICE_CPP11_MAPPING
+
+ // Fill up the receive and send buffers
+ for(int i = 0; i < 200; ++i) // 2MB
+ {
+ backgroundOneway->opWithPayloadAsync(
+ seq,
+ []()
+ {
+ test(false);
+ },
+ [](exception_ptr)
+ {
+ test(false);
+ });
+ }
+ promise<void> c1;
+ promise<bool> s1;
+
+ background->opAsync(
+ [&c1]()
+ {
+ c1.set_value();
+ },
+ [](exception_ptr err)
+ {
+ test(false);
+ },
+ [&s1](bool value)
+ {
+ s1.set_value(value);
+ });
+ auto fs1 = s1.get_future();
+ test(fs1.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ promise<void> c2;
+ promise<bool> s2;
+ background->opAsync(
+ [&c2]()
+ {
+ c2.set_value();
+ },
+ [](exception_ptr err)
+ {
+ test(false);
+ },
+ [&s2](bool value)
+ {
+ s2.set_value(value);
+ });
+
+ auto fs2 = s2.get_future();
+ test(fs2.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ promise<bool> s3;
+ backgroundOneway->opWithPayloadAsync(seq,
+ [](){ test(false); },
+ [](exception_ptr){ test(false); },
+ [&s3](bool value){ s3.set_value(value); });
+ auto fs3 = s3.get_future();
+ test(fs3.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ promise<bool> s4;
+ backgroundOneway->opWithPayloadAsync(seq,
+ [](){ test(false); },
+ [](exception_ptr){ test(false); },
+ [&s4](bool value){ s4.set_value(value); });
+ auto fs4 = s4.get_future();
+ test(fs4.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ auto fc1 = c1.get_future();
+ test(fc1.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ auto fc2 = c2.get_future();
+ test(fc2.wait_for(chrono::milliseconds(0)) != future_status::ready);
+
+ ctl->resumeAdapter();
+
+ fs1.get();
+ fs2.get();
+
+ fc1.get();
+ fc2.get();
+#else
OpAMICallbackPtr cb = new OpAMICallback();
Callback_Background_opWithPayloadPtr callbackWP = newCallback_Background_opWithPayload(cb,
&OpAMICallback::noResponse,
@@ -1193,6 +1662,7 @@ readWriteTests(const ConfigurationPtr& configuration,
cb2->checkResponseAndSent();
test(r1->isSent() && r1->isCompleted());
test(r2->isSent() && r2->isCompleted());
+#endif
try
{
@@ -1305,10 +1775,10 @@ readWriteTests(const ConfigurationPtr& configuration,
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
background->ice_ping();
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
- background->ice_getCachedConnection()->close(true);
+ background->ice_getCachedConnection()->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
}
thread1->destroy();