'Test lock locking.'

@DBSubjectLockTest
def testDBSubjectLocks(self):

    predicate = u'metadata:predicate\xce\xf1\u0163\xe9r'
    subject = u'aff4:/metadata:row\xce\xf1\u0163\xe9r'
    with data_store.DB.DBSubjectLock(subject, lease_time=100, token=self.token):
        self.assertRaises(data_store.DBSubjectLockError, data_store.DB.DBSubjectLock, subject, lease_time=100, token=self.token)
        data_store.DB.Set(subject, predicate, '1', token=self.token)
    self.assertEqual(data_store.DB.Resolve(subject, predicate, token=self.token)[0], '1')
    t2 = data_store.DB.DBSubjectLock(subject, lease_time=100, token=self.token)
    self.assertRaises(data_store.DBSubjectLockError, data_store.DB.DBSubjectLock, subject, lease_time=100, token=self.token)
    t2.Release()
    t3 = data_store.DB.DBSubjectLock(subject, lease_time=100, token=self.token)
    self.assertTrue(t3.CheckLease())
    t3.Release()
