def test_deletes_old_txlogs_within_quantity_limit(self): """Test that txnlogs old enough are deleted and are within the quantity limit given.""" now = datetime.datetime.utcnow() timestamp_limit = now - datetime.timedelta(days=7) # Old enough old_datetime = timestamp_limit quantity_limit = 2 txlogs = [ self.obj_factory.make_transaction_log(tx_id=1), self.obj_factory.make_transaction_log(tx_id=2, timestamp=old_datetime), self.obj_factory.make_transaction_log(tx_id=3), self.obj_factory.make_transaction_log(tx_id=4, timestamp=old_datetime), self.obj_factory.make_transaction_log(tx_id=5, timestamp=old_datetime), ] self.store.commit() removed = utils.delete_old_txlogs(self.obj_factory.sstore_name, timestamp_limit=timestamp_limit, quantity_limit=quantity_limit) self.store.rollback() # Shouldn't affect the deletion result txlist = utils.get_txn_recs(self.obj_factory.sstore_name, num_recs=len(txlogs), last_id=0) self.assertEqual(len(txlist), 3) self.assertEqual(removed, quantity_limit) ids = sorted(int(txdict['txn_id']) for txdict in txlist) self.assertEqual(ids, [1, 3, 5])
def test_maintains_newish_txlogs_when_purging(self): """Test that txnlogs not old enough are maintained, instead of being deleted.""" now = datetime.datetime.utcnow() limit_datetime = now - datetime.timedelta(days=7) # Not so old old_datetime = limit_datetime + datetime.timedelta(seconds=1) self.obj_factory.make_transaction_log(tx_id=1) self.obj_factory.make_transaction_log(tx_id=2, timestamp=old_datetime) self.obj_factory.make_transaction_log(tx_id=3) self.obj_factory.make_transaction_log(tx_id=4, timestamp=old_datetime) self.store.commit() removed = utils.delete_old_txlogs(self.obj_factory.sstore_name, timestamp_limit=limit_datetime) self.store.rollback() # Shouldn't affect the deletion result txlist = utils.get_txn_recs(self.obj_factory.sstore_name, num_recs=4, last_id=0) self.assertEqual(len(txlist), 4) self.assertEqual(removed, 0) ids = sorted(int(txdict['txn_id']) for txdict in txlist) self.assertEqual(ids, [1, 2, 3, 4])
def test_maintains_newish_txlogs_when_purging(self): """Test that txnlogs not old enough are maintained, instead of being deleted.""" now = datetime.datetime.utcnow() limit_datetime = now - datetime.timedelta(days=7) # Not so old old_datetime = limit_datetime + datetime.timedelta(seconds=1) self.obj_factory.make_transaction_log(tx_id=1) self.obj_factory.make_transaction_log(tx_id=2, timestamp=old_datetime) self.obj_factory.make_transaction_log(tx_id=3) self.obj_factory.make_transaction_log(tx_id=4, timestamp=old_datetime) self.store.commit() removed = utils.delete_old_txlogs(self.obj_factory.sstore_name, timestamp_limit=limit_datetime) self.store.rollback() # Shouldn't affect the deletion result txlist = utils.get_txn_recs( self.obj_factory.sstore_name, num_recs=4, last_id=0) self.assertEqual(len(txlist), 4) self.assertEqual(removed, 0) ids = sorted(int(txdict['txn_id']) for txdict in txlist) self.assertEqual(ids, [1, 2, 3, 4])
def test_deletes_old_txlogs_within_quantity_limit(self): """Test that txnlogs old enough are deleted and are within the quantity limit given.""" now = datetime.datetime.utcnow() timestamp_limit = now - datetime.timedelta(days=7) # Old enough old_datetime = timestamp_limit quantity_limit = 2 txlogs = [ self.obj_factory.make_transaction_log(tx_id=1), self.obj_factory.make_transaction_log( tx_id=2, timestamp=old_datetime), self.obj_factory.make_transaction_log(tx_id=3), self.obj_factory.make_transaction_log( tx_id=4, timestamp=old_datetime), self.obj_factory.make_transaction_log( tx_id=5, timestamp=old_datetime), ] self.store.commit() removed = utils.delete_old_txlogs(self.obj_factory.sstore_name, timestamp_limit=timestamp_limit, quantity_limit=quantity_limit) self.store.rollback() # Shouldn't affect the deletion result txlist = utils.get_txn_recs( self.obj_factory.sstore_name, num_recs=len(txlogs), last_id=0) self.assertEqual(len(txlist), 3) self.assertEqual(removed, quantity_limit) ids = sorted(int(txdict['txn_id']) for txdict in txlist) self.assertEqual(ids, [1, 3, 5])
def test_deletes_old_enough_txlogs(self): """Test that txnlogs old enough are deleted.""" now = datetime.datetime.utcnow() timestamp_limit = now - datetime.timedelta(days=7) # Old enough old_datetime = timestamp_limit txlogs = [ self.obj_factory.make_transaction_log(tx_id=1), self.obj_factory.make_transaction_log( tx_id=2, timestamp=old_datetime), self.obj_factory.make_transaction_log(tx_id=3), self.obj_factory.make_transaction_log( tx_id=4, timestamp=old_datetime), ] self.store.commit() removed = utils.delete_old_txlogs(timestamp_limit=timestamp_limit) self.store.rollback() # Shouldn't affect the deletion result txlist = utils.get_txn_recs(num_recs=len(txlogs), last_id=0) self.assertEqual(len(txlist), 2) self.assertEqual(removed, 2) ids = sorted(int(txdict['txn_id']) for txdict in txlist) self.assertEqual(ids, [1, 3])