Esempio n. 1
0
 def setUp(self):
     all_series = [
         'b1.b1.b1.b1.leaf1', 'b1.b1.b1.b2.leaf1', 'b1.b1.b2.b2.leaf1',
         'b1.b1.b1.b1.leaf2', 'b1.b1.b1.b2.leaf2', 'b1.b1.b2.b2.leaf2'
     ]
     self.index = NodeTreeIndex()
     self.index.insert_series(all_series)
Esempio n. 2
0
 def setUp(self):
     all_series = ['b1.b1.b1.b1.leaf1',
                   'b1.b1.b1.b2.leaf1',
                   'b1.b1.b2.b2.leaf1',
                   'b1.b1.b1.b1.leaf2',
                   'b1.b1.b1.b2.leaf2',
                   'b1.b1.b2.b2.leaf2'
                   ]
     self.index = NodeTreeIndex()
     for serie in all_series:
         self.index.insert(serie)
Esempio n. 3
0
 def test_index_save_load(self):
     config = { 'influxdb': { 'host' : 'localhost',
                              'port' : 8086,
                              'memcache' : {'host': 'localhost',},
                              'user' : 'root',
                              'pass' : 'root',
                              'db' : self.db_name,
                              },
                'statsd': {'host': 'localhost' },
                }
     finder = influxgraph.InfluxDBFinder(config)
     finder.index_path = 'index'
     finder.save_index()
     index_path = finder.index_path
     finder_index = finder.index
     del finder
     self.assertTrue(os.path.isfile('index'))
     # Reload index from file
     index_fh = GzipFile(index_path, 'r')
     try:
         index = NodeTreeIndex.from_file(index_fh)
     finally:
         index_fh.close()
     self.assertTrue(index is not None)
     for query in ['*', '*.*', '*.*.*', '*.*.*.*']:
         self.assertEqual(list(index.query(query)), list(finder_index.query(query)))
Esempio n. 4
0
 def test_to_from_array(self):
     index2 = NodeTreeIndex.from_array(self.index.to_array())
     self.assertEqual(index2.to_array(), self.index.to_array())
     self.assertEqual(list(self.index.query('*')), list(index2.query('*')))
Esempio n. 5
0
class IndexTreeTestCase(unittest.TestCase):
    def setUp(self):
        all_series = [
            'b1.b1.b1.b1.leaf1', 'b1.b1.b1.b2.leaf1', 'b1.b1.b2.b2.leaf1',
            'b1.b1.b1.b1.leaf2', 'b1.b1.b1.b2.leaf2', 'b1.b1.b2.b2.leaf2'
        ]
        self.index = NodeTreeIndex()
        self.index.insert_series(all_series)

    def test_root_wildcard(self):
        result = list(self.index.query('*'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0]['metric'] == 'b1')
        result = list(self.index.query('b1'))
        self.assertTrue(result[0]['metric'] == 'b1')
        result = list(self.index.query('b1.*'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0]['metric'] == 'b1.b1')
        result = list(self.index.query('b1.b1.*'))
        self.assertTrue(len(result) == 2)
        self.assertTrue(result[0]['metric'] == 'b1.b1.b1')
        self.assertTrue(result[1]['metric'] == 'b1.b1.b2')
        result = list(self.index.query('b1.b1.*.*'))
        self.assertTrue(len(result) == 3)
        self.assertTrue(result[0]['metric'] == 'b1.b1.b1.b1')
        self.assertTrue(result[1]['metric'] == 'b1.b1.b1.b2')
        self.assertTrue(result[2]['metric'] == 'b1.b1.b2.b2')
        result = list(self.index.query('b1.b1.*.*.*'))
        self.assertTrue(len(result) == 6)
        self.assertTrue(result[0]['metric'] == 'b1.b1.b1.b1.leaf1')
        self.assertTrue(result[1]['metric'] == 'b1.b1.b1.b1.leaf2')
        self.assertTrue(result[2]['metric'] == 'b1.b1.b1.b2.leaf1')
        self.assertTrue(result[3]['metric'] == 'b1.b1.b1.b2.leaf2')
        self.assertTrue(result[4]['metric'] == 'b1.b1.b2.b2.leaf1')
        self.assertTrue(result[5]['metric'] == 'b1.b1.b2.b2.leaf2')
        result = list(self.index.query('b1.b1.*.*.{leaf1,leaf2}'))
        self.assertTrue(len(result) == 6)
        self.assertTrue(result[0]['metric'] == 'b1.b1.b1.b1.leaf1')
        self.assertTrue(result[1]['metric'] == 'b1.b1.b1.b1.leaf2')
        self.assertTrue(result[2]['metric'] == 'b1.b1.b1.b2.leaf1')
        self.assertTrue(result[3]['metric'] == 'b1.b1.b1.b2.leaf2')
        self.assertTrue(result[4]['metric'] == 'b1.b1.b2.b2.leaf1')
        self.assertTrue(result[5]['metric'] == 'b1.b1.b2.b2.leaf2')
        result = list(self.index.query('b1.b1.b1.b1.leaf1'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0]['metric'] == 'b1.b1.b1.b1.leaf1')
        result = list(self.index.query('fakey*'))
        self.assertFalse(result)

    def test_to_from_array(self):
        index2 = NodeTreeIndex.from_array(self.index.to_array())
        self.assertEqual(index2.to_array(), self.index.to_array())
        self.assertEqual(list(self.index.query('*')), list(index2.query('*')))
