test_admin.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "hello_test.h"
  17. #include "../server/WinServer.h"
  18. #include "servant/AdminF.h"
  19. #include "server/FrameworkServer.h"
  20. #include "server/framework/DbHandle.h"
  21. TEST_F(HelloTest, testAdmin)
  22. {
  23. FrameworkServer fs;
  24. startServer(fs, FRAMEWORK_CONFIG());
  25. CDbHandle::cleanEndPoint();
  26. CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.ConfigObj", 11003, 1);
  27. WinServer ws;
  28. startServer(ws, WIN_CONFIG());
  29. // auto c = getCommunicator();
  30. CommunicatorPtr c = ws.getCommunicator();
  31. string adminObj = "AdminObj@" + getLocalEndpoint(WIN_CONFIG()).toString();
  32. AdminFPrx adminFPrx = c->stringToProxy<AdminFPrx>(adminObj);
  33. string loadconfig = adminFPrx->notify("tars.loadconfig test.conf");
  34. EXPECT_TRUE(loadconfig.find("[succ] get remote config:") != string::npos);
  35. loadconfig = adminFPrx->notify("tars.loadconfig no-test.conf");
  36. EXPECT_TRUE(loadconfig.find("[fail] get remote config ") != string::npos);
  37. string setloglevel = adminFPrx->notify("tars.setloglevel DEBUG");
  38. EXPECT_TRUE(setloglevel.find("set log level [DEBUG] ok") != string::npos);
  39. string viewstatus = adminFPrx->notify("tars.viewstatus");
  40. EXPECT_TRUE(viewstatus.find("notify prefix object num:1") != string::npos);
  41. string viewversion = adminFPrx->notify("tars.viewversion");
  42. EXPECT_TRUE(viewversion.find("$") != string::npos);
  43. string connection = adminFPrx->notify("tars.connection");
  44. EXPECT_TRUE(connection.find("[adapter:AdminAdapter]") != string::npos);
  45. ServerConfig::ConfigFile = CONFIGPATH + "/server/windows.conf";
  46. string loadproperty = adminFPrx->notify("tars.loadproperty");
  47. EXPECT_TRUE(loadproperty.find("loaded config items:") != string::npos);
  48. string help = adminFPrx->notify("tars.help");
  49. EXPECT_TRUE(help.find("tars.closecore") != string::npos);
  50. string closecout = adminFPrx->notify("tars.closecout NO");
  51. string enabledaylog = adminFPrx->notify("tars.enabledaylog local|daylog|true");
  52. EXPECT_TRUE(enabledaylog.find("set local daylog true ok") != string::npos);
  53. enabledaylog = adminFPrx->notify("tars.enabledaylog remote|false");
  54. EXPECT_TRUE(enabledaylog.find("set remote false ok") != string::npos);
  55. string reloadlocator = adminFPrx->notify("tars.reloadlocator reload");
  56. EXPECT_TRUE(reloadlocator.find("[notify prefix object num:1]") != string::npos);
  57. // string closecore = adminFPrx->notify("tars.closecore no");
  58. // EXPECT_TRUE(closecore.find("after set cur:18446744073709551615;max: 18446744073709551615") != string::npos);
  59. // closecore = adminFPrx->notify("tars.closecore yes");
  60. // EXPECT_TRUE(closecore.find("after set cur:0;max: 18446744073709551615") != string::npos);
  61. string errorcmd = adminFPrx->notify("tars.errorcmd");
  62. EXPECT_STREQ(errorcmd.c_str(), "");
  63. string normalcmd = adminFPrx->notify("AdminCmdNormalTest returnMark");
  64. EXPECT_STREQ(normalcmd.c_str(), "[notify servant object num:1]\n[1]:returnMark AdminCmdNormalTest success!\n");
  65. string normaldeletecmd = adminFPrx->notify("DeletePrefixCmd");
  66. EXPECT_STREQ(normaldeletecmd.c_str(), "[notify servant object num:1]\n[1]:Delete success!\n");
  67. stopServer(ws);
  68. stopServer(fs);
  69. }