def test_notification_callback(self): client = molequeue.Client() client.connect_to_server('MoleQueue') self.callback_count = 0 def callback_counter(testcase, msg): testcase.callback_count += 1 callback = partial(callback_counter, self) client.register_notification_callback(callback) client.register_notification_callback(callback) job = molequeue.Job() job.queue = 'salix' job.program = 'sleep (testing)' molequeue_id = client.submit_job(job) # wait for notification time.sleep(1) self.assertIs(self.callback_count, 2) client.disconnect()
def test_lookup_job(self): client = molequeue.Client() client.connect_to_server('MoleQueue') expected_job = molequeue.Job() expected_job.queue = 'salix' expected_job.program = 'sleep (testing)' expected_job.description = 'This is a test job' expected_job.hide_from_gui = True expected_job.popup_on_state_change = False file_contents = molequeue.FileContents() file_contents.filename = 'test.in' file_contents.contents = 'Hello' expected_job.input_file = file_contents molequeue_id = client.submit_job(expected_job) job = client.lookup_job(molequeue_id) self.assertEqual(molequeue_id, job.molequeue_id()) self.assertEqual(job.job_state(), molequeue.JobState.ACCEPTED) self.assertEqual(job.queue_id(), None) self.assertEqual(job.queue, expected_job.queue) self.assertEqual(job.program, expected_job.program) self.assertEqual(job.description, expected_job.description) self.assertEqual(job.hide_from_gui, expected_job.hide_from_gui) self.assertEqual(job.popup_on_state_change, expected_job.popup_on_state_change) client.disconnect()
def run_test(): global socketname, molequeue_ids_done, clientId, mq_id_lock, num_jobs if debug: print "Client %s connecting to socket: %s" % (clientId, socketname) client = mq.Client() client.connect_to_server(socketname) def notification_callback(msg): global molequeue_ids_done, mq_id_lock try: if msg['method'] == 'jobStateChanged': if msg['params']['newState'] == 'Finished': moleQueueId = msg['params']['moleQueueId'] with mq_id_lock: molequeue_ids_done.append(moleQueueId) if debug: print "Job %d finished! (Client %s)" % (moleQueueId, clientId) except Exception as ex: print "Unexpected notification:", msg, ex sys.stdout.flush() client.register_notification_callback(notification_callback) molequeue_ids = [] for i in range(num_jobs): job = mq.Job() job.queue = "TestQueue" job.program = "TestProgram" job.description = "Test job %d from python client %s" % (i + 1, clientId) job.popup_on_state_change = False molequeue_id = client.submit_job(job, 30) molequeue_ids.append(molequeue_id) if molequeue_id == None: # Timeout client.disconnect() raise Exception("Connection timed out!") if debug: print "Submitted job %d (Client %s)" % (molequeue_id, clientId) sys.stdout.flush() timeout = 30 mq_id_lock.acquire() while len(molequeue_ids) != len(molequeue_ids_done) and timeout > 0: if debug: print "Client %s waiting to finish (timeout=%d unmatchedIDs=%d)"%\ (clientId, timeout, len(molequeue_ids) - len(molequeue_ids_done)) sys.stdout.flush() timeout -= 1 mq_id_lock.release() time.sleep(1) mq_id_lock.acquire() mq_id_lock.release() client.disconnect() if timeout > 0: return 0 return 1
def json_to_job(json): job = molequeue.Job() # convert response into Job object for key, value in json['result'].iteritems(): field = camelcase_to_underscore(key) if key in JsonRpc.INTERNAL_FIELDS: field = '_' + field job.__dict__[field] = value return job
def test_submit_job(self): client = molequeue.Client() client.connect_to_server('MoleQueue') job = molequeue.Job() job.queue = 'salix' job.program = 'sleep (testing)' file_path = molequeue.FilePath() file_path.path = "/tmp/test" job.input_file = file_path molequeue_id = client.submit_job(job) print "MoleQueue ID: ", molequeue_id self.assertTrue(isinstance(molequeue_id, int)) client.disconnect()