def test_request_no_active_pool(self): client = SolrRequest( ["http://localsolr:7070/solr/", "http://localsolr:8080/solr/"], zookeeper_hosts=["http://localzook:2181", "http://localzook:2181"]) client.current_hosts = '' # simulate an empty pool with mock.patch('requests.sessions.Session.request') as mock_request: fake_response = Response() fake_response.status_code = 200 fake_response.text = json.dumps({'fake_data': 'fake_value'}) mock_request.return_value = fake_response with self.assertRaises(SolrError) as cm: response = client.request('fake_path', {"fake_params": "fake_value"}, 'GET', body={"fake_body": "fake_value"}) solr_error = cm.exception self.assertEqual(str(solr_error), "SOLR reporting all nodes as down") # add nodes back to the bool client.current_hosts = [ "http://localsolr:7070/solr/", "http://localsolr:8080/solr/" ] response = client.request('fake_path', {"fake_params": "fake_value"}, 'GET', body={"fake_body": "fake_value"})
def test_request_refill_pool(self): client = SolrRequest( ["http://localsolr:7070/solr/", "http://localsolr:8080/solr/"], zookeeper_hosts=["http://localzook:2181", "http://localzook:2181"]) # simulate an empty pool and a 5 minute old error client.current_hosts = ["http://localsolr:8080/solr/"] client.last_error = time.time() - 5 with mock.patch('requests.sessions.Session.request') as mock_request: fake_response = Response() fake_response.status_code = 200 fake_response.text = json.dumps({'fake_data': 'fake_value'}) mock_request.return_value = fake_response response = client.request('fake_path', {"fake_params": "fake_value"}, 'GET', body={"fake_body": "fake_value"}) self.assertEqual(client.current_hosts, client.master_hosts)