コード例 #1
0
ファイル: test_observers.py プロジェクト: yohummus/yogi
    def test_BindingObserver(self):
        observer = yogi.BindingObserver(self.consumer)

        i = [0]

        def fn1(state):
            if i[0] is 0:
                self.assertIs(yogi.BindingState.RELEASED, state)
            elif i[0] is 1:
                self.assertIs(yogi.BindingState.ESTABLISHED, state)
            elif i[0] is 2:
                self.assertIs(yogi.BindingState.RELEASED, state)
            i[0] += 1

        observer_id = observer.add(fn1)

        j = [0]

        def fn2(state):
            if j[0] is 0:
                self.assertIs(yogi.BindingState.RELEASED, state)
            elif j[0] is 1:
                self.assertIs(yogi.BindingState.ESTABLISHED, state)
            elif j[0] is 2:
                self.assertIs(yogi.BindingState.RELEASED, state)
            elif j[0] is 3:
                self.assertIs(yogi.BindingState.ESTABLISHED, state)
            j[0] += 1

        observer.add(fn2)

        self.assertIs(0, i[0])
        self.assertIs(0, j[0])

        observer.start()
        self.connection = yogi.LocalConnection(self.leafA, self.leafB)
        while self.consumer.get_binding_state() is yogi.BindingState.RELEASED:
            pass
        self.connection.destroy()
        while self.consumer.get_binding_state(
        ) is yogi.BindingState.ESTABLISHED:
            pass

        observer.remove(observer_id)
        self.connection = yogi.LocalConnection(self.leafA, self.leafB)
        while self.consumer.get_binding_state() is yogi.BindingState.RELEASED:
            pass

        observer.stop()
        self.connection.destroy()
        while self.consumer.get_binding_state(
        ) is yogi.BindingState.ESTABLISHED:
            pass

        self.assertIs(3, i[0])
        self.assertIs(4, j[0])
コード例 #2
0
ファイル: test_process.py プロジェクト: yohummus/yogi
    def setUp(self):
        self.pi = yogi.ProcessInterface(yogi.Configuration())
        self.scheduler = yogi.Scheduler()
        self.leaf = yogi.Leaf(self.scheduler)
        self.connection = yogi.LocalConnection(self.pi.leaf, self.leaf)

        self.operational_terminal = yogi.CachedConsumerTerminal(
            '/Process/Operational', yogi_00000001_pb2, leaf=self.leaf)
        self.errors_terminal = yogi.CachedConsumerTerminal('/Process/Errors',
                                                           yogi_0000040d_pb2,
                                                           leaf=self.leaf)
        self.warnings_terminal = yogi.CachedConsumerTerminal(
            '/Process/Warnings', yogi_0000040d_pb2, leaf=self.leaf)

        for tm in [
                self.operational_terminal, self.errors_terminal,
                self.warnings_terminal
        ]:
            while tm.get_binding_state() is yogi.BindingState.RELEASED:
                pass

            while True:
                try:
                    tm.get_cached_message()
                    break
                except yogi.Failure:
                    pass
コード例 #3
0
ファイル: test_subscription.py プロジェクト: yohummus/yogi
 def connect(self):
     self.assertIs(yogi.SubscriptionState.UNSUBSCRIBED,
                   self.tmB.get_subscription_state())
     self.connection = yogi.LocalConnection(self.leafA, self.leafB)
     while self.tmB.get_subscription_state(
     ) is yogi.SubscriptionState.UNSUBSCRIBED:
         pass
     self.assertIs(yogi.SubscriptionState.SUBSCRIBED,
                   self.tmB.get_subscription_state())
コード例 #4
0
ファイル: test_terminals.py プロジェクト: yohummus/yogi
 def connect(self, binder, subscribable=None):
     self.assertIs(yogi.BindingState.RELEASED, binder.get_binding_state())
     self.connection = yogi.LocalConnection(self.leafA, self.leafB)
     while binder.get_binding_state() is yogi.BindingState.RELEASED:
         pass
     while subscribable and subscribable.get_subscription_state(
     ) is yogi.SubscriptionState.UNSUBSCRIBED:
         pass
     self.assertIs(yogi.BindingState.ESTABLISHED,
                   binder.get_binding_state())
