Пример #1
0
    def testSave(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
Пример #2
0
    def testSave(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
Пример #3
0
    def testRestore(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER | pytc.HDBOWRITER)
        try:
            db.out("__pool__")
        except:
            pass
        db.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER | pytc.HDBOWRITER)
        #assert db["__sync__"] == "1"
        try:
            db.out("__sync__")
        except:
            pass
        db.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
Пример #4
0
    def testRestore(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER|pytc.HDBOWRITER)
        try:
            db.out("__pool__")
        except:
            pass
        db.close()
        
        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
        
        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER|pytc.HDBOWRITER)
        #assert db["__sync__"] == "1"
        try:
            db.out("__sync__")
        except:
            pass
        db.close()
        
        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
Пример #5
0
    def testDepth(self):
        self.testSplit()
        h, c = self.htree.get_hash("@1")
        s = self.htree.list("1")

        t = HTree("tt.tch", 1)
        for key, ver, ha in [l.split(' ') for l in s.split("\n") if l]:
            t.add(key, int(ver), int(ha))
        self.assertEqual(len(t), c)
        self.assertEqual(hash(t), h)
        self.assertEqual(t.list(''), s)
        t.close()
        os.unlink('tt.tch')
Пример #6
0
    def testDepth(self):
        self.testSplit()
        h, c = self.htree.get_hash("@1")
        s = self.htree.list("1")

        t = HTree("tt.tch", 1)
        for key, ver, ha in [l.split(' ') for l in s.split("\n") if l]:
            t.add(key, int(ver), int(ha))
        self.assertEqual(len(t), c)
        self.assertEqual(hash(t), h)
        self.assertEqual(t.list(''), s)
        t.close()
        os.unlink('tt.tch')
Пример #7
0
 def setUp(self):
     self.htree = HTree("t.tch", 0)
     self.htree.clear()
Пример #8
0
class TestHTree(unittest.TestCase):
    def setUp(self):
        self.htree = HTree("t.tch", 0)
        self.htree.clear()

    def tearDown(self):
        self.htree.close()
        os.unlink("t.tch")

    def testEmpty(self):
        self.assertEqual(len(self.htree), 0)
        self.assertEqual(hash(self.htree), 0)
        self.assertEqual(self.htree.list(''), '')

    def testAdd(self):
        self.htree.add(TEST_KEY, TEST_VER, 3)
        self.assertEqual(len(self.htree), 1)
        self.assertEqual(hash(self.htree), TEST_HASH)
    
    def testRemove(self):
        self.htree.remove(TEST_KEY)
        self.testEmpty()
        
        self.testAdd()
        self.htree.remove(TEST_KEY)
        self.testEmpty()

    def testSplit(self):
        self.testAdd()
        for i in range(200):
            self.htree.add('a%d'%i, i, i, 0)
        self.assertEqual(len(self.htree), 201)
        self.assertEqual(hash(self.htree), 53137)

    def testMerge(self):
        self.testSplit()

        for i in range(200):
            self.htree.remove('a%d'%i)
        self.assertEqual(len(self.htree), 1)
        self.assertEqual(hash(self.htree), TEST_HASH)

    def testList(self):
        self.testAdd()
        self.testAdd()
        l = "%s %d %d\n" % (TEST_KEY, 3, TEST_VER)
        self.assertEqual(self.htree.list(''), l)

        self.testSplit()
        self.assertEqual(len(self.htree.list('').split('\n')), 17)

    def testPerformance(self):
        st = time.time()
        for i in range(200000):
            self.htree.add('key%d'%i, i, 0, False)
        t = time.time() - st
        self.assertEqual(t<1, True)
        self.htree.flush()
        st = time.time()
        for i in range(200000):
            self.htree.add('key%d'%i, i, 0, False)
        t = time.time() - st
        self.assertEqual(t<1, True)

    def testClear(self):
        self.testSplit()
        self.htree.clear()
        self.testEmpty()

    def testSave(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

    def testRestore(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER|pytc.HDBOWRITER)
        try:
            db.out("__pool__")
        except:
            pass
        db.close()
        
        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()
        
        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER|pytc.HDBOWRITER)
        #assert db["__sync__"] == "1"
        try:
            db.out("__sync__")
        except:
            pass
        db.close()
        
        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

    def testGetHash(self):
        self.testSplit()
        h, c = self.htree.get_hash("@")
        assert h == hash(self.htree)
        assert c == len(self.htree)

        h, ver = self.htree.get_hash(TEST_KEY)
        assert h == 3
        assert ver == TEST_VER

    def testDepth(self):
        self.testSplit()
        h, c = self.htree.get_hash("@1")
        s = self.htree.list("1")

        t = HTree("tt.tch", 1)
        for key, ver, ha in [l.split(' ') for l in s.split("\n") if l]:
            t.add(key, int(ver), int(ha))
        self.assertEqual(len(t), c)
        self.assertEqual(hash(t), h)
        self.assertEqual(t.list(''), s)
        t.close()
        os.unlink('tt.tch')
