Пример #1
0
    def test_start_and_shutdown_with_configured_queue_processor(self):
        start_time = time()
        destination = StubDestination(10)
        server = Server()
        processor = server.create_queue_processor()
        processor.set_destinations([destination])
        processor.flush_interval = 0.5
        server.queue_processor = processor
        metric = Counter('test.metric', 1)
        collector = StubCollector(data=metric.to_request(), frequency=10)
        server.set_collectors([collector])
        server_thread = Thread(target=server.start)
        server_thread.setDaemon(True)
        server_thread.start()
        server.wait_until_running(5)
        self.assertTrue(server.is_running())
        destination.wait_until_expected_count_items(10)

        server.shutdown()
        server.wait_until_shutdown(5)
        self.assertFalse(server.is_running())
        self.assertFalse(server_thread.isAlive())
        self.assertFalse(collector.is_queuing_requests())
        self.assertFalse(processor.is_processing())

        self.assertGreaterEqual(len(destination.metrics), 10)
        for metric in destination.metrics:
            self.assertEqual(3, len(metric))
            self.assertEqual(metric[0], "test.metric")
            self.assertGreaterEqual(metric[1], 0)
            self.assertGreaterEqual(metric[2], start_time)
Пример #2
0
    def test_reload_stops_collectors_and_processor_and_new_ones_used_in_server_start_thread(self):
        start_time = time()
        destination = StubDestination(10)
        server = Server()
        processor = server.create_queue_processor()
        processor.set_destinations([destination])
        processor.flush_interval = 0.5
        server.queue_processor = processor
        metric = Counter('test.metric', 1)
        collector = StubCollector(data=metric.to_request(), frequency=10)
        server.set_collectors([collector])
        server_thread = Thread(target=server.start)
        server_thread.setDaemon(True)
        server_thread.start()
        server.wait_until_running(5)
        self.assertTrue(server.is_running())
        destination.wait_until_expected_count_items(10)

        metric2 = Counter('test.metric2', 1)
        collector2 = StubCollector(data=metric2.to_request(), frequency=10)
        destination2 = StubDestination(5)
        processor2 = server.create_queue_processor()
        processor2.set_destinations([destination2])
        processor2.flush_interval = 0.5
        server.queue_processor = processor2
        server.set_collectors([collector2])
        server.reload()
        server.wait_until_reload(10)
        self.assertTrue(server_thread.isAlive())
        self.assertTrue(server.is_running())
        self.assertTrue(collector2.is_queuing_requests())
        self.assertTrue(processor2.is_processing())
        self.assertFalse(collector.is_queuing_requests())
        self.assertFalse(processor.is_processing())
        destination2.wait_until_expected_count_items(15)

        self.assertEqual(len(destination2.metrics), 5)
        for metric in destination2.metrics:
            self.assertEqual(3, len(metric))
            self.assertEqual(metric[0], "test.metric2")
            self.assertGreaterEqual(metric[1], 0)
            self.assertGreaterEqual(metric[2], start_time)
Пример #3
0
 def test_start_fails_without_collectors(self):
     server = Server()
     processor = server.create_queue_processor()
     processor.set_destinations([StubDestination()])
     server.queue_processor = processor
     self.assertRaises(Exception, server.start)
Пример #4
0
 def test_create_queue_processor(self):
     server = Server()
     server.logger = logging.getLogger('test')
     processor = server.create_queue_processor()
     self.assertIsInstance(processor, QueueProcessor)
     self.assertEqual(server.logger, processor.logger)