def test_log_more_up_to_date(self): """ Test figuring out which log is more up to date """ outofdate = WriteLog() uptodate = WriteLog() # Add some log records version = 0 for term in xrange(1, 5): for x in xrange(1, 10): version += 1 outofdate.append(version, term) uptodate.append(version, term) # Make sure they're greater/less equal to start self.assertEqual(uptodate, outofdate) self.assertGreaterEqual(uptodate, outofdate) self.assertLessEqual(outofdate, uptodate) # Make out of date more and more out of date. # To ensure both different terms and different lengths. while outofdate.lastApplied > 0: outofdate.truncate(outofdate.lastApplied) self.assertNotEqual(uptodate, outofdate) self.assertGreater(uptodate, outofdate) self.assertLess(outofdate, uptodate)
def test_log_empty(self): """ Test completely empty a log """ log = WriteLog() version = 0 for term in xrange(1, 5): for x in xrange(1, 10): version += 1 log.append(version, term) self.assertEqual(log.lastApplied, len(log) - 1) self.assertEqual(log.lastVersion, version) self.assertEqual(log.lastTerm, 4) log.truncate() self.assertEqual(log.lastApplied, 0) self.assertEqual(log.lastVersion, None) self.assertEqual(log.lastTerm, 0) self.assertEqual(log[0], NullEntry)
def test_log_truncate(self): """ Test truncating a write log """ log = WriteLog() version = 0 for term in xrange(1, 5): for x in xrange(1, 10): version += 1 log.append(version, term) self.assertEqual(log.lastApplied, len(log) - 1) self.assertEqual(log.lastVersion, version) self.assertEqual(log.lastTerm, 4) log.truncate(30) self.assertEqual(len(log), 30) self.assertEqual(log.lastApplied, len(log) - 1) self.assertEqual(log.lastVersion, version-7) self.assertEqual(log.lastTerm, 4)
def test_log_truncate(self): """ Test truncating a write log """ log = WriteLog() version = 0 for term in xrange(1, 5): for x in xrange(1, 10): version += 1 log.append(version, term) self.assertEqual(log.lastApplied, len(log) - 1) self.assertEqual(log.lastVersion, version) self.assertEqual(log.lastTerm, 4) log.truncate(30) self.assertEqual(len(log), 30) self.assertEqual(log.lastApplied, len(log) - 1) self.assertEqual(log.lastVersion, version - 7) self.assertEqual(log.lastTerm, 4)