当前位置: 首页>>代码示例>>Python>>正文


Python Scheduler.find_slot方法代码示例

本文整理汇总了Python中scheduler.Scheduler.find_slot方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.find_slot方法的具体用法?Python Scheduler.find_slot怎么用?Python Scheduler.find_slot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scheduler.Scheduler的用法示例。


在下文中一共展示了Scheduler.find_slot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TimingTestCase

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import find_slot [as 别名]
class TimingTestCase(unittest.TestCase):
    sch = None

    def __init__(self, *args, **kwargs):
        super(TimingTestCase, self).__init__(*args, **kwargs)

        if self.sch is None:
            configuration.select('marvinctld',
                                 preset={'inventory': {'sync': False},
                                         'database': TEMP_DB,
                                         'log': {'level': 50,
                                                 'file': TEMP_LOG}})

            from scheduler import Scheduler
            self.sch = Scheduler(refresh=True)
            self.assertIsNotNone(self.sch.db())

            self.assertTrue(os.path.isfile(TEMP_DB))

            userid, error = self.sch.create_user('admin', 'admin', 'admin')
            self.assertIsNotNone(userid)

            c = self.sch.db().cursor()
            nodes = self.sch.get_nodes()
            if nodes is None or len(nodes) < 25:
                print "creating 25 nodes...",
                for nodeid in xrange(1,25):
                    c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                              (nodeid, 'test %i' % nodeid, 'active', 0))
                    self.sch.db().commit()
                    self.sch.set_node_types(nodeid, 'status:test')
                print "done."

    def test_01_lots_of_recurring(self):
        userid = self.sch.get_users()[0]['id']
        now = time.time()
        until = self.sch.get_scheduling_period()[1]
        print
        print "creating 25x2 recurring experiments ..."
        for nodeid in xrange(1,25):
            before = time.time()
            r = self.sch.allocate(userid, 'test', now + 500, 60, 1,
                                  'status:test', '...',
                                  {'recurrence': 'simple',
                                   'period': 3600,
                                   'until': until})
            print r
            self.assertEqual(r[2]['nodecount'], 1)
            self.assertEqual(r[2]['intervals'], 744)
            r = self.sch.allocate(userid, 'test', now + 750, 60, 1, 'status:test', '...',
                                  {'recurrence': 'simple',
                                   'period': 3600,
                                   'until': until})
            self.assertEqual(r[2]['nodecount'], 1)
            self.assertEqual(r[2]['intervals'], 744)
            after = time.time()
            print nodeid * 2, after-before, "seconds."
            self.assertLess(after-before, 10)  # completes in 10 seconds or less
        print "completed in %f seconds." % (after-now)

    def test_02_find_slot(self):
        before = time.time()
        r = self.sch.find_slot(1)
        self.assertEqual(r[0][0]['nodecount'], 1)
        r = self.sch.find_slot(1, nodetypes='status:fail')
        self.assertIsNone(r[0])
        r = self.sch.find_slot(1, duration=500, nodes=['1'],
                               nodetypes='status:test,-status:foo')
        self.assertIsNotNone(r[0])
        self.assertEqual(r[0][0]['nodecount'], 1)
        r = self.sch.find_slot(1, duration=500, nodes=['500', '600'])
        self.assertIsNone(r[0])
        after = time.time()
        print "completed in %f seconds - " % (after-before),
        self.assertLess(after-before, 3)  # completes in 3 seconds or less

    def test_99_cleanup(self):
        os.unlink(TEMP_DB)
开发者ID:MONROE-PROJECT,项目名称:Scheduler,代码行数:80,代码来源:test_timing.py

示例2: SchedulerTestCase

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import find_slot [as 别名]