コード例 #5
0
ファイル: test_observers.py プロジェクト: yohummus/yogi
    def test_MessageObserverPublishNonCached(self):
        observer = yogi.MessageObserver(self.consumer)

        i = [0]

        def fn1(msg):
            i[0] += 1
            self.assertEqual(123, msg.value)

        callback_id = observer.add(fn1)

        def fn2(msg, cached=False):
            i[0] += 1
            self.assertEqual(123, msg.value)
            self.assertFalse(cached)

        observer.add(fn2)

        self.assertIs(0, i[0])

        observer.start()
        self.connection = yogi.LocalConnection(self.leafA, self.leafB)

        msg = self.producer.make_message(value=123)
        while not self.producer.try_publish(msg):
            pass
        while i[0] < 2:
            pass
        self.assertIs(2, i[0])

        observer.remove(callback_id)
        self.producer.publish(msg)
        while i[0] < 3:
            pass
        self.assertIs(3, i[0])

        observer.stop()
        self.producer.publish(msg)
        self.assertIs(3, i[0])
コード例 #6
0
ファイル: test_observers.py プロジェクト: yohummus/yogi
    def test_MessageObserverPublishCached(self):
        observer = yogi.MessageObserver(self.cachedConsumer)

        i = [0]

        def fn(msg, cached):
            i[0] += 1
            self.assertEqual(123, msg.value)
            if i[0] < 3:
                self.assertTrue(cached)
            else:
                self.assertFalse(cached)

        callback_id = observer.add(fn)
        observer.add(fn)

        self.assertIs(0, i[0])

        msg = self.cachedProducer.make_message(value=123)
        self.cachedProducer.try_publish(msg)

        observer.start()
        self.connection = yogi.LocalConnection(self.leafA, self.leafB)

        while i[0] < 2:
            pass
        self.assertIs(2, i[0])

        observer.remove(callback_id)
        self.cachedProducer.publish(msg)
        while i[0] < 3:
            pass
        self.assertIs(3, i[0])

        observer.stop()
        self.cachedProducer.publish(msg)
        self.assertIs(3, i[0])
