def test_hosts_got_sorted(self): collection = HostsCollection([Host("a", 10), Host("b", 20), Host("c")]) hosts = collection.read() self.assertEqual(hosts[0].url, "b") self.assertEqual(hosts[1].url, "a") self.assertEqual(hosts[2].url, "c")
def test_hosts_got_sorted(self): collection = HostsCollection([Host('a', 10), Host('b', 20), Host('c')]) hosts = collection.read() self.assertEqual(hosts[0].url, 'b') self.assertEqual(hosts[1].url, 'a') self.assertEqual(hosts[2].url, 'c')
def build_hosts(self): # type: () -> HostsCollection return HostsCollection([ Host('{}-dsn.algolia.net'.format(self.app_id), 10, CallType.READ), Host('{}.algolia.net'.format(self.app_id), 10, CallType.WRITE), Host('{}-1.algolianet.com'.format(self.app_id)), Host('{}-2.algolianet.com'.format(self.app_id)), Host('{}-3.algolianet.com'.format(self.app_id)) ])
def hosts(app_id): # type: (str) -> HostsCollection hosts = [ Host('{}-1.algolianet.com'.format(app_id)), Host('{}-2.algolianet.com'.format(app_id)), Host('{}-3.algolianet.com'.format(app_id)) ] shuffle(hosts) return HostsCollection([hosts[0]])
def test_priority(self): # Default priority test self.assertEqual(self.host.priority, 0) host_with_less_priority = Host("foo.com", 5) # Specific priority self.assertEqual(host_with_less_priority.priority, 5)
def build_hosts(self): # type: () -> HostsCollection return HostsCollection([ Host("{}.{}.{}".format("personalization", self._region, "algolia.com")) ])
def build_hosts(self): # type: () -> HostsCollection return HostsCollection([ Host('{}.{}.{}'.format('recommendation', self._region, 'algolia.com')) ])
def test_dns_timeout(self): config = SearchConfig(F.get_app_id(), F.get_api_key()) config.hosts = HostsCollection([ Host('algolia.biz', 10), Host('{}-1.algolianet.com'.format(F.get_app_id())), Host('{}-2.algolianet.com'.format(F.get_app_id())), Host('{}-3.algolianet.com'.format(F.get_app_id())) ]) client = SearchClient.create_with_config(config) client.list_indices() # We test that the first Host `algolia.biz` is down. self.assertFalse(config.hosts.read()[0].up) self.assertTrue(config.hosts.read()[1].up) self.assertTrue(config.hosts.read()[2].up) self.assertTrue(config.hosts.read()[3].up)
def test_down_hosts(self): a = Host('a', 10) b = Host('b', 20) c = Host('c') self.retry_strategy._now = mock.Mock(name="_now") self.retry_strategy._now.return_value = 1000 hosts = list(self.retry_strategy.valid_hosts([a, b, c])) self.assertEqual(len(hosts), 3) a.last_use = 800.0 # 1000 - 800 = 200 (lower than TTL - 300) a.up = False hosts = list(self.retry_strategy.valid_hosts([a, b, c])) self.assertEqual(len(hosts), 2) # still down a.last_use = 400.0 # 1000 - 400 = 600 (bigger than TTL - 300) hosts = list(self.retry_strategy.valid_hosts([a, b, c])) self.assertEqual(len(hosts), 3) # got up
def setUp(self): self.host = Host("foo.com")
def setUp(self): self.time = time.time() self.retry_strategy = RetryStrategy() self.host = Host('foo.com') self.response = Response()
def build_hosts(self): # type: () -> HostsCollection return HostsCollection( [Host('{}.{}.{}'.format('insights', self._region, 'algolia.io'))])
def setUp(self): self.host = Host('foo.com')
def build_hosts(self): # type: () -> HostsCollection return HostsCollection( [Host("{}.{}.{}".format("insights", self._region, "algolia.io"))])