diff options
Diffstat (limited to 'cpp/test/Ice/ami/AllTests.cpp')
-rw-r--r-- | cpp/test/Ice/ami/AllTests.cpp | 437 |
1 files changed, 436 insertions, 1 deletions
diff --git a/cpp/test/Ice/ami/AllTests.cpp b/cpp/test/Ice/ami/AllTests.cpp index 8fd66031174..4fdfb66dd44 100644 --- a/cpp/test/Ice/ami/AllTests.cpp +++ b/cpp/test/Ice/ami/AllTests.cpp @@ -945,6 +945,50 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 async callback... " << flush; + { + AsyncCallbackPtr cb = new AsyncCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + + p->begin_ice_ping([=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + p->begin_ice_ping(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + + p->begin_ice_id([=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + p->begin_ice_id(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + + p->begin_ice_ids([=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + p->begin_ice_ids(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + + p->begin_op([=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + p->begin_op(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + + p->begin_opWithResult([=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + p->begin_opWithResult(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + + p->begin_opWithUE([=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + p->begin_opWithUE(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing response callback... " << flush; { @@ -1031,6 +1075,58 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 response callback... " << flush; + { + ResponseCallbackPtr cb = new ResponseCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }); + cb->check(); + + p->begin_ice_ping(ctx, [=](){ cb->ping(); }); + cb->check(); + + + p->begin_ice_id([=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_id(ctx, [=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_ice_ids(ctx, [=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }); + cb->check(); + + p->begin_op(ctx, [=](){ cb->op(); }); + cb->check(); + + p->begin_opWithResult([=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithResult(ctx, [=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithUE([](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + + p->begin_opWithUE(ctx, [](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif + cout << "testing local exceptions... " << flush; { Test::TestIntfPrx indirect = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1111,7 +1207,7 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; - + cout << "testing local exceptions with response callback... " << flush; { Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1151,6 +1247,30 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing local exceptions with C++11 response callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), std::function<void (bool)>([](bool){ test(false); }), [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ping([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_id([](const string&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ids([](const Ice::StringSeq&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_op([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing exception callback... " << flush; { @@ -1200,6 +1320,32 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 exception callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){cb->ex(ex); }); + cb->check(); + + i->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + // Ensures no exception is called when response is received + p->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + p->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + + // If response is a user exception, it should be received. + p->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing sent callback... " << flush; { @@ -1280,6 +1426,79 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 sent callback... " << flush; + { + SentCallbackPtr cb = new SentCallback; + + p->begin_ice_isA("", [=](bool v){ cb->isA(v); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_id([=](const string& id){ cb->id(id); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + + p->begin_op([=](){ cb->op(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, + nullptr, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op(nullptr, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + vector<SentCallbackPtr> cbs; + Ice::ByteSeq seq; + seq.resize(1024); // Make sure the request doesn't compress too well. + for(Ice::ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) + { + *q = static_cast<Ice::Byte>(IceUtilInternal::random(255)); + } + testController->holdAdapter(); + try + { + cb = new SentCallback(); + while(p->begin_opWithPayload(seq, nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); })->sentSynchronously()) + { + cbs.push_back(cb); + cb = new SentCallback(); + } + } + catch(...) + { + testController->resumeAdapter(); + throw; + } + testController->resumeAdapter(); + for(vector<SentCallbackPtr>::const_iterator r = cbs.begin(); r != cbs.end(); r++) + { + (*r)->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing illegal arguments... " << flush; { @@ -1427,6 +1646,32 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing unexpected exceptions from C++11 callback... " << flush; + { + Test::TestIntfPrx q = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ThrowType throwEx[] = { LocalException, UserException, StandardException, OtherException }; + + for(int i = 0; i < 4; ++i) + { + ThrowerPtr cb = new Thrower(throwEx[i]); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + p->begin_op([=](){ cb->noOp(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }, [=](bool sent){ cb->sent(sent); }); + cb->check(); + + q->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with proxy... " << flush; { @@ -1566,6 +1811,43 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with proxy... " << flush; + { + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with connection... " << flush; { CookiePtr cookie = new Cookie(5); @@ -1702,6 +1984,48 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with connection... " << flush; + { + { + // + // Without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with communicator... " << flush; { @@ -1973,6 +2297,117 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with communicator... " << flush; + { + { + // + // Without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + + { + // + // 2 connections. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b1->opBatch(); + b2->opBatch(); + b2->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(4)); + } + + { + // + // Exception - 2 connections - 1 failure. + // + // All connections should be flushed even if there are failures on some connections. + // Exceptions should not be reported. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->waitForBatch(1)); + } + + { + // + // Exception - 2 connections - 2 failures. + // + // The sent callback should be invoked even if all connections fail. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + b2->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing AsyncResult operations... " << flush; { { |