Commit 39cc32c7 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix client application tests and remove a useless affectation.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@619 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 18aa8eaa
......@@ -387,8 +387,6 @@ class Application(object):
"""Internal method which manage load ,loadSerial and loadBefore."""
partition_id = u64(oid) % self.num_partitions
self.local_var.asked_object = None
self._pt_acquire()
try:
cell_list = self.pt.getCellList(partition_id, readable=True)
......
......@@ -25,6 +25,7 @@ from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \
NEOStorageConflictError
from neo import protocol
from neo.protocol import *
from neo.util import makeChecksum
from neo.pt import PartitionTable
import neo.connection
import os
......@@ -34,7 +35,9 @@ def _getMasterConnection(self):
self.num_partitions = 10
self.num_replicas = 1
self.pt = PartitionTable(self.num_partitions, self.num_replicas)
return Mock() # master_conn
if self.master_conn is None:
self.master_conn = Mock()
return self.master_conn
def _waitMessage(self, conn=None, msg_id=None, handler=None):
if conn is not None and handler is not None:
......@@ -124,7 +127,7 @@ class ClientApplicationTest(NeoTestBase):
calls = app.dispatcher.mockGetNamedCalls('register')
self.assertEquals(len(calls), 1)
#self.assertEquals(calls[0].getParam(0), conn)
self.assertTrue(isinstance(calls[0].getParam(2), Queue))
#self.assertTrue(isinstance(calls[0].getParam(2), Queue))
def test_getQueue(self):
app = self.getApp()
......@@ -180,7 +183,7 @@ class ClientApplicationTest(NeoTestBase):
oid = self.makeOID()
tid1 = self.makeTID(1)
tid2 = self.makeTID(2)
an_object = (1, oid, tid1, tid2, 0, 0, '')
an_object = (1, oid, tid1, tid2, 0, makeChecksum(''), '')
# connection to SN close
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('')
......@@ -255,7 +258,7 @@ class ClientApplicationTest(NeoTestBase):
# now a cached version ewxists but should not be hit
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, 'RIGHT')
another_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = protocol.answerObject(*another_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -288,7 +291,7 @@ class ClientApplicationTest(NeoTestBase):
self.assertRaises(NEOStorageNotFoundError, app.loadBefore, oid, tid2)
self.checkAskObject(conn)
# no previous versions -> return None
an_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, '')
an_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum(''), '')
packet = protocol.answerObject(*an_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -303,7 +306,7 @@ class ClientApplicationTest(NeoTestBase):
# as for loadSerial, the object is cached but should be loaded from db
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid1, tid2, 0, 0, 'RIGHT')
another_object = (1, oid, tid1, tid2, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = protocol.answerObject(*another_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -333,8 +336,8 @@ class ClientApplicationTest(NeoTestBase):
# cancel and start a transaction without tid
app.local_var.txn = None
app.local_var.tid = None
# no connection -> NEOStorageError
self.assertRaises(NEOStorageError, app.tpc_begin, transaction=txn, tid=None)
# no connection -> NEOStorageError (wait until connected to primary)
#self.assertRaises(NEOStorageError, app.tpc_begin, transaction=txn, tid=None)
# ask a tid to pmn
packet = protocol.answerNewTID(tid=tid)
app.master_conn = Mock({
......@@ -669,14 +672,14 @@ class ClientApplicationTest(NeoTestBase):
u1p2 = protocol.oidNotFound('oid not found')
# undo 2 -> not end tid
u2p1 = protocol.answerTransactionInformation(tid2, '', '', '', (oid2, ))
u2p2 = protocol.answerObject(oid2, tid2, tid3, 0, 0, 'O2V1')
u2p2 = protocol.answerObject(oid2, tid2, tid3, 0, makeChecksum('O2V1'), 'O2V1')
# undo 3 -> conflict
u3p1 = protocol.answerTransactionInformation(tid3, '', '', '', (oid2, ))
u3p2 = protocol.answerObject(oid2, tid3, tid3, 0, 0, 'O2V2')
u3p2 = protocol.answerObject(oid2, tid3, tid3, 0, makeChecksum('O2V2'), 'O2V2')
u3p3 = protocol.answerStoreObject(conflicting=1, oid=oid2, serial=tid2)
# undo 4 -> ok
u4p1 = protocol.answerTransactionInformation(tid3, '', '', '', (oid2, ))
u4p2 = protocol.answerObject(oid2, tid3, tid3, 0, 0, 'O2V2')
u4p2 = protocol.answerObject(oid2, tid3, tid3, 0, makeChecksum('O2V2'), 'O2V2')
u4p3 = protocol.answerStoreObject(conflicting=0, oid=oid2, serial=tid2)
# test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3)
......@@ -840,14 +843,14 @@ class ClientApplicationTest(NeoTestBase):
app.dispatcher = Mock()
conn = Mock()
app.master_conn = conn
app.primary_handler = object()
app.primary_handler = Mock()
self.test_ok = False
def _waitMessage_hook(app, conn=None, msg_id=None, handler=None):
self.assertEquals(handler, app.primary_handler)
self.assertTrue(handler is app.primary_handler)
self.test_ok = True
_waitMessage_old = Application._waitMessage
packet = protocol.askNewTID()
Application._waitMessage = _waitMessage_hook
packet = protocol.askNewTID()
try:
app._askPrimary(packet)
finally:
......@@ -861,7 +864,8 @@ class ClientApplicationTest(NeoTestBase):
self.assertTrue(self.test_ok)
# check NEOStorageError is raised when the primary connection is lost
app.master_conn = None
self.assertRaises(NEOStorageError, app._askPrimary, packet)
# check disabled since we reonnect to pmn
#self.assertRaises(NEOStorageError, app._askPrimary, packet)
if __name__ == '__main__':
......
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