コード例 #7
0
ファイル: test_logging.py プロジェクト: yohummus/yogi
    def test_ProcessInterface(self):
        yogi.Logger.colourised_stdout = False

        argv = [
            '-j', '''
            {
                "logging": {
                    "stdout": {
                        "colourised": true,
                        "max-verbosity": "DEBUG",
                        "component-verbosity": {
                            "App"  : "ERROR",
                            "Yogi" : "FATAL",
                            "test" : "TRACE"
                        }
                    },
                    "yogi": {
                        "max-verbosity": "INFO",
                        "component-verbosity": {
                            "App"  : "DEBUG",
                            "Yogi" : "INFO",
                            "test" : "WARNING"
                        }
                    }
                }
            }'''
        ]

        scheduler = yogi.Scheduler()
        leaf = yogi.Leaf(scheduler)
        pi = yogi.ProcessInterface(argv)

        # check initial configuration
        self.assertTrue(yogi.Logger.colourised_stdout)
        self.assertIs(yogi.Verbosity.DEBUG, yogi.Logger.max_stdout_verbosity)
        self.assertIs(yogi.Verbosity.ERROR, yogi.Logger().stdout_verbosity)
        self.assertIs(yogi.Verbosity.ERROR,
                      yogi.Logger('App').stdout_verbosity)
        self.assertIs(yogi.Verbosity.FATAL,
                      yogi.Logger('Yogi').stdout_verbosity)
        self.assertIs(yogi.Verbosity.TRACE,
                      yogi.Logger('test').stdout_verbosity)

        self.assertIs(yogi.Verbosity.INFO, yogi.Logger.max_yogi_verbosity)
        self.assertIs(yogi.Verbosity.DEBUG, yogi.Logger().yogi_verbosity)
        self.assertIs(yogi.Verbosity.DEBUG, yogi.Logger('App').yogi_verbosity)
        self.assertIs(yogi.Verbosity.INFO, yogi.Logger('Yogi').yogi_verbosity)
        self.assertIs(yogi.Verbosity.WARNING,
                      yogi.Logger('test').yogi_verbosity)

        # check logging over YOGI
        log_terminal = yogi.ConsumerTerminal('/Process/Log',
                                             yogi_000009cd_pb2,
                                             leaf=leaf)
        connection = yogi.LocalConnection(leaf, pi.leaf)
        while log_terminal.get_binding_state() is yogi.BindingState.RELEASED:
            pass

        with AsyncCall() as wrap:

            def fn(res, msg):
                self.assertEqual(yogi.Success(), res)
                self.assertEqual('Hello', msg.value.first)
                info = json.loads(msg.value.second)
                self.assertEqual('App', info['component'])
                self.assertEqual('FATAL', info['severity'])
                self.assertGreater(info['thread'], 0)

            log_terminal.async_receive_message(wrap(fn))
            yogi.log_fatal('Hello')

        # check changing verbosity levels at runtime
        logger = yogi.Logger('My Component')
        max_verbosity_terminal = yogi.CachedSlaveTerminal(
            '/Process/YOGI Log Verbosity/Max Verbosity',
            yogi_00004004_pb2,
            leaf=leaf)
        while max_verbosity_terminal.get_binding_state(
        ) is yogi.BindingState.RELEASED:
            pass
        while max_verbosity_terminal.get_subscription_state(
        ) is yogi.SubscriptionState.UNSUBSCRIBED:
            pass

        self.change_verbosity(max_verbosity_terminal, yogi.Verbosity.INFO)

        verbosity_terminal = yogi.CachedSlaveTerminal(
            '/Process/YOGI Log Verbosity/Components/My Component',
            yogi_00004004_pb2,
            leaf=leaf)
        while verbosity_terminal.get_binding_state(
        ) is yogi.BindingState.RELEASED:
            pass
        while verbosity_terminal.get_subscription_state(
        ) is yogi.SubscriptionState.UNSUBSCRIBED:
            pass

        self.change_verbosity(verbosity_terminal, yogi.Verbosity.DEBUG)

        # check that new verbosity levels are being applied
        with AsyncCall() as wrap:

            def fn(res, msg):
                self.assertEqual(yogi.Success(), res)
                self.assertEqual('Go', msg.value.first)

            log_terminal.async_receive_message(wrap(fn))
            logger.log_info('Go')

        self.change_verbosity(verbosity_terminal, yogi.Verbosity.WARNING)

        with AsyncCall() as wrap:

            def fn(res, msg):
                self.assertEqual(yogi.Success(), res)
                self.assertEqual('Vegan', msg.value.first)

            log_terminal.async_receive_message(wrap(fn))
            logger.log_info('Welcome')
            logger.log_warning('Vegan')

        self.change_verbosity(max_verbosity_terminal, yogi.Verbosity.ERROR)

        with AsyncCall() as wrap:

            def fn(res, msg):
                self.assertEqual(yogi.Success(), res)
                self.assertEqual('Mate', msg.value.first)

            log_terminal.async_receive_message(wrap(fn))
            logger.log_warning('Dude')
            logger.log_error('Mate')

        # clean up
        connection.destroy()
        verbosity_terminal.destroy()
        max_verbosity_terminal.destroy()
        log_terminal.destroy()
        leaf.destroy()
        scheduler.destroy()
        pi.destroy()
コード例 #8
0
ファイル: test_node.py プロジェクト: yohummus/yogi
 def setUp(self):
     self.scheduler = yogi.Scheduler()
     self.node = yogi.Node(self.scheduler)
     self.leaf = yogi.Leaf(self.scheduler)
     self.connection = yogi.LocalConnection(self.node, self.leaf)
コード例 #9
0
 def setUp(self):
     self.scheduler = yogi.Scheduler()
     self.endpointA = yogi.Leaf(self.scheduler)
     self.endpointB = yogi.Leaf(self.scheduler)
     self.connection = yogi.LocalConnection(self.endpointA, self.endpointB)
コード例 #10
0
ファイル: test_binding.py プロジェクト: yohummus/yogi
 def connect(self):
     self.assertIs(yogi.BindingState.RELEASED, self.bd.get_binding_state())
     self.connection = yogi.LocalConnection(self.leafA, self.leafB)
     while self.bd.get_binding_state() is yogi.BindingState.RELEASED:
         pass
     self.assertIs(yogi.BindingState.ESTABLISHED, self.bd.get_binding_state())