Commit 61abdcd9 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove getQueue() method because the queue intialization can be done in

ThreadContext. Update tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@548 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 972ef850
...@@ -86,7 +86,7 @@ class ConnectionPool(object): ...@@ -86,7 +86,7 @@ class ConnectionPool(object):
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
app.uuid, addr[0], addr[1], app.name) app.uuid, addr[0], addr[1], app.name)
msg_id = conn.ask(p) msg_id = conn.ask(p)
app.dispatcher.register(conn, msg_id, app.getQueue()) app.dispatcher.register(conn, msg_id, app.local_var.queue)
finally: finally:
conn.unlock() conn.unlock()
...@@ -208,6 +208,7 @@ class ThreadContext(object): ...@@ -208,6 +208,7 @@ class ThreadContext(object):
'object_stored': 0, 'object_stored': 0,
'txn_voted': False, 'txn_voted': False,
'txn_finished': False, 'txn_finished': False,
'queue': Queue(5),
} }
...@@ -274,16 +275,9 @@ class Application(object): ...@@ -274,16 +275,9 @@ class Application(object):
if self.uuid == INVALID_UUID: if self.uuid == INVALID_UUID:
raise NEOStorageError('No UUID given from the primary master') raise NEOStorageError('No UUID given from the primary master')
def getQueue(self):
try:
return self.local_var.queue
except AttributeError:
self.local_var.queue = Queue(5)
return self.local_var.queue
def _waitMessage(self, target_conn = None, msg_id = None, handler=None): def _waitMessage(self, target_conn = None, msg_id = None, handler=None):
"""Wait for a message returned by the dispatcher in queues.""" """Wait for a message returned by the dispatcher in queues."""
local_queue = self.getQueue() local_queue = self.local_var.queue
while 1: while 1:
try: try:
...@@ -307,7 +301,7 @@ class Application(object): ...@@ -307,7 +301,7 @@ class Application(object):
""" Send a request to a storage node and process it's answer """ """ Send a request to a storage node and process it's answer """
try: try:
msg_id = conn.ask(packet, timeout, additional_timeout) msg_id = conn.ask(packet, timeout, additional_timeout)
self.dispatcher.register(conn, msg_id, self.getQueue()) self.dispatcher.register(conn, msg_id, self.local_var.queue)
finally: finally:
# assume that the connection was already locked # assume that the connection was already locked
conn.unlock() conn.unlock()
...@@ -321,7 +315,7 @@ class Application(object): ...@@ -321,7 +315,7 @@ class Application(object):
conn.lock() conn.lock()
try: try:
msg_id = conn.ask(packet, timeout, additional_timeout) msg_id = conn.ask(packet, timeout, additional_timeout)
self.dispatcher.register(conn, msg_id, self.getQueue()) self.dispatcher.register(conn, msg_id, self.local_var.queue)
finally: finally:
conn.unlock() conn.unlock()
self._waitMessage(conn, msg_id, self.primary_handler) self._waitMessage(conn, msg_id, self.primary_handler)
...@@ -729,7 +723,7 @@ class Application(object): ...@@ -729,7 +723,7 @@ class Application(object):
try: try:
p = protocol.askTIDs(first, last, INVALID_PARTITION) p = protocol.askTIDs(first, last, INVALID_PARTITION)
msg_id = conn.ask(p) msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue()) self.dispatcher.register(conn, msg_id, self.local_var.queue)
finally: finally:
conn.unlock() conn.unlock()
...@@ -919,7 +913,7 @@ class Application(object): ...@@ -919,7 +913,7 @@ class Application(object):
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
self.uuid, '0.0.0.0', 0, self.name) self.uuid, '0.0.0.0', 0, self.name)
msg_id = conn.ask(p) msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue()) self.dispatcher.register(conn, msg_id, self.local_var.queue)
finally: finally:
conn.unlock() conn.unlock()
......
...@@ -147,19 +147,18 @@ class ClientApplicationTest(NeoTestBase): ...@@ -147,19 +147,18 @@ class ClientApplicationTest(NeoTestBase):
# common checks # common checks
def checkDispatcherRegisterCalled(self, app, conn): def checkDispatcherRegisterCalled(self, app, conn):
from Queue import Queue
calls = app.dispatcher.mockGetNamedCalls('register') calls = app.dispatcher.mockGetNamedCalls('register')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(conn, None, app.local_var.queue) #self.assertEquals(calls[0].getParam(0), conn)
self.assertTrue(isinstance(calls[0].getParam(2), Queue))
def test_getQueue(self): def test_getQueue(self):
app = self.getApp() app = self.getApp()
# Test sanity check # Test sanity check
self.assertTrue(getattr(app, 'local_var', None) is not None) self.assertTrue(getattr(app, 'local_var', None) is not None)
# Test that queue is created if it does not exist in local_var # Test that queue is created
self.assertTrue(getattr(app.local_var, 'queue', None) is None) self.assertTrue(getattr(app.local_var, 'queue', None) is not None)
queue = app.getQueue()
# Test sanity check
self.assertTrue(getattr(app.local_var, 'queue', None) is queue)
def test_registerDB(self): def test_registerDB(self):
app = self.getApp() app = self.getApp()
......
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