示例#1
0
    def test_disappearing_logs(self):
        try:
            dl = DiskLog("testdir")
            for i in xrange(0, 10):
                dl.append(i)
            dl.sync()

            # head is cached even though we removed it
            os.remove("testdir/00000000")
            os.remove("testdir/00000001")
            self.assertEqual(dl.head(), 0)

            # this should cause it to notice that it's missing
            dl.pop()
            self.assertEqual(dl.head(), 2)

            # remove the rast of the logs
            for f in glob.glob("testdir/0000*"):
                os.remove(f)
            self.assertEqual(dl.head(), 2)
            dl.pop()
            # head was still in memory
            self.assertEqual(dl.head(), dl.tail())
            self.assertEqual(dl.head(), 9)
        finally:
            shutil.rmtree("testdir")
示例#2
0
 def test_big(self):
     try:
         dl = DiskLog("testdir")
         for i in xrange(0, 10):
             dl.append([i for i in xrange(0, 100000)])
     finally:
         shutil.rmtree("testdir")
    def test_disappearing_logs(self):
        try:
            dl = DiskLog("testdir")
            for i in xrange(0, 10):
                dl.append(i)
            dl.sync()

            # head is cached even though we removed it
            os.remove("testdir/00000000")
            os.remove("testdir/00000001")
            self.assertEqual(dl.head(), 0)

            # this should cause it to notice that it's missing
            dl.pop()
            self.assertEqual(dl.head(), 2)

            # remove the rast of the logs
            for f in glob.glob("testdir/0000*"):
                os.remove(f)
            self.assertEqual(dl.head(), 2)
            dl.pop()
            # head was still in memory
            self.assertEqual(dl.head(), dl.tail())
            self.assertEqual(dl.head(), 9)
        finally:
            shutil.rmtree("testdir")
 def test_big(self):
     try:
         dl = DiskLog("testdir")
         for i in xrange(0, 10):
             dl.append([i for i in xrange(0, 100000)])
     finally:
         shutil.rmtree("testdir")
 def test_1(self):
     try:
         dl = DiskLog("testdir")
         dl.append("FOO")
         self.assertEqual(dl.head(), "FOO")
         self.assertEqual(dl.tail(), "FOO")
     finally:
         shutil.rmtree("testdir")
示例#6
0
 def test_1(self):
     try:
         dl = DiskLog("testdir")
         dl.append("FOO")
         self.assertEqual(dl.head(), "FOO")
         self.assertEqual(dl.tail(), "FOO")
     finally:
         shutil.rmtree("testdir")
示例#7
0
 def test_append(self):
     try:
         dl = DiskLog("testdir")
         dl.append("FOO 0")
         for i in xrange(1, 10):
             self.assertEqual(dl.tail(), "FOO " + str(i - 1))
             self.assertEqual(dl.head(), "FOO 0")
             dl.append("FOO " + str(i))
     finally:
         shutil.rmtree("testdir")
 def test_append(self):
     try:
         dl = DiskLog("testdir")
         dl.append("FOO 0")
         for i in xrange(1, 10):
             self.assertEqual(dl.tail(), "FOO " + str(i-1))
             self.assertEqual(dl.head(), "FOO 0")
             dl.append("FOO " + str(i))
     finally:
         shutil.rmtree("testdir")
示例#9
0
    def test_corrupt_meta(self):
        try:
            d = DiskLog("testdir")
            d.append(1)
            d.close()

            del d
            with open("testdir/META", "w") as fp:
                print >> fp, "CORRUPT"

            d = DiskLog("testdir")
        finally:
            shutil.rmtree("testdir")
    def test_corrupt_meta(self):
        try:
            d = DiskLog("testdir")
            d.append(1)
            d.close()

            del d
            with open("testdir/META", "w") as fp:
                print >>fp, "CORRUPT"

            d = DiskLog("testdir")
        finally:
            shutil.rmtree("testdir")
示例#11
0
 def test_aging(self):
     try:
         max_age = datetime.timedelta(seconds=1)
         dl = DiskLog("testdir", max_age)
         for i in xrange(0, 10):
             dl.append(str(i))
         dl.sync()
         self.assertEqual(dl.head(), "0")
         time.sleep(2)
         dl.append("11")
         dl.sync()
         self.assertEqual(dl.head(), "11")
     finally:
         shutil.rmtree("testdir")
 def test_aging(self):
     try:
         max_age = datetime.timedelta(seconds=1)
         dl = DiskLog("testdir", max_age)
         for i in xrange(0, 10):
             dl.append(str(i))
         dl.sync()
         self.assertEqual(dl.head(), "0")
         time.sleep(2)
         dl.append("11")
         dl.sync()
         self.assertEqual(dl.head(), "11")
     finally:
         shutil.rmtree("testdir")