Пример #9
0
 def setUp(self):
     self.htree = HTree("t.tch", 0)
     self.htree.clear()
Пример #10
0
class TestHTree(unittest.TestCase):
    def setUp(self):
        self.htree = HTree("t.tch", 0)
        self.htree.clear()

    def tearDown(self):
        self.htree.close()
        os.unlink("t.tch")

    def testEmpty(self):
        self.assertEqual(len(self.htree), 0)
        self.assertEqual(hash(self.htree), 0)
        self.assertEqual(self.htree.list(''), '')

    def testAdd(self):
        self.htree.add(TEST_KEY, TEST_VER, 3)
        self.assertEqual(len(self.htree), 1)
        self.assertEqual(hash(self.htree), TEST_HASH)

    def testRemove(self):
        self.htree.remove(TEST_KEY)
        self.testEmpty()

        self.testAdd()
        self.htree.remove(TEST_KEY)
        self.testEmpty()

    def testSplit(self):
        self.testAdd()
        for i in range(200):
            self.htree.add('a%d' % i, i, i, 0)
        self.assertEqual(len(self.htree), 201)
        self.assertEqual(hash(self.htree), 53137)

    def testMerge(self):
        self.testSplit()

        for i in range(200):
            self.htree.remove('a%d' % i)
        self.assertEqual(len(self.htree), 1)
        self.assertEqual(hash(self.htree), TEST_HASH)

    def testList(self):
        self.testAdd()
        self.testAdd()
        l = "%s %d %d\n" % (TEST_KEY, 3, TEST_VER)
        self.assertEqual(self.htree.list(''), l)

        self.testSplit()
        self.assertEqual(len(self.htree.list('').split('\n')), 17)

    def testPerformance(self):
        st = time.time()
        for i in range(200000):
            self.htree.add('key%d' % i, i, 0, False)
        t = time.time() - st
        self.assertEqual(t < 1, True)
        self.htree.flush()
        st = time.time()
        for i in range(200000):
            self.htree.add('key%d' % i, i, 0, False)
        t = time.time() - st
        self.assertEqual(t < 1, True)

    def testClear(self):
        self.testSplit()
        self.htree.clear()
        self.testEmpty()

    def testSave(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

    def testRestore(self):
        self.testSplit()
        path = self.htree.path
        l = len(self.htree)
        h = hash(self.htree)
        self.htree.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER | pytc.HDBOWRITER)
        try:
            db.out("__pool__")
        except:
            pass
        db.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

        import pytc
        db = pytc.HDB()
        db.open(path, pytc.HDBOREADER | pytc.HDBOWRITER)
        #assert db["__sync__"] == "1"
        try:
            db.out("__sync__")
        except:
            pass
        db.close()

        t = HTree(path, 0)
        self.assertEqual(len(t), l)
        self.assertEqual(hash(t), h)
        t.close()

    def testGetHash(self):
        self.testSplit()
        h, c = self.htree.get_hash("@")
        assert h == hash(self.htree)
        assert c == len(self.htree)

        h, ver = self.htree.get_hash(TEST_KEY)
        assert h == 3
        assert ver == TEST_VER

    def testDepth(self):
        self.testSplit()
        h, c = self.htree.get_hash("@1")
        s = self.htree.list("1")

        t = HTree("tt.tch", 1)
        for key, ver, ha in [l.split(' ') for l in s.split("\n") if l]:
            t.add(key, int(ver), int(ha))
        self.assertEqual(len(t), c)
        self.assertEqual(hash(t), h)
        self.assertEqual(t.list(''), s)
        t.close()
        os.unlink('tt.tch')