Пример #1
0
    def test_to_json_startup(self):
        from datetime import datetime as dt
        recently = dt.utcnow() - timedelta(seconds=30)
        expected = recently.strftime('%Y-%m-%dT%H:%M:%SZ')
        conf = HandlerConf(service_id='service_id', startup=recently)

        self.assertEqual(expected, conf.to_json()['startup'])
        self.assertAlmostEqual(30, conf.to_json()['uptime'], delta=2)
Пример #2
0
    def update_handler(self, handler_conf: HandlerConf):
        if handler_conf.node_id() not in self.handlers:
            return

        fields = [
            'return_to', 'event', 'method', 'retries', 'timeout', 'group_id',
            'path', 'failed_topic'
        ]
        for handler_type in self.env.handler_types:
            for field in fields:
                updated = handler_conf.__getattribute__(field)
                self.handlers[handler_conf.node_id()][
                    handler_type.name].__setattr__(field, updated)
Пример #3
0
    def test_demote_one_handler(self):
        conf = HandlerConf(
            name='name', event='event', endpoint='endpoint', version='version',
            path='/path', model_type='model', node=0, timeout=60, retries=3,
            enabled=1, retired=0, service_id='serviceid', return_to='return',
            port=4444, hostname='hostname', traffic=0.1, reader_type='kafka',
            event_display_name='event'
        )
        node_id = HandlerConf.to_node_id(
            conf.service_id,
            conf.hostname,
            conf.model_type,
            conf.node
        )

        self.assertIsNone(self.db.demote_model(node_id))
Пример #4
0
 def test_from_node_id(self):
     service_id, hostname, model, node = HandlerConf.from_node_id(
         'service_id-hostname-model-0')
     self.assertEqual(service_id, 'service_id')
     self.assertEqual(hostname, 'hostname')
     self.assertEqual(model, 'model')
     self.assertEqual(node, '0')
Пример #5
0
    def test_get_handler_for(self):
        conf = HandlerConf(
            name='name', event='event', endpoint='endpoint', version='version',
            path='/path', model_type='model', node=0, timeout=60, retries=3,
            enabled=1, retired=0, service_id='serviceid', return_to='return',
            port=4444, hostname='hostname', traffic=0.1, reader_type='kafka',
            event_display_name='event'
        )
        node_id = HandlerConf.to_node_id(
            conf.service_id,
            conf.hostname,
            conf.model_type,
            conf.node
        )

        with self.assertRaises(HandlerNotFoundException):
            self.db.get_handler_for(node_id)
Пример #6
0
    def test_enabled_for(self):
        conf = HandlerConf(name='name',
                           event='event',
                           endpoint='endpoint',
                           version='version',
                           path='/path',
                           model_type='model',
                           node=0,
                           timeout=60,
                           retries=3,
                           enabled=1,
                           retired=0,
                           service_id='serviceid',
                           return_to='return',
                           port=4444,
                           hostname='hostname',
                           traffic=0.1,
                           reader_type='kafka',
                           event_display_name='event')
        node_id = HandlerConf.to_node_id(conf.service_id, conf.hostname,
                                         conf.model_type, conf.node)

        handlers = self.db.get_enabled_handlers_for(node_id)
        self.assertListEqual(list(), handlers)
Пример #7
0
 def test_create_handler(self):
     conf = HandlerConf(name='name',
                        event='event',
                        endpoint='endpoint',
                        version='version',
                        path='/path',
                        model_type='model',
                        node=0,
                        timeout=60,
                        retries=3,
                        enabled=1,
                        retired=0,
                        service_id='serviceid',
                        return_to='return',
                        port=4444,
                        hostname='hostname',
                        traffic=0.1,
                        reader_type='kafka',
                        event_display_name='event')
     self.assertIsNotNone(self.db.register_handler(conf))
Пример #8
0
 def test_get_one_handler(self):
     conf = HandlerConf(name='name',
                        event='event',
                        endpoint='endpoint',
                        version='version',
                        path='/path',
                        model_type='model',
                        node=0,
                        timeout=60,
                        retries=3,
                        enabled=1,
                        retired=0,
                        service_id='serviceid',
                        return_to='return',
                        port=4444,
                        hostname='hostname',
                        traffic=0.1,
                        reader_type='kafka',
                        event_display_name='event')
     self.assertIsNotNone(self.db.register_handler(conf))
     environ.env.dbman.session.commit()
     self.assertEqual(1,
                      len(self.db.get_all_handlers(include_retired=True)))
Пример #9
0
    def test_update_consul(self):
        conf = HandlerConf(name='name',
                           event='event',
                           endpoint='endpoint',
                           version='version',
                           path='/path',
                           model_type='model',
                           node=0,
                           timeout=60,
                           retries=3,
                           enabled=1,
                           retired=0,
                           service_id='serviceid',
                           return_to='return',
                           port=4444,
                           hostname='hostname',
                           traffic=0.1,
                           reader_type='kafka',
                           event_display_name='event')

        handler = self.db.update_consul_service_id_and_group_id(
            conf, 'asdf', dict())
        self.assertIsNotNone(handler)
Пример #10
0
 def test_build_group_id(self):
     conf = HandlerConf(service_id='foo-bar-baz', group_id='group_id')
     self.assertEqual(conf.group_id, conf.build_group_id())
Пример #11
0
 def test_from_node_id_missing_one(self):
     with self.assertRaises(AttributeError):
         HandlerConf.from_node_id('service_id-hostname-model')
Пример #12
0
 def test_build_group_id_from_service_id_blank(self):
     conf = HandlerConf(service_id='foo-bar-baz', group_id='')
     self.assertEqual('foo', conf.build_group_id())
Пример #13
0
 def _gen_conf(self, enabled=False, hostname='machine_a'):
     handler_conf = HandlerConf()
     handler_conf.service_id = 'testthing'
     handler_conf.node = '0'
     handler_conf.port = '9999'
     handler_conf.event = 'event-test'
     handler_conf.reader_type = 'kafka'
     handler_conf.hostname = hostname
     handler_conf.enabled = enabled
     handler_conf.retries = 3
     handler_conf.timeout = 10
     handler_conf.endpoint = 'localhost'
     handler_conf.return_to = 'return-topic'
     handler_conf.path = 'test'
     handler_conf.name = 'testthing'
     handler_conf.model_type = ModelTypes.MODEL
     return handler_conf