def test_gettablelocks(self): stdout = ''' There is 1 table lock Table LockID Process PID Session Txn CreationTime State DBRoots test.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(len(reslt['locks']), 1) self.assertEqual(reslt['locks'][0]['Table'], 'test.foo') self.assertEqual(reslt['locks'][0]['LockID'], '15949') self.assertEqual(reslt['locks'][0]['Process'], 'DMLProc') self.assertEqual(reslt['locks'][0]['PID'], '17916') self.assertEqual(reslt['locks'][0]['Session'], '14029') self.assertEqual(reslt['locks'][0]['Txn'], '340729') self.assertEqual(reslt['locks'][0]['CreationTime'], 'Sun Mar 23 20:45:41 2014') self.assertEqual(reslt['locks'][0]['State'], 'LOADING') self.assertEqual(reslt['locks'][0]['DBRoots'], '1,2,3,4,5,6') stdout = ''' There is 1 table lock Table LockID Process PID Session Txn CreationTime State DBRoots longertable.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(reslt['locks'][0]['Table'], 'longertable.foo') self.assertEqual(reslt['locks'][0]['LockID'], '15949')
def test_gettablelocks_neg(self): # try out a case where the columns have changed or are screwed up stdout = ''' There is 1 table lock Table LockBad Process PID Session Txn CreationTime State DBRoots test.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(reslt['locks'][0]['CreationTime'], 'Sun Mar 23 20:45:41 2014') self.assertEqual(reslt['locks'][0]['LockID'], '') # first column messed up - this shouldn't parse as a lock stdout = ''' There is 1 table lock BadTable LockID Process PID Session Txn CreationTime State DBRoots test.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(len(reslt['locks']),0) # last column messed up stdout = ''' There is 1 table lock Table LockID Process PID Session Txn CreationTime State FooRoots test.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(reslt['locks'][0]['CreationTime'], 'Sun Mar 23 20:45:41 2014') # this case is a strange but without the column header to rely on we include additional text self.assertEqual(reslt['locks'][0]['State'], 'LOADING 1,2,3,4,5,6') self.assertEqual(reslt['locks'][0]['DBRoots'], '') # multiple columns messed up stdout = ''' There is 1 table lock Table LockID Process XID Fession Txn CreationTime State DBRoots test.foo 15949 DMLProc 17916 14029 340729 Sun Mar 23 20:45:41 2014 LOADING 1,2,3,4,5,6 ''' reslt = console.gettablelocks(stdout) self.assertEqual(reslt['locks'][0]['CreationTime'], 'Sun Mar 23 20:45:41 2014') # this case is a strange but without the column header to rely on we include additional text self.assertEqual(reslt['locks'][0]['Process'], 'DMLProc 17916 14029') self.assertEqual(reslt['locks'][0]['State'], 'LOADING') self.assertEqual(reslt['locks'][0]['DBRoots'], '1,2,3,4,5,6')