Esempio n. 6
0
 def test_to_from_array(self):
     index2 = NodeTreeIndex.from_array(self.index.to_array())
     self.assertEqual(index2.to_array(), self.index.to_array())
     self.assertEqual([path for (path, _) in self.index.query('*')],
                      [path for (path, _) in index2.query('*')])
Esempio n. 7
0
class IndexTreeTestCase(unittest.TestCase):

    def setUp(self):
        all_series = ['b1.b1.b1.b1.leaf1',
                      'b1.b1.b1.b2.leaf1',
                      'b1.b1.b2.b2.leaf1',
                      'b1.b1.b1.b1.leaf2',
                      'b1.b1.b1.b2.leaf2',
                      'b1.b1.b2.b2.leaf2'
                      ]
        self.index = NodeTreeIndex()
        for serie in all_series:
            self.index.insert(serie)

    def test_root_wildcard(self):
        result = list(self.index.query('*'))
        self.assertTrue(len(result) == 1)
        # Unicode query test
        result = list(self.index.query(u'*'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0][0] == 'b1')
        result = list(self.index.query('b1'))
        self.assertTrue(result[0][0] == 'b1')
        result = list(self.index.query('b1.*'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0][0] == 'b1.b1')
        result = list(self.index.query('b1.b1.*'))
        self.assertTrue(len(result) == 2)
        self.assertTrue(result[0][0] == 'b1.b1.b1')
        self.assertTrue(result[1][0] == 'b1.b1.b2')
        result = list(self.index.query('b1.b1.*.*'))
        self.assertTrue(len(result) == 3)
        self.assertTrue(result[0][0] == 'b1.b1.b1.b1')
        self.assertTrue(result[1][0] == 'b1.b1.b1.b2')
        self.assertTrue(result[2][0] == 'b1.b1.b2.b2')
        result = list(self.index.query('b1.b1.*.*.*'))
        self.assertTrue(len(result) == 6)
        self.assertTrue(result[0][0] == 'b1.b1.b1.b1.leaf1')
        self.assertTrue(result[1][0] == 'b1.b1.b1.b1.leaf2')
        self.assertTrue(result[2][0] == 'b1.b1.b1.b2.leaf1')
        self.assertTrue(result[3][0] == 'b1.b1.b1.b2.leaf2')
        self.assertTrue(result[4][0] == 'b1.b1.b2.b2.leaf1')
        self.assertTrue(result[5][0] == 'b1.b1.b2.b2.leaf2')
        result = list(self.index.query('b1.b1.*.*.{leaf1,leaf2}'))
        self.assertTrue(len(result) == 6)
        self.assertTrue(result[0][0] == 'b1.b1.b1.b1.leaf1')
        self.assertTrue(result[1][0] == 'b1.b1.b1.b1.leaf2')
        self.assertTrue(result[2][0] == 'b1.b1.b1.b2.leaf1')
        self.assertTrue(result[3][0] == 'b1.b1.b1.b2.leaf2')
        self.assertTrue(result[4][0] == 'b1.b1.b2.b2.leaf1')
        self.assertTrue(result[5][0] == 'b1.b1.b2.b2.leaf2')
        result = list(self.index.query('b1.b1.b1.b1.leaf1'))
        self.assertTrue(len(result) == 1)
        self.assertTrue(result[0][0] == 'b1.b1.b1.b1.leaf1')
        result = list(self.index.query('fakey*'))
        self.assertFalse(result)

    def test_to_from_array(self):
        index2 = NodeTreeIndex.from_array(self.index.to_array())
        self.assertEqual(index2.to_array(), self.index.to_array())
        self.assertEqual([path for (path, _) in self.index.query('*')],
                         [path for (path, _) in index2.query('*')])