def test_server_queues(self): handler = self.PriorityHandler() processor = PriorityService.Processor(handler) # Make sure there are 0 threads for best_effort and 1 queue slot # (the queue size cannot be set to 0) cppserver = TCppServerTestManager.make_server(processor) cppserver.setNewPriorityThreadManager(best_effort=0, normal=1, important=1, high=0, high_important=0, enableTaskStats=False, maxQueueLen=1) # Since we'll have a Cpp2Worker stuck, don't wait for it to exit cppserver.setWorkersJoinTimeout(0) with TCppServerTestManager(cppserver) as server: # Send a request to the server and return immediately try: self._expiring_rpc(server, PriorityService, 'bestEffort', 0) except TTransportException: pass # The queue for bestEffort should be full, as the first request # will never get processed (best_effort=0) with self.assertRaises(TApplicationException): self._perform_rpc(server, PriorityService, 'bestEffort') # However the normal prio one should go through self.assertTrue( self._perform_rpc(server, PriorityService, 'normal')) cppserver.getThreadManager().clearPending()
def test_processor_priorities(self): handler = self.PriorityHandler() processor = PriorityService.Processor(handler) # Did we parse annotations correctly self.assertEquals(processor.get_priority("bestEffort"), TPriority.BEST_EFFORT) self.assertEquals(processor.get_priority("normal"), TPriority.NORMAL) self.assertEquals(processor.get_priority("important"), TPriority.IMPORTANT) self.assertEquals(processor.get_priority("unspecified"), TPriority.HIGH)