Commit 0baab33c authored by Vincent Pelletier's avatar Vincent Pelletier

Use ZERO_TID instead of None.

There is no strong reason to use None, and it makes code more complex.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2477 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 62ccef7f
......@@ -17,6 +17,7 @@
from time import time, gmtime
from struct import pack, unpack
from neo.protocol import ZERO_TID
from datetime import timedelta, datetime
from neo.util import dump
import neo
......@@ -175,13 +176,13 @@ class TransactionManager(object):
"""
Manage current transactions
"""
_last_tid = ZERO_TID
def __init__(self):
# tid -> transaction
self._tid_dict = {}
# node -> transactions mapping
self._node_dict = {}
self._last_tid = None
self._last_oid = None
def __getitem__(self, tid):
......@@ -234,7 +235,7 @@ class TransactionManager(object):
gmt.tm_min),
int((gmt.tm_sec % 60 + (tm - int(tm))) / SECOND_PER_TID_LOW)
))
if self._last_tid is not None and tid <= self._last_tid:
if tid <= self._last_tid:
tid = addTID(self._last_tid, 1)
self._last_tid = tid
return self._last_tid
......@@ -249,10 +250,7 @@ class TransactionManager(object):
"""
Set the last TID, keep the previous if lower
"""
if self._last_tid is None:
self._last_tid = tid
else:
self._last_tid = max(self._last_tid, tid)
self._last_tid = max(self._last_tid, tid)
def reset(self):
"""
......
......@@ -19,6 +19,7 @@ import unittest
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoUnitTestBase
from neo.protocol import ZERO_TID
from neo.master.transactions import Transaction, TransactionManager
from neo.master.transactions import packTID, unpackTID, addTID
......@@ -126,7 +127,7 @@ class testTransactionManager(NeoUnitTestBase):
def test_getNextTID(self):
txnman = TransactionManager()
# no previous TID
self.assertEqual(txnman.getLastTID(), None)
self.assertEqual(txnman.getLastTID(), ZERO_TID)
# first transaction
node1 = Mock({'__hash__': 1})
tid1 = txnman.begin()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment