def test_read_metric(self): tsd = LevelTsdBase('/tmp') reader = LevelTsdReader(tsd) writer = LevelTsdWriter(tsd) self.assertTrue(writer.write("just.purge", 1, 2.4)) self.assertTrue(writer.write("just.delete", 1, 2.4)) self.assertTrue(writer.write("fubar.zigar", 112, 3.14)) self.assertTrue(writer.write("fubar.zigar", 90000, 3.14)) self.assertTrue(writer.write("fubar.zigar", 90000000, 2.18)) tsd.flush(True) just_children = reader.get_child_nodes('just') self.assertTrue('purge' in just_children) self.assertTrue('delete' in just_children) self.assertTrue(reader.is_node_leaf('just.purge')) dp = list(reader.get_range_data("just.purge", 1, 100)) print dp self.assertEqual(len(dp), 1) dp = list(reader.get_range_data("fubar.zigar", 1, 100000)) print dp self.assertEqual(len(dp), 2)
def test_create_metric(self): tsd = LevelTsdBase('/tmp') writer = LevelTsdWriter(tsd) ddb = tsd.dir_db mdb = tsd.indexer self.assertTrue(writer.write("foo.bar", 1, 2.4)) self.assertTrue(writer.write("foo.baz", int(time()), 12.1)) self.assertTrue(writer.write("foo.baz", int(time()) - 90000, -1)) self.assertTrue(writer.write("foo.bazigar", 112, 3.14)) self.assertTrue(writer.write("foo.bazigar", 90000, 3.14)) self.assertTrue(writer.write("foo.bazigar", 90000000, 2.18)) tsd.flush(True) self.assertTrue(writer.purge_db_data("foo.bazigar")) self.assertTrue(writer.purge_db_data("foo"))
def test_dir_metric(self): tsd = LevelTsdBase('/tmp') ddb = tsd.dir_db ddb.upsert("a.b.c.d.january") ddb.upsert("a.b.c.d.january.monday") ddb.upsert("a.b.c.d.feburary") ddb.upsert("a.b.c.d.feburary.tuesday") ddb.upsert("a.b.c.d.feburary.wednesday") ddb.upsert("a.b.c.d.march.sunday.one") ddb.upsert("a.b.c.d.march.sunday.two") feb_child = ddb.get_children("a.b.c.d.feburary") self.assertEqual(set(feb_child), set(('tuesday', 'wednesday')))
def __init__(self, settings): self.db = LevelTsdBase(settings['LOCAL_DATA_DIR']) self.writer = LevelTsdWriter(self.db) LevelTsdCarbon._pesudo_singleton = self