Merge "Add timestamp checking in AccountBroker.is_status_deleted"

This commit is contained in:
Jenkins 2014-08-15 17:31:41 +00:00 committed by Gerrit Code Review
commit 9de6b3e33a
2 changed files with 18 additions and 2 deletions

View File

@ -312,9 +312,10 @@ class AccountBroker(DatabaseBroker):
"""Only returns true if the status field is set to DELETED."""
with self.get() as conn:
row = conn.execute('''
SELECT status
SELECT put_timestamp, delete_timestamp, status
FROM account_stat''').fetchone()
return (row['status'] == "DELETED")
return row['status'] == "DELETED" or (
row['delete_timestamp'] > row['put_timestamp'])
def get_policy_stats(self):
"""

View File

@ -91,6 +91,21 @@ class TestAccountBroker(unittest.TestCase):
POLICIES.default.idx)
self.assert_(broker.empty())
def test_is_status_deleted(self):
# Test AccountBroker.is_status_deleted
broker1 = AccountBroker(':memory:', account='a')
broker1.initialize(Timestamp(time()).internal)
self.assert_(not broker1.is_status_deleted())
broker1.delete_db(Timestamp(time()).internal)
self.assert_(broker1.is_status_deleted())
broker2 = AccountBroker(':memory:', account='a')
broker2.initialize(Timestamp(time()).internal)
# Set delete_timestamp greater than put_timestamp
broker2.merge_timestamps(
time(), Timestamp(time()).internal,
Timestamp(time() + 999).internal)
self.assert_(broker2.is_status_deleted())
def test_reclaim(self):
broker = AccountBroker(':memory:', account='test_account')
broker.initialize(Timestamp('1').internal)