def test_increment(self): client = BatchClient("localhost") client._socket = self.mock_socket client.increment("event", 2, 0.5) client.flush() self.mock_sendto.assert_called_with( bytearray("event:2|c|@0.5\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.increment("login") client.increment("login.fail", 5, 0.2) client.increment("login.ok", rate=0.8) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.login:1|c\npre.login.ok:1|c|@0.8\n".encode()), ("127.0.0.2", 8125) )
def test_set(self): client = BatchClient("localhost") client._socket = self.mock_socket client.set("username", 'first') client.flush() self.mock_sendto.assert_called_with( bytearray("username:first|s\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.set("user", 'second') client.set("user", 'third', 0.2) client.set("user", 'last', rate=0.5) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.user:second|s\npre.user:last|s|@0.5\n".encode()), ("127.0.0.2", 8125) )
def test_gauge_delta(self): client = BatchClient("localhost") client._socket = self.mock_socket client.gauge_delta("memory", -512) client.flush() self.mock_sendto.assert_called_with( bytearray("memory:-512|g\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.gauge_delta("memory", 2048) client.gauge_delta("memory", 8096, 0.2) client.gauge_delta("storage", -128, rate=0.7) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.memory:+2048|g\npre.storage:-128|g|@0.7\n".encode()), ("127.0.0.2", 8125) )
def test_gauge(self): client = BatchClient("localhost") client._socket = self.mock_socket client.gauge("memory", 10240) client.flush() self.mock_sendto.assert_called_with( bytearray("memory:10240|g\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.gauge("memory", 2048) client.gauge("memory", 8096, 0.2) client.gauge("storage", 512, rate=0.6) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.memory:2048|g\npre.storage:512|g|@0.6\n".encode()), ("127.0.0.2", 8125) )
def test_timing(self): client = BatchClient("localhost") client._socket = self.mock_socket client.timing("event", 10, 0.4) client.flush() self.mock_sendto.assert_called_with( bytearray("event:10|ms|@0.4\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.timing("query", 3) client.timing("process.request", 2, 0.2) client.timing("query.user", 350, rate=0.6) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.query:3|ms\npre.query.user:350|ms|@0.6\n".encode()), ("127.0.0.2", 8125) )
def test_decrement(self): client = BatchClient("localhost") client._socket = self.mock_socket client.decrement("event", 3, 0.7) client.flush() self.mock_sendto.assert_called_with( bytearray("event:-3|c|@0.7\n".encode()), ("127.0.0.2", 8125) ) self.mock_sendto.reset_mock() client.prefix = "pre." client.decrement("session") client.decrement("session.fail", 2, 0.2) client.decrement("session.ok", rate=0.6) client.flush() self.mock_sendto.assert_called_once_with( bytearray("pre.session:-1|c\npre.session.ok:-1|c|@0.6\n".encode()), ("127.0.0.2", 8125) )