def test_send(self, *args): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/crawler:password', batch_send_every_t=1000, batch_send_every_n=3) assert mt.next_timeout == 2000 with self.assertRaises(TypeError): mt.send_messages(1) m1 = mt.construct_message('space', 'group', 'cpu', 100, 1) m2 = mt.construct_message('space', 'group', 'cpu', 100, 2) with self.assertRaises(TypeError): mt.send_messages(m1) # we will not send anything yet as send_every_n is 3 mt.send_messages([m1, m2]) assert mt.msgset == [m1, m2] # now we should send something m3 = mt.construct_message('space', 'group', 'cpu', 100, 3) mt.send_messages([m3]) assert mt.msgset == [] mt.close() assert mt.conn is None
def init(self, url, timeout=1, max_retries=5, emit_format='graphite'): self.url = url self.timeout = timeout self.max_retries = max_retries self.emit_per_line = True if emit_format != 'graphite': raise EmitterUnsupportedFormat('Not supported: %s' % emit_format) self.formatter = write_in_graphite_format self.mtgraphite_client = MTGraphiteClient(self.url)
def test_init(self, *args): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/crawler:password', batch_send_every_t=1, batch_send_every_n=10) assert not mt.conn assert not mt.socket assert mt.next_timeout == 1001 assert mt.host == '2.2.2.2' assert mt.port == '123' assert mt.tenant == 'crawler' assert mt.password == 'password' args[0].assert_called()
def test_send_bad_password(self, *args): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/crawler:password', batch_send_every_t=1000, batch_send_every_n=3) assert mt.next_timeout == 2000 m1 = mt.construct_message('space', 'group', 'cpu', 100, 1) m2 = mt.construct_message('space', 'group', 'cpu', 100, 2) m3 = mt.construct_message('space', 'group', 'cpu', 100, 3) with self.assertRaises(MTGraphiteInvalidTenant): mt.send_messages([m1, m2, m3]) assert mt.msgset == [m1, m2, m3]
def test_init_bad_urls(self, *args): with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/crawler') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/:password') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123/') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2:123') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2/crawler') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://2.2.2.2/crawler:password') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://:234/crawler:password') with self.assertRaises(ValueError): mt = MTGraphiteClient('mtgraphite://') with self.assertRaises(ValueError): mt = MTGraphiteClient('http://1.2.3.4:234/crawler:password') with self.assertRaises(ValueError): mt = MTGraphiteClient('host.com:234/crawler:password') with self.assertRaises(ValueError): mt = MTGraphiteClient('host') mt = MTGraphiteClient('mtgraphite://host.com:234/crawler:password') assert mt