Exemplo n.º 1
0
    def test_plugin_wrapper_no_collector(self):
        class TestBundle(object):
            label = 'test'
            label_extractor = None
            collector = None

        wrapped = scrutinize.plugin_wrapper(TestBundle())
        self.assertRaises(scrutinize.NoCollector, wrapped)
Exemplo n.º 2
0
    def test_plugin_wrapper_no_collector(self):
        class TestBundle(object):
            label = "test"
            label_extractor = None
            collector = None

        wrapped = scrutinize.plugin_wrapper(TestBundle())
        self.assertRaises(scrutinize.NoCollector, wrapped)
Exemplo n.º 3
0
    def test_plugin_wrapper_happy_day(self):
        collected_metrics =  [('label_a', 10), ('label_b', 20)]

        class TestCollector(collectors.Collector):
            called = []

            def start(iself, label):
                iself.called.append(1)
                return super(TestCollector, iself).start(label)

            def stop(iself, state):
                iself.called.append(2)
                super(TestCollector, iself).stop(state)
                return collected_metrics

            def call_target(iself, __state, __bundle, *args, **kwargs):
                iself.called.append(3)
                self.assertEquals(__state, "test")
                return __bundle.target_impl(*args, **kwargs)

        class TestBundle(object):
            label = 'test'
            label_extractor = None
            collector = TestCollector({})

            def target_impl(iself, a, b, c=3):
                return a + b + c

            def notify(iself, metrics):
                self.assertEquals(collected_metrics, metrics)

        bundle = TestBundle()
        wrapped = scrutinize.plugin_wrapper(bundle)
        result = wrapped(1, 2)
        self.assertEquals(result, 6)
        self.assertEquals([1,3,2], bundle.collector.called)
Exemplo n.º 4
0
    def test_plugin_wrapper_happy_day(self):
        collected_metrics = [("label_a", 10), ("label_b", 20)]

        class TestCollector(collectors.Collector):
            called = []

            def start(iself, label):
                iself.called.append(1)
                return super(TestCollector, iself).start(label)

            def stop(iself, state):
                iself.called.append(2)
                super(TestCollector, iself).stop(state)
                return collected_metrics

            def call_target(iself, __state, __bundle, *args, **kwargs):
                iself.called.append(3)
                self.assertEquals(__state, "test")
                return __bundle.target_impl(*args, **kwargs)

        class TestBundle(object):
            label = "test"
            label_extractor = None
            collector = TestCollector({})

            def target_impl(iself, a, b, c=3):
                return a + b + c

            def notify(iself, metrics):
                self.assertEquals(collected_metrics, metrics)

        bundle = TestBundle()
        wrapped = scrutinize.plugin_wrapper(bundle)
        result = wrapped(1, 2)
        self.assertEquals(result, 6)
        self.assertEquals([1, 3, 2], bundle.collector.called)