コード例 #1
0
ファイル: test_disklog.py プロジェクト: tarunsmalviya/smap
    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_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")
コード例 #3
0
ファイル: test_disklog.py プロジェクト: tarunsmalviya/smap
 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")
コード例 #4
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")
コード例 #5
0
ファイル: test_disklog.py プロジェクト: tarunsmalviya/smap
    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")
コード例 #6
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")
コード例 #7
0
ファイル: test_disklog.py プロジェクト: tarunsmalviya/smap
    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")
コード例 #8
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")