Пример #1
0
 def testSchemaUrlFallback(self):
     config = queryUtility(ISolrConnectionConfig)
     config.active = True
     config.port = 55555         # random port so the real solr can still run
     def notfound(handler):      # set up fake 404 response
         self.assertEqual(handler.path,
             '/solr/admin/file/?file=schema.xml')
         handler.send_response(404, getData('not_found.txt'))
     def solr12(handler):        # set up response with the schema
         self.assertEqual(handler.path,
             '/solr/admin/get-file.jsp?file=schema.xml')
         handler.send_response(200, getData('schema.xml'))
     responses = [notfound, solr12]
     thread = fakeServer(responses, config.port)
     schema = queryUtility(ISolrConnectionManager).getSchema()
     thread.join()               # the server thread must always be joined
     self.assertEqual(responses, [])
     self.assertEqual(len(schema), 21)   # 21 items defined in schema.xml
    def testSchemaUrlFallback(self):
        config = queryUtility(ISolrConnectionConfig)
        config.active = True
        config.port = 55555  # random port so the real solr can still run

        def notfound(handler):  # set up fake 404 response
            self.assertEqual(handler.path, '/solr/admin/file/?file=schema.xml')
            handler.send_response(404, getData('not_found.txt'))

        def solr12(handler):  # set up response with the schema
            self.assertEqual(handler.path,
                             '/solr/admin/get-file.jsp?file=schema.xml')
            handler.send_response(200, getData('schema.xml'))

        responses = [notfound, solr12]
        thread = fakeServer(responses, config.port)
        schema = queryUtility(ISolrConnectionManager).getSchema()
        thread.join()  # the server thread must always be joined
        self.assertEqual(responses, [])
        self.assertEqual(len(schema), 21)  # 21 items defined in schema.xml
Пример #3
0
 def testSearchTimeout(self):
     config = queryUtility(ISolrConnectionConfig)
     config.active = True
     config.search_timeout = 2   # specify the timeout
     config.port = 55555         # don't let the real solr disturb us
     def quick(handler):         # set up fake http response
         sleep(0.5)              # and wait a bit before sending it
         handler.send_response(200, getData('search_response.txt'))
     def slow(handler):          # set up another http response
         sleep(3)                # but wait longer before sending it
         handler.send_response(200, getData('search_response.txt'))
     # We need a third handler, as the second one will timeout, which causes
     # the SolrConnection.doPost method to catch it and try to reconnect.
     thread = fakeServer([quick, slow, slow], port=55555)
     search = queryUtility(ISearch)
     search('foo')               # the first search should succeed
     try:
         self.assertRaises(timeout, search, 'foo')   # but not the second
     finally:
         thread.join()           # the server thread must always be joined
    def testSearchTimeout(self):
        config = queryUtility(ISolrConnectionConfig)
        config.active = True
        config.search_timeout = 2  # specify the timeout
        config.port = 55555  # don't let the real solr disturb us

        def quick(handler):  # set up fake http response
            sleep(0.5)  # and wait a bit before sending it
            handler.send_response(200, getData('search_response.txt'))

        def slow(handler):  # set up another http response
            sleep(3)  # but wait longer before sending it
            handler.send_response(200, getData('search_response.txt'))

        # We need a third handler, as the second one will timeout, which causes
        # the SolrConnection.doPost method to catch it and try to reconnect.
        thread = fakeServer([quick, slow, slow], port=55555)
        search = queryUtility(ISearch)
        search('foo')  # the first search should succeed
        try:
            self.assertRaises(timeout, search, 'foo')  # but not the second
        finally:
            thread.join()  # the server thread must always be joined