def test_meters_with_tags_b(self): """ Test """ hca = Meters._tags_hash_compute_and_store({"flag1": "FA"}) hcb = Meters._tags_hash_compute_and_store({"flag2": "FB"}) Meters.aii("ai1") Meters.aii("ai1", tags={"flag1": "FA"}) Meters.aii("ai1", tags={"flag1": "FA"}) Meters.aii("ai1", tags={"flag2": "FB"}) Meters.aii("ai1", tags={"flag2": "FB"}) Meters.aii("ai1", tags={"flag2": "FB"}) Meters.dtci("dtc1", 0) Meters.dtci("dtc1", 50) Meters.dtci("dtc1", 100) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[0].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[50].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[100].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[500].get(), 0) Meters.dtci("dtc1", 0, tags={"flag1": "FA"}) Meters.dtci("dtc1", 50, tags={"flag1": "FA"}) Meters.dtci("dtc1", 100, tags={"flag1": "FA"}) Meters.dtci("dtc1", 0, tags={"flag2": "FB"}) Meters.dtci("dtc1", 50, tags={"flag2": "FB"}) Meters.dtci("dtc1", 100, tags={"flag2": "FB"}) Meters.dtci("dtc1", 0, tags={"flag2": "FB"}) Meters.dtci("dtc1", 50, tags={"flag2": "FB"}) Meters.dtci("dtc1", 100, tags={"flag2": "FB"}) self.assertEquals(Meters._hash_meter["a_int"]["ai1#"].get(), 1) self.assertEquals(Meters._hash_meter["a_int"]["ai1#" + hca].get(), 2) self.assertEquals(Meters._hash_meter["a_int"]["ai1#" + hcb].get(), 3) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[0].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[50].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[100].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[500].get(), 0) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[0].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[50].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[100].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[500].get(), 0) # Write Meters.write_to_logger()
def test_tags_hash(self): """ Test """ d1 = {"a": "va", "b": "vb"} s1 = Meters._tags_hash_compute_and_store(d1) self.assertIsNotNone(s1) self.assertGreater(len(s1), 0) self.assertIn(s1, Meters._hash_meter["tags_hash"]) self.assertEquals(d1, Meters._hash_meter["tags_hash"][s1]) d2 = {"b": "vb", "a": "va"} s2 = Meters._tags_hash_compute_and_store(d2) self.assertIsNotNone(s2) self.assertGreater(len(s2), 0) self.assertIn(s2, Meters._hash_meter["tags_hash"]) self.assertEquals(d2, Meters._hash_meter["tags_hash"][s2]) d3 = {"a": "za", "b": "zb"} s3 = Meters._tags_hash_compute_and_store(d3) self.assertIsNotNone(s3) self.assertGreater(len(s3), 0) self.assertIn(s3, Meters._hash_meter["tags_hash"]) self.assertNotEqual(s1, s3) self.assertEquals(s1, s2) self.assertEquals(len(Meters._hash_meter["tags_hash"]), 2) Meters.reset() self.assertEquals(len(Meters._hash_meter["tags_hash"]), 0) s_tags_1 = Meters.tags_format_for_logger(d1) s_tags_2 = Meters.tags_format_for_logger(d2) logger.info("Got s_tags_1=%s", s_tags_1) logger.info("Got s_tags_2=%s", s_tags_2) self.assertEquals(s_tags_1, s_tags_2) self.assertEquals(s_tags_1, " (a:va,b:vb) ")
def test_key(self): """ Test """ d1 = {"a": "va", "b": "vb"} s1 = Meters._tags_hash_compute_and_store(d1) k1 = Meters._key_compute("zzz", d1) self.assertEquals(k1, "zzz#" + s1) s_key, s_sash = Meters._key_split(k1) self.assertEquals(s_key, "zzz") self.assertEquals(s_sash, s1) self.assertEquals(Meters._key_compute("zzz", None), "zzz#") self.assertEquals(Meters._key_compute("zzz", {}), "zzz#") s_key, s_sash = Meters._key_split("zzz#") self.assertEquals(s_key, "zzz") self.assertEquals(s_sash, None)
def test_meters_with_tags_a_with_udp_check(self): """ Test """ hca = Meters._tags_hash_compute_and_store({"flag": "FA"}) hcb = Meters._tags_hash_compute_and_store({"flag": "FB"}) Meters.aii("ai1") Meters.aii("ai1", tags={"flag": "FA"}) Meters.aii("ai1", tags={"flag": "FA"}) Meters.aii("ai1", tags={"flag": "FB"}) Meters.aii("ai1", tags={"flag": "FB"}) Meters.aii("ai1", tags={"flag": "FB"}) Meters.dtci("dtc1", 0) Meters.dtci("dtc1", 50) Meters.dtci("dtc1", 100) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[0].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[50].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[100].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#"]._sorted_dict[500].get(), 0) Meters.dtci("dtc1", 0, tags={"flag": "FA"}) Meters.dtci("dtc1", 50, tags={"flag": "FA"}) Meters.dtci("dtc1", 100, tags={"flag": "FA"}) Meters.dtci("dtc1", 0, tags={"flag": "FB"}) Meters.dtci("dtc1", 50, tags={"flag": "FB"}) Meters.dtci("dtc1", 100, tags={"flag": "FB"}) Meters.dtci("dtc1", 0, tags={"flag": "FB"}) Meters.dtci("dtc1", 50, tags={"flag": "FB"}) Meters.dtci("dtc1", 100, tags={"flag": "FB"}) self.assertEquals(Meters._hash_meter["a_int"]["ai1#"].get(), 1) self.assertEquals(Meters._hash_meter["a_int"]["ai1#" + hca].get(), 2) self.assertEquals(Meters._hash_meter["a_int"]["ai1#" + hcb].get(), 3) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[0].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[50].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[100].get(), 1) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hca]._sorted_dict[500].get(), 0) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[0].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[50].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[100].get(), 2) self.assertEquals(Meters._hash_meter["dtc"]["dtc1#" + hcb]._sorted_dict[500].get(), 0) # Write Meters.write_to_logger() # Upd check ar_udp = Meters.meters_to_udp_format(send_pid=True, send_tags=True, send_dtc=True) total_check = 0 total_ok = 0 total_ko_not_found = 0 total_ko_multiple_found = 0 for s_key, d_tag, v in [ ("ai1", {}, 1), ("ai1", {"flag": "FA", }, 2), ("ai1", {"flag": "FB", }, 3), ("dtc1_0-50", {}, 1), ("dtc1_50-100", {}, 1), ("dtc1_100-500", {}, 1), ("dtc1_500-1000", {}, 0), ("dtc1_1000-2500", {}, 0), ("dtc1_2500-5000", {}, 0), ("dtc1_5000-10000", {}, 0), ("dtc1_10000-30000", {}, 0), ("dtc1_30000-60000", {}, 0), ("dtc1_60000-MAX", {}, 0), ("dtc1_0-50", {"flag": "FA", }, 1), ("dtc1_50-100", {"flag": "FA", }, 1), ("dtc1_100-500", {"flag": "FA", }, 1), ("dtc1_500-1000", {"flag": "FA", }, 0), ("dtc1_1000-2500", {"flag": "FA", }, 0), ("dtc1_2500-5000", {"flag": "FA", }, 0), ("dtc1_5000-10000", {"flag": "FA", }, 0), ("dtc1_10000-30000", {"flag": "FA", }, 0), ("dtc1_30000-60000", {"flag": "FA", }, 0), ("dtc1_60000-MAX", {"flag": "FA", }, 0), ("dtc1_0-50", {"flag": "FB", }, 2), ("dtc1_50-100", {"flag": "FB", }, 2), ("dtc1_100-500", {"flag": "FB", }, 2), ("dtc1_500-1000", {"flag": "FB", }, 0), ("dtc1_1000-2500", {"flag": "FB", }, 0), ("dtc1_2500-5000", {"flag": "FB", }, 0), ("dtc1_5000-10000", {"flag": "FB", }, 0), ("dtc1_10000-30000", {"flag": "FB", }, 0), ("dtc1_30000-60000", {"flag": "FB", }, 0), ("dtc1_60000-MAX", {"flag": "FB", }, 0), ]: total_check += 1 # Locate it found = 0 for check_key, check_tag, check_v, _, _ in ar_udp: if check_key == s_key and check_tag == d_tag and check_v == v: found += 1 # Check if found == 0: total_ko_not_found += 1 elif found > 1: total_ko_multiple_found += 1 else: total_ok += 1 # Final self.assertEquals(total_ko_multiple_found, 0) self.assertEquals(total_ko_multiple_found, 0) self.assertEquals(total_ok, total_check) self.assertEquals(len(ar_udp), total_check)