本文整理汇总了Python中mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol._add_scheduler方法的典型用法代码示例。如果您正苦于以下问题:Python CommandResponseInstrumentProtocol._add_scheduler方法的具体用法?Python CommandResponseInstrumentProtocol._add_scheduler怎么用?Python CommandResponseInstrumentProtocol._add_scheduler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol
的用法示例。
在下文中一共展示了CommandResponseInstrumentProtocol._add_scheduler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnitInstrumentProtocol
# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _add_scheduler [as 别名]
#.........这里部分代码省略.........
Jobs are just queued for adding unit we call initialize_scheduler
then the jobs are actually created.
use an interval job to allow for testing for removal
"""
job_name = 'test_job'
startup_config = {
DriverConfigKey.SCHEDULER: {
job_name: {
DriverSchedulerConfigKey.TRIGGER: {
DriverSchedulerConfigKey.TRIGGER_TYPE: TriggerType.INTERVAL,
DriverSchedulerConfigKey.SECONDS: 2
},
}
}
}
self.protocol.set_init_params(startup_config)
# Verify we are initialized properly
self.assertIsNone(self.protocol._scheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Verify the the scheduler is created
self.protocol.initialize_scheduler()
self.assertIsInstance(self.protocol._scheduler, DriverScheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Now lets see some magic happen. Lets add our schedulers. Generally
# This would be done as part of the protocol init, but it can happen
# anytime. If the scheduler has already been initialized the
# job will be started right away
self.protocol._add_scheduler(job_name, self._scheduler_callback)
self.assertEqual(0, self._trigger_count)
self.assert_scheduled_event_triggered(event_count=3)
# now remove the job and see that no events are triggered
self.protocol._remove_scheduler(job_name)
self._trigger_count = 0
time.sleep(4)
self.assertEqual(self._trigger_count, 0)
# now check that it raises exception if the removal is re-attempted
try:
self.protocol._remove_scheduler(job_name)
except Exception as e:
return
self.fail("a non-existent job was erroneous removed")
def test_scheduler_event(self):
"""
Test if we can add and trigger jobs using events instead of callbacks
We will create two event triggers, foo and bar. They should come in
that order.
"""
self.protocol._protocol_fsm = Mock()
#self.protocol._fsm.on_event = Mock()
dt = datetime.datetime.now() + datetime.timedelta(0,1)
foo_scheduler = 'foo'
bar_scheduler = 'bar'
startup_config = {
DriverConfigKey.SCHEDULER: {
foo_scheduler: {
DriverSchedulerConfigKey.TRIGGER: {
示例2: TestUnitInstrumentProtocol
# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _add_scheduler [as 别名]
#.........这里部分代码省略.........
def test_apply_startup_params(self):
"""
Test that the apply startup parameters method exists and throws
a "not implemented" exception for the base class
"""
self.assertRaises(NotImplementedException,
self.protocol.apply_startup_params)
def test_scheduler(self):
"""
Test to see that the scheduler can add and remove jobs properly
Jobs are just queued for adding unit we call initialize_scheduler
then the jobs are actually created.
"""
dt = datetime.datetime.now() + datetime.timedelta(0,1)
job_name = 'test_job'
startup_config = {
DriverConfigKey.SCHEDULER: {
job_name: {
DriverSchedulerConfigKey.TRIGGER: {
DriverSchedulerConfigKey.TRIGGER_TYPE: TriggerType.ABSOLUTE,
DriverSchedulerConfigKey.DATE: dt
}
}
}
}
self.protocol.set_init_params(startup_config)
# Verify we are initialized properly
self.assertIsNone(self.protocol._scheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Verify the the scheduler is created
self.protocol.initialize_scheduler()
self.assertIsInstance(self.protocol._scheduler, DriverScheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Now lets see some magic happen. Lets add our schedulers. Generally
# This would be done as part of the protocol init, but it can happen
# anytime. If the scheduler has already been initialized the
# job will be started right away
self.protocol._add_scheduler(job_name, self._scheduler_callback)
self.assertEqual(0, self._trigger_count)
self.assert_scheduled_event_triggered()
def test_scheduler_event(self):
"""
Test if we can add and trigger jobs using events instead of callbacks
We will create two event triggers, foo and bar. They should come in
that order.
"""
self.protocol._protocol_fsm = Mock()
#self.protocol._fsm.on_event = Mock()
dt = datetime.datetime.now() + datetime.timedelta(0,1)
foo_scheduler = 'foo'
bar_scheduler = 'bar'
startup_config = {
DriverConfigKey.SCHEDULER: {
foo_scheduler: {
DriverSchedulerConfigKey.TRIGGER: {
DriverSchedulerConfigKey.TRIGGER_TYPE: TriggerType.INTERVAL,
DriverSchedulerConfigKey.SECONDS: 1
}
},
bar_scheduler: {
DriverSchedulerConfigKey.TRIGGER: {
DriverSchedulerConfigKey.TRIGGER_TYPE: TriggerType.INTERVAL,
DriverSchedulerConfigKey.SECONDS: 2
}
}
}
}
self.protocol.set_init_params(startup_config)
# Verify we are initialized properly
self.assertIsNone(self.protocol._scheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Verify the the scheduler is created
self.protocol.initialize_scheduler()
self.assertIsInstance(self.protocol._scheduler, DriverScheduler)
self.assertEqual(self.protocol._scheduler_config, {})
self.assertEqual(self.protocol._scheduler_callback, {})
# Now lets see some magic happen. Lets add our schedulers. Generally
# This would be done as part of the protocol init, but it can happen
# anytime. If the scheduler has already been initialized the
# job will be started right away
foo_event='foo'
bar_event='bar'
self.protocol._add_scheduler_event(foo_scheduler, foo_event)
self.protocol._add_scheduler_event(bar_scheduler, bar_event)
self.assertEqual(0, self._trigger_count)