test_prx_update.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. 
  2. #include "hello_test.h"
  3. #include "servant/CommunicatorEpoll.h"
  4. #include "servant/ObjectProxy.h"
  5. #include "server/framework/DbHandle.h"
  6. #include "server/FrameworkServer.h"
  7. #include "QueryF.h"
  8. TEST_F(HelloTest, prxUpdate)
  9. {
  10. shared_ptr<Communicator> comm = getCommunicator();
  11. RpcServer rpc1Server;
  12. startServer(rpc1Server, RPC1_CONFIG());
  13. RpcServer rpc2Server;
  14. startServer(rpc2Server, RPC2_CONFIG());
  15. HelloPrx qPrx = comm->stringToProxy<HelloPrx>("TestApp.RpcServer.HelloObj@tcp -h 127.0.0.1 -p 9990:tcp -h 127.0.0.1 -p 9991");
  16. int ret;
  17. string out;
  18. ret = qPrx->testHello(0, _buffer, out);
  19. ASSERT_TRUE(ret == 0);
  20. ASSERT_TRUE(out == _buffer);
  21. set<EndpointInfo> active;
  22. active.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9992")));
  23. set<EndpointInfo> inactive;
  24. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9990")));
  25. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9991")));
  26. qPrx->tars_update_endpoints(active, inactive);
  27. stopServer(rpc1Server);
  28. stopServer(rpc2Server);
  29. RpcServer rpc3Server;
  30. startServer(rpc3Server, RPC3_CONFIG());
  31. ret = qPrx->testHello(0, _buffer, out);
  32. ASSERT_TRUE(ret == 0);
  33. ASSERT_TRUE(out == _buffer);
  34. stopServer(rpc3Server);
  35. }
  36. TEST_F(HelloTest, prxUpdateInCoroutine1)
  37. {
  38. shared_ptr<Communicator> comm = getCommunicator();
  39. RpcServer rpc1Server;
  40. startServer(rpc1Server, RPC1_CONFIG());
  41. RpcServer rpc2Server;
  42. startServer(rpc2Server, RPC2_CONFIG());
  43. int ret;
  44. string out;
  45. HelloPrx qPrx;
  46. funcInCoroutine([&](){
  47. qPrx = comm->stringToProxy<HelloPrx>("TestApp.RpcServer.HelloObj@tcp -h 127.0.0.1 -p 9990:tcp -h 127.0.0.1 -p 9991");
  48. ret = qPrx->testHello(0, _buffer, out);
  49. ASSERT_TRUE(ret == 0);
  50. ASSERT_TRUE(out == _buffer);
  51. });
  52. set<EndpointInfo> active;
  53. active.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9992")));
  54. set<EndpointInfo> inactive;
  55. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9990")));
  56. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9991")));
  57. qPrx->tars_update_endpoints(active, inactive);
  58. stopServer(rpc1Server);
  59. stopServer(rpc2Server);
  60. RpcServer rpc3Server;
  61. startServer(rpc3Server, RPC3_CONFIG());
  62. ret = qPrx->testHello(0, _buffer, out);
  63. ASSERT_TRUE(ret == 0);
  64. ASSERT_TRUE(out == _buffer);
  65. stopServer(rpc3Server);
  66. }
  67. TEST_F(HelloTest, prxUpdateInCoroutine2)
  68. {
  69. shared_ptr<Communicator> comm = getCommunicator();
  70. RpcServer rpc1Server;
  71. startServer(rpc1Server, RPC1_CONFIG());
  72. RpcServer rpc2Server;
  73. startServer(rpc2Server, RPC2_CONFIG());
  74. int ret;
  75. string out;
  76. HelloPrx qPrx;
  77. funcInCoroutine([&](){
  78. qPrx = comm->stringToProxy<HelloPrx>("TestApp.RpcServer.HelloObj@tcp -h 127.0.0.1 -p 9990:tcp -h 127.0.0.1 -p 9991");
  79. ret = qPrx->testHello(0, _buffer, out);
  80. ASSERT_TRUE(ret == 0);
  81. ASSERT_TRUE(out == _buffer);
  82. }, true);
  83. funcInCoroutine([&]()
  84. {
  85. set<EndpointInfo> active;
  86. active.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9992")));
  87. set<EndpointInfo> inactive;
  88. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9990")));
  89. inactive.insert(EndpointInfo(TC_Endpoint("tcp -h 127.0.0.1 -p 9991")));
  90. qPrx->tars_update_endpoints(active, inactive);
  91. }, true);
  92. stopServer(rpc1Server);
  93. stopServer(rpc2Server);
  94. RpcServer rpc3Server;
  95. startServer(rpc3Server, RPC3_CONFIG());
  96. ret = qPrx->testHello(0, _buffer, out);
  97. ASSERT_TRUE(ret == 0);
  98. ASSERT_TRUE(out == _buffer);
  99. stopServer(rpc3Server);
  100. }