示例#1
0
 def test_tcp_crlf_dp(self):
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.set_metric(self.test_metric, 20, lf='\r\n')
     setup_tcp_receiver(tcp_receiver)
     reciever_run_shutdown(tcp_receiver, 1)
     self.assertEqual(len(my_spool._spools), 1)
示例#2
0
 def test_tcp_multi_dp(self):
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     [tcp_receiver._sock.set_metric(self.test_metric, 20) for _ in range(20)]
     setup_tcp_receiver(tcp_receiver)
     reciever_run_shutdown(tcp_receiver, 5)
     self.assertEqual(len(my_spool._spools), 1)
示例#3
0
 def test_key_in_metric(self):
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.metric = "%s.%s %s\n" % (API_KEY, "foo.bar.baz", 20)
     tcp_receiver._sock.metric_count += 1
     setup_tcp_receiver(tcp_receiver)
     reciever_run_shutdown(tcp_receiver, 1)
     self.assertEqual(len(my_spool._spools), 1)
示例#4
0
 def test_invalid_metric(self):
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.set_metric("@@1.---=++", 20)
     setup_tcp_receiver(tcp_receiver)
     # this won't result in any update.. sleep then shutdown.
     reciever_run_shutdown(tcp_receiver, 1)
     # no valid metric, no spool created.
     self.assertEqual(len(my_spool._spools), 0)
示例#5
0
 def test_tcp_single_dp_spool(self):
     tcp_config_sock = patch('hg_agent_forwarder.receiver.socket')
     tcp_mock_sock = self.tcp_config_sock.start()
     tcp_mock_sock.socket.return_value = MockedTcpRecvSocket()
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     setup_tcp_receiver(tcp_receiver)
     forwarder = MetricForwarder(self.config, self.shutdown)
     forwarder.request_session = FakeSession()
     forwarder.start()
     while len(forwarder.request_session.metrics_posted) < 1:
         if forwarder.should_send_batch():
             forwarder.forward()
         time.sleep(0.01)
     tcp_receiver.shutdown()
     self.assertEqual(len(my_spool.lookup_spools()), 1)
     self.shutdown.set()
     shutdown(forwarder)
     # we only have 1 valid metric.
     self.assertEqual(len(my_spool.lookup_spools()), 1)
     self.assertEqual(len(forwarder.request_session.metrics_posted), 1)
示例#6
0
 def test_fileno_1_string(self):
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.fileno_res = 1
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     setup_tcp_receiver(tcp_receiver)
     time.sleep(1)
     tcp_receiver._sock.fileno_res = 0
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     tcp_receiver._sock.fileno_res = 0
     time.sleep(1)
     reciever_run_shutdown(tcp_receiver, 1)
     self.assertEqual(len(my_spool._spools), 1)
示例#7
0
 def test_tcp_multi_dp_low_timeout(self):
     conf = self.config
     conf['tcp']['timeout'] = 0.0001
     tcp_receiver = MetricReceiverTcp(conf)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     setup_tcp_receiver(tcp_receiver)
     time.sleep(2)
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     tcp_receiver._sock.set_metric(self.test_metric, 22)
     time.sleep(2)
     reciever_run_shutdown(tcp_receiver, 2)
     self.assertEqual(len(my_spool._spools), 1)
示例#8
0
    def test_too_many_spools(self):
        tcp_receiver = MetricReceiverTcp(self.config)
        # create too many spools, sleep to ensure new ts
        for t in range(1000, 1011):
            write_spool(t)
        my_spool = tcp_receiver.spool
        tcp_receiver._sock.set_metric(self.test_metric, 20)
        setup_tcp_receiver(tcp_receiver)
        time.sleep(1)
        reciever_run_shutdown(tcp_receiver, 1)

        all_spools = my_spool.lookup_spools()
        for ts in all_spools:
            self.assertIsInstance(ts, int)
        self.assertEqual(len(all_spools), 10)
示例#9
0
 def test_too_many_spools_rotate_bytes(self):
     conf = self.config
     conf['spool_rotatesize'] = 10
     tcp_receiver = MetricReceiverTcp(conf)
     # create too many spools, sleep to ensure new ts
     for t in range(1000, 1011):
         write_spool(t)
     my_spool = tcp_receiver.spool
     [tcp_receiver._sock.set_metric(self.test_metric, 20) for _ in range(4)]
     setup_tcp_receiver(tcp_receiver)
     while len(my_spool.lookup_spools()) > 10:
         tcp_receiver._sock.set_metric(self.test_metric, 20)
         time.sleep(0.1)
     reciever_run_shutdown(tcp_receiver, 1)
     self.assertEqual(len(my_spool.lookup_spools()), 10)