main.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include <iostream>
  17. #include "servant/Communicator.h"
  18. #include "Proxy.h"
  19. using namespace std;
  20. using namespace TestApp;
  21. using namespace tars;
  22. int main(int argc,char ** argv)
  23. {
  24. Communicator comm;
  25. try
  26. {
  27. ProxyPrx prx;
  28. comm.stringToProxy("TestApp.ProxyServer.ProxyObj@tcp -h 127.0.0.1 -p 9200" , prx);
  29. int64_t t = TC_Common::now2us();
  30. try
  31. {
  32. int i = 10000;
  33. while(i-- >= 0)
  34. {
  35. string sReq("hello");
  36. string sRsp("");
  37. int iRet = prx->testProxy(sReq, sRsp);
  38. assert(iRet == 0);
  39. assert(sReq == sRsp);
  40. }
  41. int64_t cost = TC_Common::now2us() - t;
  42. cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/10000 << "us" << endl;
  43. }
  44. catch(exception &ex)
  45. {
  46. cerr << "ex:" << ex.what() << endl;
  47. }
  48. catch(...)
  49. {
  50. cerr << "unknown exception." << endl;
  51. }
  52. }
  53. catch(exception& e)
  54. {
  55. cerr << "exception:" << e.what() << endl;
  56. }
  57. catch (...)
  58. {
  59. cerr << "unknown exception." << endl;
  60. }
  61. return 0;
  62. }