Example #1
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)
Example #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)
Example #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)
Example #4
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)
Example #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)
Example #6
0
 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())
Example #7
0
 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())
Example #8
0
 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)
Example #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)
Example #10
0
 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)
Example #11
0
File: rmi.py Project: 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)
Example #12
0
 def test_provides(self):
     name = 'Admin'
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     self.assertTrue(p)
Example #13
0
 def test_provides(self):
     name = 'Admin'
     plugin = Mock()
     builtin = Builtin(plugin)
     p = builtin.provides(name)
     self.assertTrue(p)
Example #14
0
File: rmi.py Project: 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()
Example #15
0
 def test_shutdown(self, pool):
     plugin = Mock(container=Mock())
     builtin = Builtin(plugin)
     builtin.shutdown()
     pool.return_value.shutdown.assert_called_once_with()
Example #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()
Example #17
0
 def test__dispatcher(self):
     dispatcher = Builtin._dispatcher()
     self.assertTrue(Admin.__name__ in dispatcher.catalog)
Example #18
0
 def test_shutdown(self, pool):
     plugin = Mock(container=Mock())
     builtin = Builtin(plugin)
     builtin.shutdown()
     pool.return_value.shutdown.assert_called_once_with()
Example #19
0
 def test__dispatcher(self):
     dispatcher = Builtin._dispatcher()
     self.assertTrue(Admin.__name__ in dispatcher.catalog)