示例#1
0
    def test_add_new(self):
        """Add a new plugin to the scheduler."""
        CONF.set_override('enable', True, 'scheduler')

        self.assertIsNone(scheduler.SCHEDULER)
        scheduler.initialize_scheduler()

        mock_plugin = MockPlugin(dict())
        mock_plugin_name = mock_plugin.get_name()
        mock_extensions = [
            Extension(mock_plugin_name, None, None, mock_plugin)
        ]
        loader = StoryboardPluginLoader.make_test_instance(
            mock_extensions, namespace='storyboard.plugin.testing'
        )
        test_list = list()
        loader.map(scheduler.add_plugins, test_list)

        self.assertTrue(test_list.index(mock_plugin_name) == 0)

        self.assertIsNotNone(scheduler.SCHEDULER.get_job(mock_plugin_name))

        scheduler.shutdown_scheduler()
        self.assertIsNone(scheduler.SCHEDULER)
        CONF.clear_override('enable', 'scheduler')
示例#2
0
    def test_enabled_initialize(self):
        """Test that the initialize and shutdown methods work when enabled."""
        CONF.set_override('enable', True, 'scheduler')

        self.assertIsNone(scheduler.SCHEDULER)
        scheduler.initialize_scheduler()
        self.assertIsNotNone(scheduler.SCHEDULER)
        scheduler.shutdown_scheduler()
        self.assertIsNone(scheduler.SCHEDULER)

        CONF.clear_override('enable', 'scheduler')
示例#3
0
    def test_add_plugins_reschedule(self):
        """Assert that the test_add_plugins will reschedule existing plugins.
        """
        CONF.set_override('enable', True, 'scheduler')

        self.assertIsNone(scheduler.SCHEDULER)
        scheduler.initialize_scheduler()

        mock_plugin = MockPlugin(dict())
        mock_plugin_name = mock_plugin.get_name()
        mock_extensions = [
            Extension(mock_plugin_name, None, None, mock_plugin)
        ]
        loader = StoryboardPluginLoader.make_test_instance(
            mock_extensions, namespace='storyboard.plugin.testing'
        )
        test_list = list()
        loader.map(scheduler.add_plugins, test_list)

        self.assertTrue(test_list.index(mock_plugin_name) == 0)
        first_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name)
        first_run_trigger = first_run_job.trigger
        self.assertEqual(mock_plugin._trigger.run_date,
                         first_run_trigger.run_date)

        # Update the plugin's interval and re-run
        new_date = datetime.datetime.now() + datetime.timedelta(days=2)
        mock_plugin._trigger = DateTrigger(run_date=new_date)
        test_list = list()
        loader.map(scheduler.add_plugins, test_list)

        # make sure the plugin is only loaded once.
        self.assertTrue(test_list.index(mock_plugin_name) == 0)
        self.assertEquals(len(test_list), 1)

        # Get the job.
        second_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name)
        second_run_trigger = second_run_job.trigger
        self.assertNotEqual(second_run_trigger.run_date,
                            first_run_trigger.run_date)

        scheduler.shutdown_scheduler()
        self.assertIsNone(scheduler.SCHEDULER)
        CONF.clear_override('enable', 'scheduler')
示例#4
0
    def test_intialize_with_manager(self):
        """Assert that the management plugin is loaded, and runs every
        minute.
        """
        CONF.set_override('enable', True, 'scheduler')

        self.assertIsNone(scheduler.SCHEDULER)
        scheduler.initialize_scheduler()
        self.assertIsNotNone(scheduler.SCHEDULER)

        manager_job = scheduler.SCHEDULER \
            .get_job(scheduler.SCHEDULE_MANAGER_ID)

        self.assertIsNotNone(manager_job)
        trigger = manager_job.trigger
        self.assertIsInstance(trigger, IntervalTrigger)
        self.assertEqual(60, trigger.interval_length)
        self.assertEqual(scheduler.SCHEDULE_MANAGER_ID, manager_job.id)

        scheduler.shutdown_scheduler()
        self.assertIsNone(scheduler.SCHEDULER)

        CONF.clear_override('enable', 'scheduler')
示例#5
0
 def _remove_scheduler(self):
     if scheduler.SCHEDULER:
         scheduler.shutdown_scheduler()