Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
neoppod
Commits
2553b1c9
Commit
2553b1c9
authored
Aug 26, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: remove useless calls to time.time()
parent
b70de293
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
23 deletions
+22
-23
neo/client/pool.py
neo/client/pool.py
+7
-15
neo/tests/client/testConnectionPool.py
neo/tests/client/testConnectionPool.py
+13
-6
neo/tests/threaded/__init__.py
neo/tests/threaded/__init__.py
+2
-2
No files found.
neo/client/pool.py
View file @
2553b1c9
...
@@ -95,25 +95,17 @@ class ConnectionPool(object):
...
@@ -95,25 +95,17 @@ class ConnectionPool(object):
@
profiler_decorator
@
profiler_decorator
def
notifyFailure
(
self
,
node
):
def
notifyFailure
(
self
,
node
):
self
.
_notifyFailure
(
node
.
getUUID
(),
time
.
time
()
+
MAX_FAILURE_AGE
)
self
.
node_failure_dict
[
node
.
getUUID
()]
=
time
.
time
()
+
MAX_FAILURE_AGE
def
_notifyFailure
(
self
,
uuid
,
at
):
self
.
node_failure_dict
[
uuid
]
=
at
@
profiler_decorator
@
profiler_decorator
def
getCellSortKey
(
self
,
cell
):
def
getCellSortKey
(
self
,
cell
):
return
self
.
_getCellSortKey
(
cell
.
getUUID
(),
time
.
time
())
uuid
=
cell
.
getUUID
()
def
_getCellSortKey
(
self
,
uuid
,
now
):
if
uuid
in
self
.
connection_dict
:
if
uuid
in
self
.
connection_dict
:
result
=
CELL_CONNECTED
return
CELL_CONNECTED
else
:
failure
=
self
.
node_failure_dict
.
get
(
uuid
)
failure
=
self
.
node_failure_dict
.
get
(
uuid
)
if
failure
is
None
or
failure
<
time
.
time
():
if
failure
is
None
or
failure
<
now
:
return
CELL_GOOD
result
=
CELL_GOOD
return
CELL_FAILED
else
:
result
=
CELL_FAILED
return
result
@
profiler_decorator
@
profiler_decorator
def
getConnForCell
(
self
,
cell
):
def
getConnForCell
(
self
,
cell
):
...
...
neo/tests/client/testConnectionPool.py
View file @
2553b1c9
...
@@ -14,12 +14,13 @@
...
@@ -14,12 +14,13 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
unittest
import
time
,
unittest
from
mock
import
Mock
,
ReturnValues
from
mock
import
Mock
,
ReturnValues
from
..
import
NeoUnitTestBase
from
..
import
NeoUnitTestBase
from
neo.client.app
import
ConnectionPool
from
neo.client.app
import
ConnectionPool
from
neo.client.exception
import
NEOStorageError
from
neo.client.exception
import
NEOStorageError
from
neo.client
import
pool
class
ConnectionPoolTests
(
NeoUnitTestBase
):
class
ConnectionPoolTests
(
NeoUnitTestBase
):
...
@@ -47,16 +48,22 @@ class ConnectionPoolTests(NeoUnitTestBase):
...
@@ -47,16 +48,22 @@ class ConnectionPoolTests(NeoUnitTestBase):
# TODO: test getConnForNode (requires splitting complex functionalities)
# TODO: test getConnForNode (requires splitting complex functionalities)
def
test_CellSortKey
(
self
):
def
test_CellSortKey
(
self
):
pool
=
ConnectionPool
(
None
)
cp
=
ConnectionPool
(
None
)
node_uuid_1
=
self
.
getStorageUUID
()
node_uuid_1
=
self
.
getStorageUUID
()
node_uuid_2
=
self
.
getStorageUUID
()
node_uuid_2
=
self
.
getStorageUUID
()
node_uuid_3
=
self
.
getStorageUUID
()
node_uuid_3
=
self
.
getStorageUUID
()
# We are connected to node 1
# We are connected to node 1
pool
.
connection_dict
[
node_uuid_1
]
=
None
cp
.
connection_dict
[
node_uuid_1
]
=
None
def
uuid_now
(
func
,
uuid
,
now
):
pool
.
time
=
Mock
({
'time'
:
now
})
try
:
return
func
(
Mock
({
'getUUID'
:
uuid
}))
finally
:
pool
.
time
=
time
# A connection to node 3 failed, will be forgotten at 5
# A connection to node 3 failed, will be forgotten at 5
pool
.
_notifyFailure
(
node_uuid_3
,
5
)
uuid_now
(
cp
.
notifyFailure
,
node_uuid_3
,
5
-
pool
.
MAX_FAILURE_AGE
)
getCellSortKey
=
pool
.
_getCellSortKey
def
getCellSortKey
(
*
args
):
return
uuid_now
(
cp
.
getCellSortKey
,
*
args
)
# At 0, key values are not ambiguous
# At 0, key values are not ambiguous
self
.
assertTrue
(
getCellSortKey
(
node_uuid_1
,
0
)
<
getCellSortKey
(
self
.
assertTrue
(
getCellSortKey
(
node_uuid_1
,
0
)
<
getCellSortKey
(
node_uuid_2
,
0
)
<
getCellSortKey
(
node_uuid_3
,
0
))
node_uuid_2
,
0
)
<
getCellSortKey
(
node_uuid_3
,
0
))
...
...
neo/tests/threaded/__init__.py
View file @
2553b1c9
...
@@ -743,8 +743,8 @@ class NEOCluster(object):
...
@@ -743,8 +743,8 @@ class NEOCluster(object):
raise
raise
def
extraCellSortKey
(
self
,
key
):
def
extraCellSortKey
(
self
,
key
):
return
Patch
(
self
.
client
.
cp
,
_getCellSortKey
=
lambda
orig
,
*
args
:
return
Patch
(
self
.
client
.
cp
,
getCellSortKey
=
lambda
orig
,
cell
:
(
orig
(
*
args
),
key
(
*
args
)))
(
orig
(
cell
),
key
(
cell
)))
class
NEOThreadedTest
(
NeoTestBase
):
class
NEOThreadedTest
(
NeoTestBase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment