コード例 #1
0
ファイル: test_builtin.py プロジェクト: darinlively/gofer
 def test_dispatch(self, dispatcher):
     request = 'test'
     dispatcher.__iadd__ = Mock()
     plugin = Mock()
     builtin = Builtin(plugin)
     result = builtin.dispatch(request)
     builtin.dispatcher.dispatch.assert_called_once_with(request)
     self.assertEqual(result, builtin.dispatcher.dispatch.return_value)
コード例 #2
0
 def test_dispatch(self, dispatcher):
     request = 'test'
     dispatcher.__iadd__ = Mock()
     plugin = Mock()
     builtin = Builtin(plugin)
     result = builtin.dispatch(request)
     builtin.dispatcher.dispatch.assert_called_once_with(request)
     self.assertEqual(result, builtin.dispatcher.dispatch.return_value)
コード例 #3
0
 def test_provides(self, dispatcher):
     name = 'test'
     dispatcher.__iadd__ = Mock()
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     builtin.dispatcher.provides.assert_called_once_with(name)
     self.assertEqual(p, builtin.dispatcher.provides.return_value)
コード例 #4
0
ファイル: test_builtin.py プロジェクト: darinlively/gofer
 def test_provides(self, dispatcher):
     name = 'test'
     dispatcher.__iadd__ = Mock()
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     builtin.dispatcher.provides.assert_called_once_with(name)
     self.assertEqual(p, builtin.dispatcher.provides.return_value)
コード例 #5
0
 def __init__(self, plugin):
     """
     :param plugin: A plugin.
     :type plugin: gofer.agent.plugin.Plugin
     """
     Thread.__init__(self, name='scheduler:%s' % plugin.name)
     self.plugin = plugin
     self.pending = Pending(plugin.name)
     self.builtin = Builtin(plugin)
     self.setDaemon(True)
コード例 #6
0
ファイル: test_builtin.py プロジェクト: swipswaps/gofer
 def test_dispatch(self):
     request = Document(routing=['A', 'B'],
                        request={
                            'classname': 'Admin',
                            'method': 'hello',
                            'args': [],
                            'keywords': {}
                        })
     plugin = Mock()
     builtin = Builtin(plugin)
     result = builtin.dispatch(request)
     self.assertEqual(result.retval, Admin().hello())
コード例 #7
0
ファイル: test_builtin.py プロジェクト: jortel/gofer
 def test_dispatch(self):
     request = Document(
         routing=['A', 'B'],
         request={
             'classname': 'Admin',
             'method': 'hello',
             'args': [],
             'keywords': {}
         })
     plugin = Mock()
     builtin = Builtin(plugin)
     result = builtin.dispatch(request)
     self.assertEqual(result.retval, Admin().hello())
コード例 #8
0
ファイル: test_builtin.py プロジェクト: swipswaps/gofer
 def test_properties(self):
     plugin = Mock(container=Mock(),
                   authenticator=Mock(),
                   url='http://1234')
     builtin = Builtin(plugin)
     self.assertEqual(builtin.url, builtin.url)
     self.assertEqual(builtin.authenticator, builtin.authenticator)
コード例 #9
0
 def test_properties(self, dispatcher):
     dispatcher.__iadd__ = Mock()
     plugin = Mock(container=Mock(),
                   authenticator=Mock(),
                   url='http://1234')
     builtin = Builtin(plugin)
     self.assertEqual(builtin.url, builtin.url)
     self.assertEqual(builtin.authenticator, builtin.authenticator)
コード例 #10
0
ファイル: test_builtin.py プロジェクト: swipswaps/gofer
 def test_init(self, pool, dispatcher):
     dispatcher.__iadd__ = Mock()
     plugin = Mock(container=Mock())
     builtin = Builtin(plugin)
     pool.assert_called_once_with(3)
     self.assertEqual(builtin.dispatcher, builtin._dispatcher.return_value)
     self.assertEqual(builtin.pool, pool.return_value)
     self.assertEqual(builtin.plugin, plugin)
コード例 #11
0
ファイル: rmi.py プロジェクト: roshan/gofer
 def __init__(self, plugin):
     """
     :param plugin: A plugin.
     :type plugin: gofer.agent.plugin.Plugin
     """
     Thread.__init__(self, name="scheduler:%s" % plugin.name)
     self.plugin = plugin
     self.pending = Pending(plugin.name)
     self.builtin = Builtin(plugin)
     self.setDaemon(True)
コード例 #12
0
ファイル: test_builtin.py プロジェクト: jortel/gofer
 def test_provides(self):
     name = 'Admin'
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     self.assertTrue(p)
コード例 #13
0
ファイル: test_builtin.py プロジェクト: swipswaps/gofer
 def test_provides(self):
     name = 'Admin'
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     self.assertTrue(p)
コード例 #14
0
ファイル: rmi.py プロジェクト: roshan/gofer
class Scheduler(Thread):
    """
    The pending request scheduler.
    Processes the *pending* queue.
    """

    def __init__(self, plugin):
        """
        :param plugin: A plugin.
        :type plugin: gofer.agent.plugin.Plugin
        """
        Thread.__init__(self, name="scheduler:%s" % plugin.name)
        self.plugin = plugin
        self.pending = Pending(plugin.name)
        self.builtin = Builtin(plugin)
        self.setDaemon(True)

    def run(self):
        """
        Read the pending queue and dispatch requests
        to the plugin thread pool.
        """
        while not Thread.aborted():
            try:
                request = self.pending.get()
            except Empty:
                # aborted
                break
            try:
                plugin = self.select_plugin(request)
                transaction = Transaction(plugin, self.pending, request)
                task = Task(transaction)
                plugin.pool.run(task)
            except Exception:
                self.pending.commit(request.sn)
                log.exception(request.sn)

    def select_plugin(self, request):
        """
        Select the plugin based on the request.
        :param request: A request to be scheduled.
        :rtype request: gofer.messaging.Document
        :return: The appropriate plugin.
        :rtype: gofer.agent.plugin.Plugin
        """
        call = Document(request.request)
        if self.builtin.provides(call.classname):
            plugin = self.builtin
        else:
            plugin = self.plugin
        return plugin

    def add(self, request):
        """
        Add a request to be scheduled.
        :param request: A request to be scheduled.
        :rtype request: gofer.messaging.Document
        """
        self.pending.put(request)

    def shutdown(self):
        """
        Shutdown the scheduler.
        """
        self.builtin.shutdown()
        self.abort()
コード例 #15
0
 def test_shutdown(self, pool):
     plugin = Mock(container=Mock())
     builtin = Builtin(plugin)
     builtin.shutdown()
     pool.return_value.shutdown.assert_called_once_with()
コード例 #16
0
class Scheduler(Thread):
    """
    The pending request scheduler.
    Processes the *pending* queue.
    """
    def __init__(self, plugin):
        """
        :param plugin: A plugin.
        :type plugin: gofer.agent.plugin.Plugin
        """
        Thread.__init__(self, name='scheduler:%s' % plugin.name)
        self.plugin = plugin
        self.pending = Pending(plugin.name)
        self.builtin = Builtin(plugin)
        self.setDaemon(True)

    def run(self):
        """
        Read the pending queue and dispatch requests
        to the plugin thread pool.
        """
        self.builtin.start()
        while not Thread.aborted():
            try:
                request = self.pending.get()
            except Empty:
                # aborted
                break
            try:
                plugin = self.select_plugin(request)
                transaction = Transaction(plugin, self.pending, request)
                task = Task(transaction)
                plugin.pool.run(task)
            except Exception:
                self.pending.commit(request.sn)
                log.exception(request.sn)

    def select_plugin(self, request):
        """
        Select the plugin based on the request.
        :param request: A request to be scheduled.
        :rtype request: gofer.messaging.Document
        :return: The appropriate plugin.
        :rtype: gofer.agent.plugin.Plugin
        """
        call = Document(request.request)
        if self.builtin.provides(call.classname):
            plugin = self.builtin
        else:
            plugin = self.plugin
        return plugin

    def add(self, request):
        """
        Add a request to be scheduled.
        :param request: A request to be scheduled.
        :rtype request: gofer.messaging.Document
        """
        self.pending.put(request)

    def shutdown(self):
        """
        Shutdown the scheduler.
        """
        self.builtin.shutdown()
        self.abort()
コード例 #17
0
ファイル: test_builtin.py プロジェクト: jortel/gofer
 def test__dispatcher(self):
     dispatcher = Builtin._dispatcher()
     self.assertTrue(Admin.__name__ in dispatcher.catalog)
コード例 #18
0
ファイル: test_builtin.py プロジェクト: darinlively/gofer
 def test_shutdown(self, pool):
     plugin = Mock(container=Mock())
     builtin = Builtin(plugin)
     builtin.shutdown()
     pool.return_value.shutdown.assert_called_once_with()
コード例 #19
0
ファイル: test_builtin.py プロジェクト: swipswaps/gofer
 def test__dispatcher(self):
     dispatcher = Builtin._dispatcher()
     self.assertTrue(Admin.__name__ in dispatcher.catalog)