示例#13
0
 def test_pop(self):
     try:
         dl = DiskLog("testdir")
         dl.append("1")
         dl.append("2")
         self.assertEqual(dl.head(), "1")
         self.assertEqual(dl.tail(), "2")
         dl.pop()
         self.assertEqual(dl.head(), "2")
         self.assertEqual(dl.tail(), "2")
         dl.pop()
         self.assertEqual(dl.head(), None)
         self.assertEqual(dl.tail(), None)
     finally:
         shutil.rmtree("testdir")
 def test_pop(self):
     try:
         dl = DiskLog("testdir")
         dl.append("1")
         dl.append("2")
         self.assertEqual(dl.head(), "1")
         self.assertEqual(dl.tail(), "2")
         dl.pop()
         self.assertEqual(dl.head(), "2")
         self.assertEqual(dl.tail(), "2")
         dl.pop()
         self.assertEqual(dl.head(), None)
         self.assertEqual(dl.tail(), None)
     finally:
         shutil.rmtree("testdir")
 def test_trunc_split(self):
     try:
         dl = DiskLog("testdir")
         dl.append("FOO 0")
         for i in xrange(1, 10):
             self.assertEqual(dl.tail(), "FOO " + str(i-1))
             self.assertEqual(dl.head(), "FOO 0")
             dl.append("FOO " + str(i))
         dl.sync()
             
         dl2 = DiskLog("testdir")
         for i in xrange(1, 10):
             dl2.pop()
             self.assertEqual(dl2.head(), "FOO " + str(i))
     finally:
         shutil.rmtree("testdir")
    def test_unwritable_file(self):
        try:
            d = DiskLog("testdir")
            os.chmod(os.path.abspath("testdir"), 0000)
            d.append(1)
            d.append(2)
            d.append(3)

            # we should drop the middle write, because we can't sync
            # to disk.  head and tail are in memory.
            self.assertEqual(d.head(), 1); d.pop()
            self.assertEqual(d.head(), 3)
            
            del d
        except Exception, e:
            print e
示例#17
0
    def test_trunc_split(self):
        try:
            dl = DiskLog("testdir")
            dl.append("FOO 0")
            for i in xrange(1, 10):
                self.assertEqual(dl.tail(), "FOO " + str(i - 1))
                self.assertEqual(dl.head(), "FOO 0")
                dl.append("FOO " + str(i))
            dl.sync()

            dl2 = DiskLog("testdir")
            for i in xrange(1, 10):
                dl2.pop()
                self.assertEqual(dl2.head(), "FOO " + str(i))
        finally:
            shutil.rmtree("testdir")
示例#18
0
    def test_unwritable_file(self):
        try:
            d = DiskLog("testdir")
            os.chmod(os.path.abspath("testdir"), 0000)
            d.append(1)
            d.append(2)
            d.append(3)

            # we should drop the middle write, because we can't sync
            # to disk.  head and tail are in memory.
            self.assertEqual(d.head(), 1)
            d.pop()
            self.assertEqual(d.head(), 3)

            del d
        except Exception, e:
            print e
示例#19
0
    def test_edithead_2(self):
        try:
            dl = DiskLog("testdir")
            dl.append("FOO")
            self.assertEqual(dl.head(), "FOO")
            self.assertEqual(dl.tail(), "FOO")
            dl.append("FOO2")
            self.assertEqual(dl.tail(), "FOO2")
            dl.update_tail("FOO BAR")
            self.assertEqual(dl.tail(), "FOO BAR")

            dl.pop()
            self.assertEqual(dl.head(), "FOO BAR")
            self.assertEqual(dl.tail(), "FOO BAR")

        finally:
            shutil.rmtree("testdir")
    def test_edithead_2(self):
        try:
            dl = DiskLog("testdir")
            dl.append("FOO")
            self.assertEqual(dl.head(), "FOO")
            self.assertEqual(dl.tail(), "FOO")
            dl.append("FOO2")
            self.assertEqual(dl.tail(), "FOO2")
            dl.update_tail("FOO BAR")
            self.assertEqual(dl.tail(), "FOO BAR")

            dl.pop()
            self.assertEqual(dl.head(), "FOO BAR")
            self.assertEqual(dl.tail(), "FOO BAR")

        finally:
            shutil.rmtree("testdir")
    def test_disappearing_all(self):
        """Make sure we can hose all of the log files and still make
        progress"""
        try:
            dl = DiskLog("testdir")
            for i in xrange(0, 10):
                dl.append(i)
            dl.sync()
        finally:
            shutil.rmtree("testdir")

        map(os.remove, glob.glob("testdir/000*"))

        try:
            dl = DiskLog("testdir")
            self.assertEqual(dl.head(), None)
            for i in xrange(20, 30):
                dl.append(i)
            dl.sync()
            self.assertEqual(dl.head(), 20)
        finally:
            shutil.rmtree("testdir")
示例#22
0
    def test_disappearing_all(self):
        """Make sure we can hose all of the log files and still make
        progress"""
        try:
            dl = DiskLog("testdir")
            for i in xrange(0, 10):
                dl.append(i)
            dl.sync()
        finally:
            shutil.rmtree("testdir")

        map(os.remove, glob.glob("testdir/000*"))

        try:
            dl = DiskLog("testdir")
            self.assertEqual(dl.head(), None)
            for i in xrange(20, 30):
                dl.append(i)
            dl.sync()
            self.assertEqual(dl.head(), 20)
        finally:
            shutil.rmtree("testdir")