Commit 91ec53b9 authored by Grégory Wisniewski's avatar Grégory Wisniewski

ConnectionPool iterator raise if there is no storage available.

Remove 'else' sections of 'for' loops from app.
(and the one in checkCurrentSerialInTransaction was broken)

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2579 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent faf121b5
...@@ -647,8 +647,6 @@ class Application(object): ...@@ -647,8 +647,6 @@ class Application(object):
self.local_var.asked_object = -1 self.local_var.asked_object = -1
continue continue
break break
else:
raise NEOStorageError('no storage available')
if self.local_var.asked_object == -1: if self.local_var.asked_object == -1:
raise NEOStorageError('inconsistent data') raise NEOStorageError('inconsistent data')
...@@ -1307,8 +1305,6 @@ class Application(object): ...@@ -1307,8 +1305,6 @@ class Application(object):
conn.ask(packet, queue=queue) conn.ask(packet, queue=queue)
except ConnectionClosed: except ConnectionClosed:
continue continue
else:
raise NEOStorageError('no storage available')
self._waitAnyMessage(False) self._waitAnyMessage(False)
...@@ -148,6 +148,7 @@ class ConnectionPool(object): ...@@ -148,6 +148,7 @@ class ConnectionPool(object):
""" Iterate over nodes responsible of a object by it's ID """ """ Iterate over nodes responsible of a object by it's ID """
pt = self.app.getPartitionTable() pt = self.app.getPartitionTable()
cell_list = pt.getCellListForOID(object_id, readable, writable) cell_list = pt.getCellListForOID(object_id, readable, writable)
yielded = 0
if cell_list: if cell_list:
shuffle(cell_list) shuffle(cell_list)
cell_list.sort(key=self.getCellSortKey) cell_list.sort(key=self.getCellSortKey)
...@@ -156,7 +157,10 @@ class ConnectionPool(object): ...@@ -156,7 +157,10 @@ class ConnectionPool(object):
node = cell.getNode() node = cell.getNode()
conn = getConnForNode(node, wait_ready=wait_ready) conn = getConnForNode(node, wait_ready=wait_ready)
if conn is not None: if conn is not None:
yielded += 1
yield (node, conn) yield (node, conn)
if not yielded:
raise NEOStorageError('no storage available')
@profiler_decorator @profiler_decorator
def getConnForNode(self, node, wait_ready=True): def getConnForNode(self, node, wait_ready=True):
......
...@@ -20,6 +20,7 @@ from mock import Mock ...@@ -20,6 +20,7 @@ from mock import Mock
from neo.tests import NeoUnitTestBase from neo.tests import NeoUnitTestBase
from neo.client.app import ConnectionPool from neo.client.app import ConnectionPool
from neo.client.exception import NEOStorageError
class ConnectionPoolTests(NeoUnitTestBase): class ConnectionPoolTests(NeoUnitTestBase):
...@@ -74,7 +75,7 @@ class ConnectionPoolTests(NeoUnitTestBase): ...@@ -74,7 +75,7 @@ class ConnectionPoolTests(NeoUnitTestBase):
pt = Mock({'getCellListForOID': []}) pt = Mock({'getCellListForOID': []})
app = Mock({'getPartitionTable': pt}) app = Mock({'getPartitionTable': pt})
pool = ConnectionPool(app) pool = ConnectionPool(app)
self.assertRaises(StopIteration, pool.iterateForObject(oid).next) self.assertRaises(NEOStorageError, pool.iterateForObject(oid).next)
def test_iterateForObject_connectionRefused(self): def test_iterateForObject_connectionRefused(self):
# connection refused # connection refused
......
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