Ejemplo n.º 1
0
    def test_exchange(self):
        """
        The L{BrokerClient.exchange} method calls C{exchange} on all
        plugins, if available.
        """
        plugin = BrokerClientPlugin()
        plugin.exchange = mock.Mock()

        self.client.add(plugin)
        self.client.exchange()
        plugin.exchange.assert_called_once_with()
Ejemplo n.º 2
0
    def test_exchange_logs_errors_and_continues(self):
        """
        If the L{exchange} method of a registered plugin fails, the error is
        logged and other plugins are processed.
        """
        self.log_helper.ignore_errors(ZeroDivisionError)
        plugin1 = BrokerClientPlugin()
        plugin2 = BrokerClientPlugin()

        plugin1.exchange = mock.Mock(side_effect=ZeroDivisionError)
        plugin2.exchange = mock.Mock()

        self.client.add(plugin1)
        self.client.add(plugin2)
        self.client.exchange()
        self.assertTrue("Error during plugin exchange" in
                        self.logfile.getvalue())
        self.assertTrue("ZeroDivisionError" in self.logfile.getvalue())
        plugin1.exchange.assert_called_once_with()
        plugin2.exchange.assert_called_once_with()
Ejemplo n.º 3
0
 def test_notify_exchange(self):
     """
     The L{BrokerClient.notify_exchange} method is triggered by an
     impending-exchange event and calls C{exchange} on all plugins,
     logging the event.
     """
     plugin = BrokerClientPlugin()
     plugin.exchange = mock.Mock()
     self.client.add(plugin)
     self.client_reactor.fire("impending-exchange")
     self.assertTrue("Got notification of impending exchange. "
                     "Notifying all plugins." in self.logfile.getvalue())
     plugin.exchange.assert_called_once_with()
Ejemplo n.º 4
0
    def test_flush_after_exchange(self):
        """
        The L{Monitor.exchange} method flushes the monitor after
        C{exchange} on all plugins has been called.
        """
        plugin = BrokerClientPlugin()
        plugin.exchange = lambda: self.monitor.persist.set("a", 1)
        self.monitor.add(plugin)
        self.monitor.exchange()

        persist = Persist()
        persist.load(self.monitor.persist_filename)
        self.assertEqual(persist.get("a"), 1)