示例#1
0
文件: api.py 项目: pratikmallya/otter
def setup_converger(parent, kz_client, dispatcher, interval, build_timeout):
    """
    Create a Converger service, which has a Partitioner as a child service, so
    that if the Converger is stopped, the partitioner is also stopped.
    """
    partitioner_factory = partial(
        Partitioner,
        kz_client=kz_client,
        interval=interval,
        partitioner_path=CONVERGENCE_PARTITIONER_PATH,
        time_boundary=15,  # time boundary
    )
    cvg = Converger(log, dispatcher, 10, partitioner_factory, build_timeout,
                    interval / 2)
    cvg.setServiceParent(parent)
    watch_children(kz_client, CONVERGENCE_DIRTY_DIR, cvg.divergent_changed)
示例#2
0
def setup_converger(parent, kz_client, dispatcher, interval, build_timeout,
                    limited_retry_iterations, step_limits):
    """
    Create a Converger service, which has a Partitioner as a child service, so
    that if the Converger is stopped, the partitioner is also stopped.
    """
    partitioner_factory = partial(
        Partitioner,
        kz_client=kz_client,
        interval=interval,
        partitioner_path=CONVERGENCE_PARTITIONER_PATH,
        time_boundary=15,  # time boundary
    )
    cvg = Converger(log, dispatcher, 10, partitioner_factory, build_timeout,
                    interval / 2, limited_retry_iterations, step_limits)
    cvg.setServiceParent(parent)
    watch_children(kz_client, CONVERGENCE_DIRTY_DIR, cvg.divergent_changed)
示例#3
0
 def test_error(self):
     """
     If the call to :obj:`ChildrenWatch` raises an exception, the returned
     Deferred will fail with that exception.
     """
     def FCW(*args, **kwargs):
         raise RuntimeError('foo')
     result = watch_children(self.tx_client, '/foo', None,
                             ChildrenWatch=FCW)
     f = self.failureResultOf(result)
     self.assertEqual(f.type, RuntimeError)
     self.assertEqual(str(f.value), 'foo')
示例#4
0
 def test_kwargs(self):
     """
     ``allow_session_lost`` and ``send_event`` are passed through to the
     ChildrenWatch.
     """
     result = watch_children(self.tx_client, '/foo', None,
                             allow_session_lost=False,
                             send_event=True,
                             ChildrenWatch=FakeChildrenWatch)
     result = self.successResultOf(result)
     self.assertEqual(result[0], self.tx_client.kazoo_client)
     self.assertEqual(result[1], '/foo')
     self.assertEqual(result[3], False)
     self.assertEqual(result[4], True)
示例#5
0
    def test_error(self):
        """
        If the call to :obj:`ChildrenWatch` raises an exception, the returned
        Deferred will fail with that exception.
        """
        def FCW(*args, **kwargs):
            raise RuntimeError('foo')

        result = watch_children(self.tx_client,
                                '/foo',
                                None,
                                ChildrenWatch=FCW)
        f = self.failureResultOf(result)
        self.assertEqual(f.type, RuntimeError)
        self.assertEqual(str(f.value), 'foo')
示例#6
0
 def test_kwargs(self):
     """
     ``allow_session_lost`` and ``send_event`` are passed through to the
     ChildrenWatch.
     """
     result = watch_children(self.tx_client,
                             '/foo',
                             None,
                             allow_session_lost=False,
                             send_event=True,
                             ChildrenWatch=FakeChildrenWatch)
     result = self.successResultOf(result)
     self.assertEqual(result[0], self.tx_client.kazoo_client)
     self.assertEqual(result[1], '/foo')
     self.assertEqual(result[3], False)
     self.assertEqual(result[4], True)
示例#7
0
    def test_basic_watch(self):
        """
        Parameters are passed to :obj:`ChildrenWatch`, and the callback
        function is wrapped such that it is run in the reactor thread and its
        result is returned to the ChildrenWatch. This is important since
        ChildrenWatch interprets the result to determine whether to continue
        triggering callbacks.
        """
        result = watch_children(self.tx_client, '/foo', self._my_callback,
                                ChildrenWatch=FakeChildrenWatch)
        result = self.successResultOf(result)
        self.assertEqual(result[0], self.tx_client.kazoo_client)
        self.assertEqual(result[1], '/foo')
        self.assertEqual(result[3], True)
        self.assertEqual(result[4], False)

        self.assertEqual(
            result[2](['foo', 'bar']),
            ('called back', ['foo', 'bar']))
示例#8
0
    def test_basic_watch(self):
        """
        Parameters are passed to :obj:`ChildrenWatch`, and the callback
        function is wrapped such that it is run in the reactor thread and its
        result is returned to the ChildrenWatch. This is important since
        ChildrenWatch interprets the result to determine whether to continue
        triggering callbacks.
        """
        result = watch_children(self.tx_client,
                                '/foo',
                                self._my_callback,
                                ChildrenWatch=FakeChildrenWatch)
        result = self.successResultOf(result)
        self.assertEqual(result[0], self.tx_client.kazoo_client)
        self.assertEqual(result[1], '/foo')
        self.assertEqual(result[3], True)
        self.assertEqual(result[4], False)

        self.assertEqual(result[2](['foo', 'bar']),
                         ('called back', ['foo', 'bar']))