Exemplo n.º 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")
Exemplo n.º 2
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")
Exemplo n.º 3
0
    def test_trunc(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))

            for i in xrange(1, 10):
                dl.pop()
                self.assertEqual(dl.head(), "FOO " + str(i))
        finally:
            shutil.rmtree("testdir")
Exemplo n.º 4
0
    def test_trunc(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))

            for i in xrange(1, 10):
                dl.pop()
                self.assertEqual(dl.head(), "FOO " + str(i))
        finally:
            shutil.rmtree("testdir")
Exemplo n.º 5
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")
Exemplo n.º 6
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")
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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")
Exemplo n.º 10
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")