locator_uniq_ut.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include <library/cpp/messagebus/test_utils.h>
  3. #include <library/cpp/messagebus/ybus.h>
  4. class TLocatorRegisterUniqTest: public TTestBase {
  5. UNIT_TEST_SUITE(TLocatorRegisterUniqTest);
  6. UNIT_TEST(TestRegister);
  7. UNIT_TEST_SUITE_END();
  8. protected:
  9. void TestRegister();
  10. };
  11. UNIT_TEST_SUITE_REGISTRATION(TLocatorRegisterUniqTest);
  12. void TLocatorRegisterUniqTest::TestRegister() {
  13. ASSUME_IP_V4_ENABLED;
  14. NBus::TBusLocator locator;
  15. const char* serviceName = "TestService";
  16. const char* hostName = "192.168.0.42";
  17. int port = 31337;
  18. NBus::TBusKeyVec keys;
  19. locator.LocateKeys(serviceName, keys);
  20. UNIT_ASSERT(keys.size() == 0);
  21. locator.Register(serviceName, hostName, port);
  22. locator.LocateKeys(serviceName, keys);
  23. /// YBUS_KEYMIN YBUS_KEYMAX range
  24. UNIT_ASSERT(keys.size() == 1);
  25. TVector<NBus::TNetAddr> hosts;
  26. UNIT_ASSERT(locator.LocateAll(serviceName, NBus::YBUS_KEYMIN, hosts) == 1);
  27. locator.Register(serviceName, hostName, port);
  28. hosts.clear();
  29. UNIT_ASSERT(locator.LocateAll(serviceName, NBus::YBUS_KEYMIN, hosts) == 1);
  30. }