Example #1
0
    def setUp(self):
        config = get_collector_config('YammerCollector', {})

        self.collector = YammerCollector(config, None)
Example #2
0
class TestYammerCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('YammerCollector', {})

        self.collector = YammerCollector(config, None)

    def test_import(self):
        self.assertTrue(YammerCollector)

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        patch_urlopen = patch('urllib2.urlopen',
                              Mock(return_value=self.getFixture('stats')))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        metrics = {
            'jvm.memory.totalInit': 9.142272E7,
            'jvm.memory.totalUsed': 1.29674584E8,
            'jvm.memory.totalMax': 1.13901568E9,
            'jvm.memory.totalCommitted': 1.62267136E8,
            'jvm.memory.heapInit': 6.7108864E7,
            'jvm.memory.heapUsed': 8.3715232E7,
            'jvm.memory.heapMax': 9.54466304E8,
            'jvm.memory.heapCommitted': 1.15539968E8,
            'jvm.memory.heap_usage': 0.08770894441130528,
            'jvm.memory.non_heap_usage': 0.24903553182428534,
            'jvm.memory.memory_pool_usages.Code_Cache': 0.038289388020833336,
            'jvm.memory.memory_pool_usages.PS_Eden_Space': 0.1918924383560846,
            'jvm.memory.memory_pool_usages.PS_Old_Gen': 0.022127459689416828,
            'jvm.memory.memory_pool_usages.PS_Perm_Gen': 0.32806533575057983,
            'jvm.memory.memory_pool_usages.PS_Survivor_Space': 1.0,
            'jvm.daemon_thread_count': 10,
            'jvm.thread_count': 27,
            'jvm.fd_usage': 0.014892578125,
            'jvm.thread_states.timed_waiting': 0.5185185185185185,
            'jvm.thread_states.runnable': 0.0,
            'jvm.thread_states.blocked': 0.0,
            'jvm.thread_states.waiting': 0.2222222222222222,
            'jvm.thread_states.new': 0.0,
            'jvm.thread_states.terminated': 0.0
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)

    @patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        patch_urlopen = patch(
            'urllib2.urlopen',
            Mock(
                return_value=self.getFixture('stats_blank')))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        self.assertPublishedMany(publish_mock, {})