示例#1
0
 def test_set_track_hostname(self):
     """Test Database.set_track_hostname()"""
     db = MemoryDatabase(Job)
     numfields = len(db._fields)
     db.set_track_hostname()
     self.assertEqual(len(db._fields), numfields + 1)
     self.assertEqual(db._fields[-1].name, 'hostname')
示例#2
0
 def test_add_field(self):
     """Check Database.add_field()"""
     db = MemoryDatabase(Job)
     numfields = len(db._fields)
     db.add_field(MySQLField('test_field', 'TEXT'))
     self.assertEqual(len(db._fields), numfields + 1)
     self.assertEqual(db._fields[-1].name, 'test_field')
示例#3
0
 def test_create_tables(self):
     """Make sure that Database._create_tables() makes tables and indexes"""
     db = MemoryDatabase(Job)
     db._connect(None)
     db._create_tables()
     c = db.conn.cursor()
     c.execute('DROP INDEX state_index')
     for bad_index in ('GARBAGE', 'state', 'name_index'):
         self.assertRaises(sqlite3.OperationalError, c.execute,
                           'DROP INDEX ' + bad_index)
     c.execute('DROP TABLE jobs')
     self.assertRaises(sqlite3.OperationalError, c.execute,
                       'DROP TABLE GARBAGE')
     db.conn.commit()
示例#4
0
 def test_drop_tables(self):
     """Check Database._drop_tables()"""
     db = MemoryDatabase(Job)
     db._connect(None)
     c = db.conn.cursor()
     c.execute('CREATE TABLE jobs (test TEXT)')
     db.conn.commit()
     # Should work regardless of whether tables exist
     db._drop_tables()
     # It should have deleted the jobs table and state index
     self.assertRaises(sqlite3.OperationalError, c.execute,
                       'DROP TABLE jobs')
     self.assertRaises(sqlite3.OperationalError, c.execute,
                       'DROP INDEX state_index')
示例#5
0
 def test_change_job_state(self):
     """Check Database._change_job_state()"""
     db = MemoryDatabase(Job)
     db._connect(None)
     db._create_tables()
     make_test_jobs(db.conn)
     job = list(db._get_all_jobs_in_state('INCOMING'))[0]
     # side effect: should update _metadata
     job._metadata['runner_id'] = 'new-SGE-ID'
     db._change_job_state(job._metadata, 'INCOMING', 'FAILED')
     jobs = list(db._get_all_jobs_in_state('INCOMING'))
     self.assertEqual(len(jobs), 0)
     jobs = list(db._get_all_jobs_in_state('FAILED'))
     self.assertEqual(len(jobs), 1)
     self.assertEqual(jobs[0]._metadata['runner_id'], 'new-SGE-ID')
示例#6
0
def setup_webservice(archive='30d', expire='90d'):
    tmpdir = tempfile.mkdtemp()
    incoming = os.path.join(tmpdir, 'incoming')
    preprocessing = os.path.join(tmpdir, 'preprocessing')
    failed = os.path.join(tmpdir, 'failed')
    os.mkdir(incoming)
    os.mkdir(preprocessing)
    os.mkdir(failed)
    db = MemoryDatabase(MyJob)
    db.add_field(MySQLField('testfield', 'TEXT'))
    conf = Config(StringIO(basic_config \
                           % (incoming, preprocessing, failed, archive,
                              expire)))
    web = WebService(conf, db)
    db._create_tables()
    return db, conf, web, tmpdir
示例#7
0
 def _setup_webservice(self, directory='/'):
     db = MemoryDatabase(LoggingJob)
     conf = Config(StringIO(basic_config % {'directory': directory}))
     web = WebService(conf, db)
     web.create_database_tables()
     make_test_jobs(db.conn)
     return db, conf, web
示例#8
0
 def test_update_job(self):
     """Check Database._update_job()"""
     db = MemoryDatabase(Job)
     db._connect(None)
     db._create_tables()
     make_test_jobs(db.conn)
     job = list(db._get_all_jobs_in_state('INCOMING'))[0]
     job._metadata['runner_id'] = 'new-SGE-ID'
     db._update_job(job._metadata, 'INCOMING')
     # Get a fresh copy of the job from the database
     newjob = list(db._get_all_jobs_in_state('INCOMING'))[0]
     self.assert_(job is not newjob)
     self.assertEqual(newjob._metadata['runner_id'], 'new-SGE-ID')
示例#9
0
 def test_init(self):
     """Check WebService init"""
     db = MemoryDatabase(Job)
     conf = Config(StringIO(basic_config % {'directory': '/'}))
     ws = WebService(conf, db)
     self.assertEqual(ws.version, None)
     # OK to make multiple WebService instances
     ws2 = WebService(conf, db)
示例#10
0
 def test_count_jobs(self):
     """Check Database._count_all_jobs_in_state()"""
     db = MemoryDatabase(Job)
     db._connect(None)
     db._create_tables()
     make_test_jobs(db.conn)
     self.assertEqual(db._count_all_jobs_in_state('INCOMING'), 1)
     self.assertEqual(db._count_all_jobs_in_state('RUNNING'), 2)
     self.assertEqual(db._count_all_jobs_in_state('EXPIRED'), 0)
示例#11
0
    def test_order_by(self):
        """Test Database._get_all_jobs_in_state() order_by parameter"""
        db = MemoryDatabase(Job)
        db._connect(None)
        db._create_tables()
        make_test_jobs(db.conn)
        jobs = list(db._get_all_jobs_in_state('RUNNING'))
        # Jobs should come out in the same order they were inserted
        self.assertEqual([x._metadata['name'] for x in jobs], ['job2', 'job3'])

        jobs = list(db._get_all_jobs_in_state('RUNNING',
                                              order_by='submit_time'))
        # Jobs should be sorted by submit time
        self.assertEqual([x._metadata['name'] for x in jobs], ['job3', 'job2'])
示例#12
0
 def test_get_jobs(self):
     """Check Database._get_all_jobs_in_state()"""
     db = MemoryDatabase(Job)
     db._connect(None)
     db._create_tables()
     make_test_jobs(db.conn)
     jobs = list(db._get_all_jobs_in_state('INCOMING'))
     self.assertEqual(len(jobs), 1)
     self.assertEqual(jobs[0]._metadata['name'], 'job1')
     self.assertEqual(jobs[0]._metadata['runner_id'], 'SGE-job-1')
     jobs = list(db._get_all_jobs_in_state('RUNNING'))
     self.assertEqual(len(jobs), 2)
     jobs = list(db._get_all_jobs_in_state('INCOMING', name='job1'))
     self.assertEqual(len(jobs), 1)
     jobs = list(db._get_all_jobs_in_state('INCOMING', name='job2'))
     self.assertEqual(len(jobs), 0)
     jobs = list(db._get_all_jobs_in_state('INCOMING',
                                           after_time='expire_time'))
     self.assertEqual(len(jobs), 0)
     jobs = list(db._get_all_jobs_in_state('RUNNING',
                                           after_time='expire_time'))
     self.assertEqual(len(jobs), 1)
     self.assertEqual(jobs[0]._metadata['name'], 'job3')
     jobs = list(db._get_all_jobs_in_state('COMPLETED',
                                           after_time='expire_time'))
     self.assertEqual(len(jobs), 0)