test_async_rpc.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 
  2. #include "hello_test.h"
  3. TEST_F(HelloTest, rpcASyncGlobalCommunicator)
  4. {
  5. shared_ptr<Communicator> c = getCommunicator();
  6. transGlobalCommunicator([&](Communicator *comm){
  7. checkASync(comm);
  8. }, c.get());
  9. }
  10. TEST_F(HelloTest, rpcASyncGlobalCommunicatorInCoroutine)
  11. {
  12. shared_ptr<Communicator> c = getCommunicator();
  13. transInCoroutineGlobalCommunicator([&](Communicator *comm){
  14. checkASync(comm);
  15. }, c.get());
  16. }
  17. TEST_F(HelloTest, rpcASyncServerCommunicator)
  18. {
  19. transServerCommunicator([&](Communicator *comm){
  20. checkASync(comm);
  21. });
  22. }
  23. TEST_F(HelloTest, rpcASyncServerCommunicatorInCoroutine)
  24. {
  25. transInCoroutineServerCommunicator([&](Communicator *comm){
  26. checkASync(comm);
  27. });
  28. }
  29. TEST_F(HelloTest, rpcASyncAllocCommunicator)
  30. {
  31. transAllocCommunicator([&](Communicator *comm){
  32. checkASync(comm);
  33. });
  34. }
  35. TEST_F(HelloTest, rpcASyncAllocCommunicatorInCoroutine)
  36. {
  37. transInCoroutineAllocCommunicator([&](Communicator *comm){
  38. checkASync(comm);
  39. });
  40. }
  41. TEST_F(HelloTest, rpcASyncComplexCommunicator)
  42. {
  43. shared_ptr<Communicator> c = getCommunicator();
  44. transComplexCommunicator([&](Communicator *comm){
  45. checkASync(comm);
  46. }, c.get());
  47. transComplexCommunicator([&](Communicator *comm){
  48. checkASync(comm);
  49. }, c.get());
  50. transComplexCommunicator([&](Communicator *comm){
  51. checkASync(comm);
  52. }, c.get());
  53. transComplexCommunicator([&](Communicator *comm){
  54. checkASync(comm);
  55. }, c.get());
  56. }
  57. TEST_F(HelloTest, rpcASyncComplexCommunicatorInCoroutine)
  58. {
  59. shared_ptr<Communicator> c = getCommunicator();
  60. transInCoroutineComplexCommunicator([&](Communicator *comm)
  61. {
  62. checkASync(comm);
  63. },
  64. c.get());
  65. transInCoroutineComplexCommunicator([&](Communicator *comm){
  66. checkASync(comm);
  67. }, c.get());
  68. transInCoroutineComplexCommunicator([&](Communicator *comm){
  69. checkASync(comm);
  70. }, c.get());
  71. transInCoroutineComplexCommunicator([&](Communicator *comm){
  72. checkASync(comm);
  73. }, c.get());
  74. }
  75. TEST_F(HelloTest, rpcASyncThreadFinish)
  76. {
  77. shared_ptr<Communicator> c = getCommunicator();
  78. HelloServer server;
  79. startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0);
  80. atomic<int> callback_count{0};
  81. int count = 10000;
  82. {
  83. std::thread cor_call([&]()
  84. {
  85. HelloPrx prx = getObj<HelloPrx>(c.get(), "HelloAdapter");
  86. //发起远程调用
  87. for (int j = 0; j < count; ++j)
  88. {
  89. HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, count, _buffer, callback_count);
  90. prx->async_testHello(p, j, _buffer);
  91. }
  92. });
  93. cor_call.join();
  94. }
  95. waitForFinish(callback_count, count);
  96. // TC_Common::sleep(10);
  97. // LOG_CONSOLE_DEBUG << _count << ", " << callback_count << endl;
  98. ASSERT_TRUE(count == callback_count);
  99. stopServer(server);
  100. }