def test_canceled_queue_model(self): """Tests successfully calling perform_scheduling() when a queue model has been canceled""" offer_1 = ResourceOffer('offer_1', self.agent_1.agent_id, self.framework_id, NodeResources([Cpus(2.0), Mem(1024.0), Disk(1024.0)]), now(), None) offer_2 = ResourceOffer('offer_2', self.agent_2.agent_id, self.framework_id, NodeResources([Cpus(25.0), Mem(2048.0), Disk(2048.0)]), now(), None) resource_mgr.add_new_offers([offer_1, offer_2]) self.queue_1.is_canceled = True self.queue_1.save() scheduling_manager = SchedulingManager() num_tasks = scheduling_manager.perform_scheduling(self._client, now()) self.assertEqual(num_tasks, 1) # Scheduled non-canceled queued job execution # queue_1 should be canceled, queue_2 should be running, queue should be empty now self.assertEqual(JobExecution.objects.filter(job_id=self.queue_1.job_id).count(), 1) self.assertEqual(JobExecution.objects.filter(job_id=self.queue_2.job_id).count(), 1) self.assertEqual(Queue.objects.filter(id__in=[self.queue_1.id, self.queue_2.id]).count(), 0) # Job execution manager should have a message for the canceled job execution messages = job_exe_mgr.get_messages() found_job_exe_end_message = False for message in messages: if message.type == 'create_job_exe_ends': found_job_exe_end_message = True self.assertTrue(found_job_exe_end_message)
def _execute(self): """See :meth:`scheduler.threads.base_thread.BaseSchedulerThread._execute` """ # If there are no previous messages to send, see if there are any new messages if not self._messages: self._messages = job_exe_mgr.get_messages() count = len(self._messages) if count: logger.info('Sending %d message(s)', count) self._manager.send_messages(self._messages) self._messages = []