Beispiel #1
0
    def test_execution_select_success(self, pool):
        """
        Test the execution of a select command that is successful.
        """
        command = stellr.SelectCommand(TEST_HTTP, name='test select')
        self.assertEquals(command.pool, pool)
        response = self._create_execution_mocks(pool, 200)

        command.add_param('fq', 'field:filter')
        data = command.execute()

        # check the mock
        hdrs = {
            'connection': 'keep-alive',
            'content-type': ('application/x-www-form-urlencoded; '
                             'charset=utf-8')
        }
        pool.urlopen.assert_called_once_with(
            'GET',
            'http://localhost:8983/solr/select?wt=json&fq=field%3Afilter',
            body=None,
            headers=hdrs,
            timeout=15,
            assert_same_host=False)

        self.assertEqual(len(data), 2)
        self.assertEqual(data['key'], 'value')
        self.assertEqual(data['number'], 42)

        # verify name is returned
        data, name = command.execute(return_name=True)
        self.assertEqual(name, 'test select')
        self.assertEqual(len(data), 2)
        self.assertEqual(data['key'], 'value')
        self.assertEqual(data['number'], 42)
Beispiel #2
0
    def test_select_command(self):
        """Test the SelectCommand."""
        wt = [('wt', 'json')]
        q = stellr.SelectCommand(TEST_HTTP, handler='/solr/test/search')
        self.assertEqual(q.host, 'http://localhost:8983')
        self.assertEqual(q._handler, '/solr/test/search')
        self.assertEqual(q._commands, wt)

        self._add_query_params(q, CLAUSES)
        for c in CLAUSES:
            wt.append(c)
        self.assertEqual(q._commands, wt)
        self.assertEqual(q.handler, ('/solr/test/search?'
                                     'wt=json&q=test+query&sort=name+asc'))
        q.clear_command()
        self.assertEqual(len(q._commands), 0)
Beispiel #3
0
    def test_zmq_execution_select_success(self, pool):
        """
        Test the execution of a select command that is successful.
        """
        s, c = self._create_zmq_execution_mocks(pool)
        command = stellr.SelectCommand(TEST_ZMQ)
        command.add_param('fq', 'field:filter')
        data = command.execute()

        # check the mocks
        s.send.assert_called_once_with('/select?wt=json&fq=field%3Afilter')

        self.assertEqual(len(data), 2)
        self.assertEqual(data['responseHeader']['status'], 0)

        # verify name is returned
        data, name = command.execute(return_name=True)
        self.assertEqual(name, 'select')
Beispiel #4
0
    def test_zmq_execution_error_from_solr(self, pool):
        """
        Test the execution of a select command that is successful.
        """
        s, c = self._create_zmq_execution_mocks(pool, valid=False)
        command = stellr.SelectCommand(TEST_ZMQ)
        command.add_param('fq', 'field:filter')
        try:
            data = command.execute()
        except stellr.StellrError as e:
            pool.assert_called_once_with(TEST_ZMQ)
            self.assertFalse(e.timeout)
            self.assertEqual(e.status, 1)
            self.assertEqual(e.url, '/select?wt=json&fq=field%3Afilter')
            self.assertEqual(e.body, None)
            self.assertEqual(e.response, ZMQ_ERROR_RESPONSE)
            return

        self.assertFalse(True, 'Error should have been raised')
Beispiel #5
0
    def test_execution_invalid_response_data(self, pool):
        """
        Test the execution of a command where Solr returns a non-200 response.
        """
        command = stellr.SelectCommand(TEST_HTTP)
        self.assertEquals(command.pool, pool)
        response = self._create_execution_mocks(pool, 200, valid=False)

        command.add_param('fq', 'field:filter')
        try:
            data = command.execute()
        except stellr.StellrError as e:
            self.assertFalse(e.timeout)
            self.assertEqual(e.status, -1)
            self.assertEqual(
                e.url, TEST_HTTP + '/solr/select?wt=json&fq=field%3Afilter')
            self.assertEqual(e.body, None)
            self.assertEqual(e.response, INVALID_RESPONSE_DATA)
            return

        self.assertFalse(True, 'Error should have been raised')
Beispiel #6
0
    def test_zmq_execution_timeout(self, pool):
        """
        Test the execution of a select command that is successful.
        """
        socket = self._create_zmq_execution_mocks(pool,
                                                  valid=False,
                                                  response=None)

        command = stellr.SelectCommand(TEST_ZMQ)
        command.add_param('fq', 'field:filter')
        try:
            data = command.execute()
        except stellr.StellrError as e:
            self.assertTrue(e.timeout)
            self.assertEqual(e.status, -1)
            self.assertEqual(e.url, '/select?wt=json&fq=field%3Afilter')
            self.assertEqual(e.body, None)
            self.assertEqual(e.response, None)
            return

        self.assertFalse(True, 'Error should have been raised')