#.........这里部分代码省略.........
        # too many nodes
        r = self.sch.allocate(1,'test', now + 1500, 500, 2, 'status:test', '...', {})
        self.assertEqual(r[2]['available'], 1)
        # too much storage requested
        r = self.sch.allocate(1,'test', now + 1500, 500, 1, 'status:test', '...',
                              {'storage': 501 * 1000000000})
        self.assertEqual(r[2]['requested'], 501 * 1000000000)

    def test_11_recurrence(self):
        now = int(time.time())
        r = self.sch.allocate(1,'test', now + 1500, 500, 1, 'status:test', '...',
                {'recurrence':'simple',
                 'period': 3600,
                 'until': now + 1500 + 3600 * 2 + 500
                })
        self.assertEqual(r[2]['nodecount'], 1)
        self.assertEqual(r[2]['intervals'], 3)
        # check that the tasks are different, and of equal length
        t = self.sch.get_schedule(expid = 2)
        self.assertGreater(t[1]['start'], t[0]['start'])
        self.assertGreater(t[1]['stop'], t[0]['stop'])
        self.assertGreater(t[0]['stop'], t[0]['start'])
        self.assertGreater(t[1]['stop'], t[1]['start'])
        self.assertEqual(t[0]['stop'] - t[0]['start'],
                         t[1]['stop'] - t[1]['start'],)

        # truncating until
        r = self.sch.allocate(1,'test', now + 1500, 500, 1, 'status:test', '...',
                {'recurrence':'simple',
                 'period': 3600,
                 'until': now + 100000000000
                 })
        self.assertLess(r[2]['stop'], now + 100000000000)

        # interleaving recurrence
        r = self.sch.allocate(1,'test', now + 2500, 500, 1, 'status:test', '...',
                {'recurrence':'simple',
                 'period': 3600,
                 'until': now + 2500 + 3600 * 2 + 500
                })
        self.assertEqual(r[2]['nodecount'], 1)
        self.assertEqual(r[2]['intervals'], 3)

        r = self.sch.allocate(1,'test', now + 3500, 500, 1, 'status:test', '...',
                {'recurrence':'simple',
                 'period': 3600,
                 'until': now + 3500 + 3600 * 2 + 500
                })
        self.assertEqual(r[2]['nodecount'], 1)
        self.assertEqual(r[2]['intervals'], 3)

    def test_12_find_slot(self):
        r = self.sch.find_slot(1)
        self.assertEqual(r[0][0]['nodecount'], 1)
        r = self.sch.find_slot(1, nodetypes='status:fail')
        self.assertIsNone(r[0])
        r = self.sch.find_slot(1, duration=500, nodes=['1'],
                               nodetypes='status:test')
        self.assertIsNotNone(r[0])
        self.assertEqual(r[0][0]['nodecount'], 1)

        # actually allocate the suggested slot
        r = self.sch.allocate(1,'test', r[0][0]['start'], 500, 1, 'status:test', '...', {})
        self.assertEqual(r[2]['nodecount'], 1)

        r = self.sch.find_slot(1, duration=500, nodes=['500','600'])
        self.assertIsNone(r[0])

    def test_13_quotas(self):
        now = int(time.time())
        self.sch.set_time_quota(1, 500)
        self.sch.set_data_quota(1, 500)
        self.sch.set_storage_quota(1, 500)
        r = self.sch.allocate(1,'test', now + 500, 600, 1, 'status:test', '...', {})
        self.assertEqual(r[2]['required'], 600)
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test', '...',
                              {'traffic':200})
        self.assertEqual(r[2]['required'], 600)
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test', '...',
                              {'storage':600})
        self.assertEqual(r[2]['required'], 600)

    def test_14_journal(self):
        r = self.sch.get_quota_journal(userid=1)
        self.assertEqual(len(r), 39)

    def test_15_reports(self):
        r = self.sch.get_schedule(schedid=1)
        self.assertEqual(r[0]['report'], {})

    def test_21_delete_experiment(self):
        r = self.sch.delete_experiment(99)
        self.assertEqual(r[0],0)
        r = self.sch.delete_experiment(1)
        self.assertEqual(r[0],1)


    def test_99_cleanup(self):
        #os.unlink(TEMP_DB)
        os.unlink(TEMP_LOG)
开发者ID:MONROE-PROJECT,项目名称:Scheduler,代码行数:104,代码来源:test_scheduler.py


注:本文中的scheduler.Scheduler.find_slot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。