def testLogLine(self): with harvesterLog(stateDir=self.stateDir, logDir=self.logDir, name= 'name') as logger: logger.startRepository() logger.notifyHarvestedRecord("name:uploadId1") logger.uploadIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId1") logger.deleteIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId2") logger.logInvalidData("name:uploadId2", "Test Exception") logger.logIgnoredIdentifierWarning("name:uploadId2") logger.endRepository(None, '2012-01-01T09:00:00Z') with open(self.stateDir + '/name.stats') as fp: lines = fp.readlines() with open(self.logDir + '/name.events') as fp: eventline = fp.readlines()[1].strip() with open(self.logDir + '/invalid/name/uploadId2') as fp: invalidUploadId2 = fp.read() #Total is now counted based upon the id's self.assertTrue('3/1/1/0, Done:' in lines[0], lines[0]) date, event, id, comments = LOGLINE_RE.match(eventline).groups() self.assertEqual('SUCCES', event.strip()) self.assertEqual('name', id) self.assertEqual('Harvested/Uploaded/Deleted/Total: 3/1/1/0, ResumptionToken: None', comments) self.assertEqual('Test Exception', invalidUploadId2)
def testLogLineError(self): logger = HarvesterLog(stateDir=self.stateDir, logDir=self.logDir, name='name') logger.startRepository() try: logger.notifyHarvestedRecord("name:uploadId1") logger.uploadIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId2") raise Exception('FATAL') except: exType, exValue, exTb = exc_info() logger.endWithException(exType, exValue, exTb) logger.close() lines = open(self.stateDir+'/name.stats').readlines() eventline = open(self.logDir+'/name.events').readlines()[0].strip() #Total is now counted based upon the id's self.assertTrue('2/1/0/1, Error: ' in lines[0], lines[0]) date,event,id,comments = LOGLINE_RE.match(eventline).groups() self.assertEquals('ERROR', event.strip()) self.assertEquals('name', id) self.assertTrue(comments.startswith('Traceback (most recent call last):|File "')) self.assertTrue('harvesterlogtest.py", line ' in comments) self.assertTrue(comments.endswith(', in testLogLineError raise Exception(\'FATAL\')|Exception: FATAL'))
def testLogLine(self): logger = HarvesterLog(stateDir=self.stateDir, logDir=self.logDir, name= 'name') logger.startRepository() logger.notifyHarvestedRecord("name:uploadId1") logger.uploadIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId1") logger.deleteIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId2") logger.logInvalidData("name:uploadId2", "Test Exception") logger.logIgnoredIdentifierWarning("name:uploadId2") logger.endRepository(None, '2012-01-01T09:00:00Z') logger.close() lines = open(self.stateDir + '/name.stats').readlines() eventline = open(self.logDir + '/name.events').readlines()[1].strip() invalidUploadId2 = open(self.logDir + '/invalid/name/uploadId2').read() #Total is now counted based upon the id's self.assertTrue('3/1/1/0, Done:' in lines[0], lines[0]) date, event, id, comments = LOGLINE_RE.match(eventline).groups() self.assertEquals('SUCCES', event.strip()) self.assertEquals('name', id) self.assertEquals('Harvested/Uploaded/Deleted/Total: 3/1/1/0, ResumptionToken: None', comments) self.assertEquals('Test Exception', invalidUploadId2)
def testLogLineError(self): with harvesterLog(stateDir=self.stateDir, logDir=self.logDir, name='name') as logger: logger.startRepository() try: logger.notifyHarvestedRecord("name:uploadId1") logger.uploadIdentifier("name:uploadId1") logger.notifyHarvestedRecord("name:uploadId2") raise Exception('FATAL') except: exType, exValue, exTb = exc_info() logger.endWithException(exType, exValue, exTb) with open(self.stateDir+'/name.stats') as fp: lines = fp.readlines() with open(self.logDir+'/name.events') as fp: eventline = fp.readlines()[0].strip() #Total is now counted based upon the id's self.assertTrue('2/1/0/1, Error: ' in lines[0], lines[0]) date,event,id,comments = LOGLINE_RE.match(eventline).groups() self.assertEqual('ERROR', event.strip()) self.assertEqual('name', id) self.assertTrue(comments.startswith('Traceback (most recent call last):|File "')) self.assertTrue('harvesterlogtest.py", line ' in comments) self.assertTrue(comments.endswith(', in testLogLineError raise Exception(\'FATAL\')|Exception: FATAL'))
def readLogLine(self): line = self.logfile.readline().strip() #[2005-08-24 14:08:14] SUCCES [] Comments match = LOGLINE_RE.match(line) return match.groups()