コード例 #1
0
 def testBasicRoundRobin(self):
     """ Set up a client with three different hosts to connect to, make
     multiple calls and check that each call goes on a different host in a
     Round Robin fashion
     """
     hosts = ['http://someserver1:9200', 'http://someserver2:9200',
              'http://someserver3:9200']
     es = Elastic(hosts, connection_pool_kwargs={'dead_timeout': 10})
     with patch('rawes.http_connection.requests.Session.request',
             MagicMock(return_value=None)) as request:
         request.return_value = Response()
         called = []
         for _ in xrange(len(hosts)):
             es.get()
             # Save a list of called hosts (and remove trailing /)
             called.append(request.call_args[0][1][:-1])
         # Check against original hosts list
         self.assertSetEqual(set(hosts), set(called),
                         'All hosts in coonnection pool should be used')
         called_again = []
         for _ in xrange(len(hosts)):
             es.get()
             # Call the same hosts again (don't forget about the trailing /)
             called_again.append(request.call_args[0][1][:-1])
         # Check they were called in the same order as before
         self.assertListEqual(called, called_again,
                                 'Round robin order wasn\'t preserved')
コード例 #2
0
 def testConnectionSpecified(self):
     """ When a connection is specified to the constructor, a conenction
     pool object should be created with that single connection
     """
     connection = HttpConnection('http://singleconnectionhost:9200')
     es = Elastic(connection=connection)
     with patch('rawes.http_connection.requests.Session.request',
             MagicMock(return_value=None)) as request:
         request.return_value = Response()
         es.get()
         request.assert_called_with('get',
                                    'http://singleconnectionhost:9200/',
                                    timeout=None)
コード例 #3
0
 def testBasicRoundRobin(self):
     """ Set up a client with three different hosts to connect to, make
     multiple calls and check that each call goes on a different host in a
     Round Robin fashion
     """
     hosts = [
         'http://someserver1:9200', 'http://someserver2:9200',
         'http://someserver3:9200'
     ]
     es = Elastic(hosts, connection_pool_kwargs={'dead_timeout': 10})
     with patch('rawes.http_connection.requests.Session.request',
                MagicMock(return_value=None)) as request:
         request.return_value = Response()
         called = []
         for _ in xrange(len(hosts)):
             es.get()
             # Save a list of called hosts (and remove trailing /)
             called.append(request.call_args[0][1][:-1])
         # Check against original hosts list
         self.assertSetEqual(
             set(hosts), set(called),
             'All hosts in coonnection pool should be used')
         called_again = []
         for _ in xrange(len(hosts)):
             es.get()
             # Call the same hosts again (don't forget about the trailing /)
             called_again.append(request.call_args[0][1][:-1])
         # Check they were called in the same order as before
         self.assertListEqual(called, called_again,
                              'Round robin order wasn\'t preserved')