Commit 7544eb06 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update tests affected with changes introduced with previous commit.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@482 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f11bafed
...@@ -19,11 +19,10 @@ import unittest ...@@ -19,11 +19,10 @@ import unittest
import logging import logging
from mock import Mock, ReturnValues, ReturnIterator from mock import Mock, ReturnValues, ReturnIterator
from ZODB.POSException import StorageTransactionError, UndoError, ConflictError from ZODB.POSException import StorageTransactionError, UndoError, ConflictError
from neo.protocol import INVALID_UUID, ERROR
from neo.client.app import Application from neo.client.app import Application
from neo.protocol import Packet
from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \ from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \
NEOStorageConflictError NEOStorageConflictError
from neo import protocol
from neo.protocol import * from neo.protocol import *
import neo.connection import neo.connection
import os import os
...@@ -123,8 +122,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -123,8 +122,7 @@ class ClientApplicationTest(unittest.TestCase):
if oid is None: if oid is None:
oid = self.makeOID() oid = self.makeOID()
obj = (oid, tid, 'DATA', '', app.local_var.txn) obj = (oid, tid, 'DATA', '', app.local_var.txn)
packet = Packet() packet = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
packet.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, }) conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, })
cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', }) cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', })
app.cp = Mock({ 'getConnForNode': conn}) app.cp = Mock({ 'getConnForNode': conn})
...@@ -134,8 +132,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -134,8 +132,7 @@ class ClientApplicationTest(unittest.TestCase):
def voteTransaction(self, app): def voteTransaction(self, app):
tid = app.local_var.tid tid = app.local_var.tid
txn = app.local_var.txn txn = app.local_var.txn
packet = Packet() packet = protocol.answerStoreTransaction(msg_id=1, tid=tid)
packet.answerStoreTransaction(msg_id=1, tid=tid)
conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, }) conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, })
cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', }) cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', })
app.pt = Mock({ 'getCellList': (cell, cell, ) }) app.pt = Mock({ 'getCellList': (cell, cell, ) })
...@@ -145,8 +142,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -145,8 +142,7 @@ class ClientApplicationTest(unittest.TestCase):
def finishTransaction(self, app): def finishTransaction(self, app):
txn = app.local_var.txn txn = app.local_var.txn
tid = app.local_var.tid tid = app.local_var.tid
packet = Packet() packet = protocol.notifyTransactionFinished(1, tid)
packet.notifyTransactionFinished(1, tid)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10010), 'getAddress': ('127.0.0.1', 10010),
...@@ -201,8 +197,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -201,8 +197,7 @@ class ClientApplicationTest(unittest.TestCase):
app = self.getApp() app = self.getApp()
test_msg_id = 50 test_msg_id = 50
test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
response_packet = Packet() response_packet = protocol.answerNewOIDs(test_msg_id, test_oid_list[:])
response_packet.answerNewOIDs(test_msg_id, test_oid_list[:])
app.master_conn = Mock({'getNextId': test_msg_id, 'addPacket': None, app.master_conn = Mock({'getNextId': test_msg_id, 'addPacket': None,
'expectMessage': None, 'lock': None, 'expectMessage': None, 'lock': None,
'unlock': None, 'unlock': None,
...@@ -242,8 +237,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -242,8 +237,7 @@ class ClientApplicationTest(unittest.TestCase):
an_object = (1, oid, tid1, tid2, 0, 0, '') an_object = (1, oid, tid1, tid2, 0, 0, '')
# object not found in NEO -> NEOStorageNotFoundError # object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = Packet() packet = protocol.oidNotFound(oid, '')
packet.oidNotFound(oid, '')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
...@@ -255,8 +249,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -255,8 +249,7 @@ class ClientApplicationTest(unittest.TestCase):
self.assertRaises(NEOStorageNotFoundError, app.load, oid) self.assertRaises(NEOStorageNotFoundError, app.load, oid)
self.checkPacketSent(conn, 1, ASK_OBJECT) self.checkPacketSent(conn, 1, ASK_OBJECT)
# object found on storage nodes and put in cache # object found on storage nodes and put in cache
packet = Packet() packet = protocol.answerObject(*an_object)
packet.answerObject(*an_object)
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -284,8 +277,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -284,8 +277,7 @@ class ClientApplicationTest(unittest.TestCase):
tid2 = self.makeTID(2) tid2 = self.makeTID(2)
# object not found in NEO -> NEOStorageNotFoundError # object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = Packet() packet = protocol.oidNotFound(oid, '')
packet.oidNotFound(oid, '')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
...@@ -301,9 +293,8 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -301,9 +293,8 @@ class ClientApplicationTest(unittest.TestCase):
# now a cached version ewxists but should not be hit # now a cached version ewxists but should not be hit
mq.store(oid, (tid1, 'WRONG')) mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq) self.assertTrue(oid in mq)
packet = Packet()
another_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, 'RIGHT') another_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, 'RIGHT')
packet.answerObject(*another_object) packet = protocol.answerObject(*another_object)
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -323,8 +314,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -323,8 +314,7 @@ class ClientApplicationTest(unittest.TestCase):
tid2 = self.makeTID(2) tid2 = self.makeTID(2)
# object not found in NEO -> NEOStorageNotFoundError # object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = Packet() packet = protocol.oidNotFound(oid, '')
packet.oidNotFound(oid, '')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
...@@ -337,8 +327,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -337,8 +327,7 @@ class ClientApplicationTest(unittest.TestCase):
self.checkPacketSent(conn, 1, ASK_OBJECT) self.checkPacketSent(conn, 1, ASK_OBJECT)
# no previous versions -> return None # no previous versions -> return None
an_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, '') an_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, '')
packet = Packet() packet = protocol.answerObject(*an_object)
packet.answerObject(*an_object)
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -353,8 +342,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -353,8 +342,7 @@ class ClientApplicationTest(unittest.TestCase):
mq.store(oid, (tid1, 'WRONG')) mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq) self.assertTrue(oid in mq)
another_object = (1, oid, tid1, tid2, 0, 0, 'RIGHT') another_object = (1, oid, tid1, tid2, 0, 0, 'RIGHT')
packet = Packet() packet = protocol.answerObject(*another_object)
packet.answerObject(*another_object)
conn = Mock({ conn = Mock({
'getServer': ('127.0.0.1', 0), 'getServer': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -386,8 +374,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -386,8 +374,7 @@ class ClientApplicationTest(unittest.TestCase):
# no connection -> NEOStorageError # no connection -> NEOStorageError
self.assertRaises(NEOStorageError, app.tpc_begin, transaction=txn, tid=None) self.assertRaises(NEOStorageError, app.tpc_begin, transaction=txn, tid=None)
# ask a tid to pmn # ask a tid to pmn
packet = Packet() packet = protocol.answerNewTID(msg_id=1, tid=tid)
packet.answerNewTID(msg_id=1, tid=tid)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'expectMessage': None, 'expectMessage': None,
...@@ -433,8 +420,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -433,8 +420,7 @@ class ClientApplicationTest(unittest.TestCase):
# build conflicting state # build conflicting state
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packet() packet = protocol.answerStoreObject(msg_id=1, conflicting=1, oid=oid, serial=tid)
packet.answerStoreObject(msg_id=1, conflicting=1, oid=oid, serial=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -464,8 +450,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -464,8 +450,7 @@ class ClientApplicationTest(unittest.TestCase):
# case with no conflict # case with no conflict
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packet() packet = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
packet.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -504,9 +489,8 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -504,9 +489,8 @@ class ClientApplicationTest(unittest.TestCase):
txn = self.makeTransactionObject() txn = self.makeTransactionObject()
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packet()
# wrong answer -> failure # wrong answer -> failure
packet.answerNewOIDs(1, ()) packet = protocol.answerNewOIDs(1, ())
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -537,9 +521,8 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -537,9 +521,8 @@ class ClientApplicationTest(unittest.TestCase):
txn = self.makeTransactionObject() txn = self.makeTransactionObject()
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packet()
# response -> OK # response -> OK
packet.answerStoreTransaction(msg_id=1, tid=tid) packet = protocol.answerStoreTransaction(msg_id=1, tid=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
...@@ -636,8 +619,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -636,8 +619,7 @@ class ClientApplicationTest(unittest.TestCase):
def hook(tid): def hook(tid):
self.f_called = True self.f_called = True
self.f_called_with_tid = tid self.f_called_with_tid = tid
packet = Packet() packet = protocol.answerNewTID(1, INVALID_TID)
packet.answerNewTID(1, INVALID_TID)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10000), 'getAddress': ('127.0.0.1', 10000),
...@@ -662,8 +644,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -662,8 +644,7 @@ class ClientApplicationTest(unittest.TestCase):
def hook(tid): def hook(tid):
self.f_called = True self.f_called = True
self.f_called_with_tid = tid self.f_called_with_tid = tid
packet = Packet() packet = protocol.notifyTransactionFinished(1, tid)
packet.notifyTransactionFinished(1, tid)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10010), 'getAddress': ('127.0.0.1', 10010),
...@@ -729,23 +710,19 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -729,23 +710,19 @@ class ClientApplicationTest(unittest.TestCase):
self.voteTransaction(app) self.voteTransaction(app)
self.finishTransaction(app) self.finishTransaction(app)
# undo 1 -> no previous revision # undo 1 -> no previous revision
u1p1, u1p2 = Packet(), Packet() u1p1 = protocol.answerTransactionInformation(1, tid1, '', '', '', (oid1, ))
u1p1.answerTransactionInformation(1, tid1, '', '', '', (oid1, )) u1p2 = protocol.oidNotFound(1, 'oid not found')
u1p2.oidNotFound(1, 'oid not found')
# undo 2 -> not end tid # undo 2 -> not end tid
u2p1, u2p2 = Packet(), Packet() u2p1 = protocol.answerTransactionInformation(1, tid2, '', '', '', (oid2, ))
u2p1.answerTransactionInformation(1, tid2, '', '', '', (oid2, )) u2p2 = protocol.answerObject(1, oid2, tid2, tid3, 0, 0, 'O2V1')
u2p2.answerObject(1, oid2, tid2, tid3, 0, 0, 'O2V1')
# undo 3 -> conflict # undo 3 -> conflict
u3p1, u3p2, u3p3 = Packet(), Packet(), Packet() u3p1 = protocol.answerTransactionInformation(1, tid3, '', '', '', (oid2, ))
u3p1.answerTransactionInformation(1, tid3, '', '', '', (oid2, )) u3p2 = protocol.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2')
u3p2.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2') u3p3 = protocol.answerStoreObject(msg_id=1, conflicting=1, oid=oid2, serial=tid2)
u3p3.answerStoreObject(msg_id=1, conflicting=1, oid=oid2, serial=tid2)
# undo 4 -> ok # undo 4 -> ok
u4p1, u4p2, u4p3 = Packet(), Packet(), Packet() u4p1 = protocol.answerTransactionInformation(1, tid3, '', '', '', (oid2, ))
u4p1.answerTransactionInformation(1, tid3, '', '', '', (oid2, )) u4p2 = protocol.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2')
u4p2.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2') u4p3 = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid2, serial=tid2)
u4p3.answerStoreObject(msg_id=1, conflicting=0, oid=oid2, serial=tid2)
# test logic # test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3) packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3)
conn = Mock({ conn = Mock({
...@@ -777,9 +754,8 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -777,9 +754,8 @@ class ClientApplicationTest(unittest.TestCase):
oid1, oid2 = self.makeOID(1), self.makeOID(2) oid1, oid2 = self.makeOID(1), self.makeOID(2)
# TIDs packets supplied by _waitMessage hook # TIDs packets supplied by _waitMessage hook
# TXN info packets # TXN info packets
p3, p4 = Packet(), Packet() p3 = protocol.answerTransactionInformation(1, tid1, '', '', '', (oid1, ))
p3.answerTransactionInformation(1, tid1, '', '', '', (oid1, )) p4 = protocol.answerTransactionInformation(1, tid2, '', '', '', (oid2, ))
p4.answerTransactionInformation(1, tid2, '', '', '', (oid2, ))
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getUUID': ReturnValues(uuid1, uuid2), 'getUUID': ReturnValues(uuid1, uuid2),
...@@ -809,13 +785,11 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -809,13 +785,11 @@ class ClientApplicationTest(unittest.TestCase):
tid1, tid2 = self.makeTID(1), self.makeTID(2) tid1, tid2 = self.makeTID(1), self.makeTID(2)
object_history = ( (tid1, 42), (tid2, 42),) object_history = ( (tid1, 42), (tid2, 42),)
# object history, first is a wrong oid, second is valid # object history, first is a wrong oid, second is valid
p1, p2 = Packet(), Packet() p1 = protocol.answerObjectHistory(1, self.makeOID(2), ())
p1.answerObjectHistory(1, self.makeOID(2), ()) p2 = protocol.answerObjectHistory(1, oid, object_history)
p2.answerObjectHistory(1, oid, object_history)
# transaction history # transaction history
p3, p4 = Packet(), Packet() p3 = protocol.answerTransactionInformation(1, tid1, 'u', 'd', 'e', (oid, ))
p3.answerTransactionInformation(1, tid1, 'u', 'd', 'e', (oid, )) p4 = protocol.answerTransactionInformation(1, tid2, 'u', 'd', 'e', (oid, ))
p4.answerTransactionInformation(1, tid2, 'u', 'd', 'e', (oid, ))
# faked environnement # faked environnement
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
......
...@@ -20,6 +20,7 @@ import unittest ...@@ -20,6 +20,7 @@ import unittest
import logging import logging
import threading import threading
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \ PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
...@@ -100,7 +101,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -100,7 +101,7 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = BaseClientEventHandler(None, dispatcher) client_handler = BaseClientEventHandler(None, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.packetReceived(conn, Packet().ping(1)) client_handler.packetReceived(conn, protocol.ping(1))
pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0) pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
self.assertTrue(isinstance(pong, Packet)) self.assertTrue(isinstance(pong, Packet))
self.assertEquals(pong.getType(), PONG) self.assertEquals(pong.getType(), PONG)
......
...@@ -21,6 +21,7 @@ import logging ...@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.election import ElectionEventHandler from neo.master.election import ElectionEventHandler
from neo.master.app import Application from neo.master.app import Application
...@@ -158,8 +159,9 @@ server: 127.0.0.1:10023 ...@@ -158,8 +159,9 @@ server: 127.0.0.1:10023
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServerConnection" : True})
...@@ -298,16 +300,9 @@ server: 127.0.0.1:10023 ...@@ -298,16 +300,9 @@ server: 127.0.0.1:10023
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), BROKEN_STATE) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), BROKEN_STATE)
def test_07_packetReceived(self): def test_07_packetReceived(self):
p = Packet()
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
p.acceptNodeIdentification(1, p = protocol.acceptNodeIdentification(1, MASTER_NODE_TYPE, uuid,
MASTER_NODE_TYPE, "127.0.0.1", self.master_port, 1009, 2, self.app.uuid)
uuid,
"127.0.0.1",
self.master_port,
1009,
2,
self.app.uuid)
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
...@@ -326,7 +321,9 @@ server: 127.0.0.1:10023 ...@@ -326,7 +321,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
p = Packet() args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
...@@ -347,7 +344,9 @@ server: 127.0.0.1:10023 ...@@ -347,7 +344,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
p = Packet() args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
...@@ -365,7 +364,9 @@ server: 127.0.0.1:10023 ...@@ -365,7 +364,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
p = Packet() args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
...@@ -391,7 +392,7 @@ server: 127.0.0.1:10023 ...@@ -391,7 +392,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packet() p = protocol.askPrimaryMaster(0)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
...@@ -412,7 +413,7 @@ server: 127.0.0.1:10023 ...@@ -412,7 +413,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packet() p = protocol.askPrimaryMaster(0)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
...@@ -431,7 +432,7 @@ server: 127.0.0.1:10023 ...@@ -431,7 +432,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packet() p = protocol.askPrimaryMaster(0)
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid)) self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
...@@ -453,7 +454,7 @@ server: 127.0.0.1:10023 ...@@ -453,7 +454,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packet() p = protocol.askPrimaryMaster(1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
...@@ -474,7 +475,7 @@ server: 127.0.0.1:10023 ...@@ -474,7 +475,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packet() p = protocol.askPrimaryMaster(1)
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid)) self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
...@@ -495,8 +496,9 @@ server: 127.0.0.1:10023 ...@@ -495,8 +496,9 @@ server: 127.0.0.1:10023
def test_10_handleRequestNodeIdentification(self): def test_10_handleRequestNodeIdentification(self):
election = self.election election = self.election
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, conn = Mock({"addPacket" : None, "abort" : None,
"isServerConnection" : True}) "isServerConnection" : True})
...@@ -577,7 +579,7 @@ server: 127.0.0.1:10023 ...@@ -577,7 +579,7 @@ server: 127.0.0.1:10023
def test_11_handleAskPrimaryMaster(self): def test_11_handleAskPrimaryMaster(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(0)
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"isServerConnection" : True, "isServerConnection" : True,
...@@ -623,7 +625,7 @@ server: 127.0.0.1:10023 ...@@ -623,7 +625,7 @@ server: 127.0.0.1:10023
def test_13_handleReelectPrimaryMaster(self): def test_13_handleReelectPrimaryMaster(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet() packet = protocol.askPrimaryMaster(0)
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
......
...@@ -21,6 +21,7 @@ import logging ...@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.recovery import RecoveryEventHandler from neo.master.recovery import RecoveryEventHandler
from neo.master.app import Application from neo.master.app import Application
...@@ -144,17 +145,12 @@ server: 127.0.0.1:10023 ...@@ -144,17 +145,12 @@ server: 127.0.0.1:10023
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (node_type, uuid, ip, port,self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.recovery.handleRequestNodeIdentification(conn, self.recovery.handleRequestNodeIdentification(conn, packet, *args)
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
return uuid return uuid
...@@ -245,8 +241,9 @@ server: 127.0.0.1:10023 ...@@ -245,8 +241,9 @@ server: 127.0.0.1:10023
def test_04_handleRequestNodeIdentification(self): def test_04_handleRequestNodeIdentification(self):
recovery = self.recovery recovery = self.recovery
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None}) conn = Mock({"addPacket" : None, "abort" : None})
recovery.handleRequestNodeIdentification(conn, recovery.handleRequestNodeIdentification(conn,
...@@ -502,7 +499,7 @@ server: 127.0.0.1:10023 ...@@ -502,7 +499,7 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self): def test_05_handleAskPrimaryMaster(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -516,7 +513,7 @@ server: 127.0.0.1:10023 ...@@ -516,7 +513,7 @@ server: 127.0.0.1:10023
# if storage node, expect message # if storage node, expect message
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port) uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)}) "getAddress" : ("127.0.0.1", self.storage_port)})
...@@ -553,7 +550,7 @@ server: 127.0.0.1:10023 ...@@ -553,7 +550,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self): def test_07_handleReelectPrimaryMaster(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet() packet = protocol.askPrimaryMaster(msg_id=0)
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
......
...@@ -21,6 +21,7 @@ import logging ...@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.service import ServiceEventHandler from neo.master.service import ServiceEventHandler
from neo.master.app import Application from neo.master.app import Application
...@@ -216,35 +217,25 @@ server: 127.0.0.1:10023 ...@@ -216,35 +217,25 @@ server: 127.0.0.1:10023
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.service.handleRequestNodeIdentification(conn, self.service.handleRequestNodeIdentification(conn, packet, *args)
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
return uuid return uuid
# Tests # Tests
def test_01_handleRequestNodeIdentification(self): def test_01_handleRequestNodeIdentification(self):
service = self.service service = self.service
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None}) conn = Mock({"addPacket" : None, "abort" : None})
ptid = self.app.lptid ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, service.handleRequestNodeIdentification(conn, packet, *args)
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
self.checkCalledAbort(conn) self.checkCalledAbort(conn)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0) self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid) self.assertEquals(self.app.lptid, ptid)
...@@ -387,7 +378,7 @@ server: 127.0.0.1:10023 ...@@ -387,7 +378,7 @@ server: 127.0.0.1:10023
def test_02_handleAskPrimaryMaster(self): def test_02_handleAskPrimaryMaster(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
# test answer to a storage node # test answer to a storage node
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"answerPrimaryMaster" : None, "answerPrimaryMaster" : None,
...@@ -406,7 +397,7 @@ server: 127.0.0.1:10023 ...@@ -406,7 +397,7 @@ server: 127.0.0.1:10023
# Same but identify as a client node, must not get start operation message # Same but identify as a client node, must not get start operation message
uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021) uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, "abort" : None, "answerPrimaryMaster" : None, conn = Mock({"addPacket" : None, "abort" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "sendPartitionTable" : None, "notifyNodeInformation" : None, "sendPartitionTable" : None,
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)}) "getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
......
...@@ -24,6 +24,7 @@ from struct import pack, unpack ...@@ -24,6 +24,7 @@ from struct import pack, unpack
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.verification import VerificationEventHandler from neo.master.verification import VerificationEventHandler
from neo.master.app import Application from neo.master.app import Application
from neo import protocol
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \ PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \ REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
...@@ -147,17 +148,12 @@ server: 127.0.0.1:10023 ...@@ -147,17 +148,12 @@ server: 127.0.0.1:10023
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.verification.handleRequestNodeIdentification(conn, self.verification.handleRequestNodeIdentification(conn, packet, *args)
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
return uuid return uuid
...@@ -267,12 +263,12 @@ server: 127.0.0.1:10023 ...@@ -267,12 +263,12 @@ server: 127.0.0.1:10023
def test_04_handleRequestNodeIdentification(self): def test_04_handleRequestNodeIdentification(self):
verification = self.verification verification = self.verification
packet = Packet(msg_id=1)
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = ( MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None}) conn = Mock({"addPacket" : None, "abort" : None})
verification.handleRequestNodeIdentification(conn, verification.handleRequestNodeIdentification(conn, packet=packet,
packet=packet,
node_type=MASTER_NODE_TYPE, node_type=MASTER_NODE_TYPE,
uuid=uuid, uuid=uuid,
ip_address='127.0.0.1', ip_address='127.0.0.1',
...@@ -523,7 +519,7 @@ server: 127.0.0.1:10023 ...@@ -523,7 +519,7 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self): def test_05_handleAskPrimaryMaster(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -536,7 +532,7 @@ server: 127.0.0.1:10023 ...@@ -536,7 +532,7 @@ server: 127.0.0.1:10023
self.checkCalledNotifyNodeInformation(conn, 1) self.checkCalledNotifyNodeInformation(conn, 1)
# if storage node, expect messages # if storage node, expect messages
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port) uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = Packet(msg_id=2) packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)}) "getAddress" : ("127.0.0.1", self.storage_port)})
...@@ -571,7 +567,7 @@ server: 127.0.0.1:10023 ...@@ -571,7 +567,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self): def test_07_handleReelectPrimaryMaster(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet() packet = protocol.askPrimaryMaster(0)
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager
...@@ -409,12 +410,11 @@ class testConnection(unittest.TestCase): ...@@ -409,12 +410,11 @@ class testConnection(unittest.TestCase):
# packet witch raise protocol error # packet witch raise protocol error
# change the max packet size and create a to big message # change the max packet size and create a to big message
# be careful not to set the max packet size < error message # be careful not to set the max packet size < error message
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list) p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE
protocol.MAX_PACKET_SIZE = 0x55 protocol.MAX_PACKET_SIZE = 0x55
...@@ -425,7 +425,7 @@ class testConnection(unittest.TestCase): ...@@ -425,7 +425,7 @@ class testConnection(unittest.TestCase):
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.addPacket(p) bc.addPacket(p)
self.assertNotEqual(bc.write_buf, "testdata") self.assertNotEqual(bc.write_buf, "testdata")
self.assertEqual(len(bc.write_buf), len(p.encode())) self.assertRaises(ProtocolError, p.encode)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2)
# check it sends error packet # check it sends error packet
packet = Packet.parse(bc.write_buf) packet = Packet.parse(bc.write_buf)
...@@ -478,12 +478,11 @@ class testConnection(unittest.TestCase): ...@@ -478,12 +478,11 @@ class testConnection(unittest.TestCase):
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
# give some data to analyse # give some data to analyse
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list) p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p.encode() data = p.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
...@@ -505,21 +504,19 @@ class testConnection(unittest.TestCase): ...@@ -505,21 +504,19 @@ class testConnection(unittest.TestCase):
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
# packet 1 # packet 1
p1 = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p1.answerPrimaryMaster(1, getNewUUID(), master_list) p1 = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p1.encode() data = p1.encode()
bc.read_buf += data bc.read_buf += data
# packet 2 # packet 2
p2 = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p2.answerPrimaryMaster(2, getNewUUID(), master_list) p2 = protocol.answerPrimaryMaster(2, getNewUUID(), master_list)
data = p2.encode() data = p2.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode())) self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode()))
...@@ -562,12 +559,11 @@ class testConnection(unittest.TestCase): ...@@ -562,12 +559,11 @@ class testConnection(unittest.TestCase):
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list) p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p.encode() data = p.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
...@@ -688,13 +684,12 @@ class testConnection(unittest.TestCase): ...@@ -688,13 +684,12 @@ class testConnection(unittest.TestCase):
handler = Mock() handler = Mock()
# patch receive method to return data # patch receive method to return data
def receive(self): def receive(self):
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2136, getNewUUID()), master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2136, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
uuid = getNewUUID() uuid = getNewUUID()
p.answerPrimaryMaster(1, uuid, master_list) p = protocol.answerPrimaryMaster(1, uuid, master_list)
data = p.encode() data = p.encode()
return data return data
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo import protocol
from neo.protocol import * from neo.protocol import *
from time import time, gmtime from time import time, gmtime
...@@ -66,73 +67,58 @@ class testProtocol(unittest.TestCase): ...@@ -66,73 +67,58 @@ class testProtocol(unittest.TestCase):
self.assertEqual(len(p), PACKET_HEADER_SIZE) self.assertEqual(len(p), PACKET_HEADER_SIZE)
def test_02_error(self): def test_02_error(self):
p = Packet() p = protocol._error(1, 10, "error message")
p.error(1, 10, "error message")
code, msg = p._decodeError() code, msg = p._decodeError()
self.assertEqual(code, 10) self.assertEqual(code, 10)
self.assertEqual(msg, "error message") self.assertEqual(msg, "error message")
def test_03_protocolError(self): def test_03_protocolError(self):
p = Packet() p = protocol.protocolError(1, "bad protocol")
p.protocolError(1, "bad protocol")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, PROTOCOL_ERROR_CODE) self.assertEqual(error_code, PROTOCOL_ERROR_CODE)
self.assertEqual(error_msg, "protocol error: bad protocol") self.assertEqual(error_msg, "protocol error: bad protocol")
def test_04_internalError(self): def test_04_internalError(self):
p = Packet() p = protocol.internalError(1, "bad internal")
p.internalError(1, "bad internal")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, INTERNAL_ERROR_CODE) self.assertEqual(error_code, INTERNAL_ERROR_CODE)
self.assertEqual(error_msg, "internal error: bad internal") self.assertEqual(error_msg, "internal error: bad internal")
def test_05_notReady(self): def test_05_notReady(self):
p = Packet() p = protocol.notReady(1, "wait")
p.notReady(1, "wait")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, NOT_READY_CODE) self.assertEqual(error_code, NOT_READY_CODE)
self.assertEqual(error_msg, "not ready: wait") self.assertEqual(error_msg, "not ready: wait")
def test_06_brokenNodeDisallowedError(self): def test_06_brokenNodeDisallowedError(self):
p = Packet() p = protocol.brokenNodeDisallowedError(1, "broken")
p.brokenNodeDisallowedError(1, "broken")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, BROKEN_NODE_DISALLOWED_CODE) self.assertEqual(error_code, BROKEN_NODE_DISALLOWED_CODE)
self.assertEqual(error_msg, "broken node disallowed error: broken") self.assertEqual(error_msg, "broken node disallowed error: broken")
def test_07_oidNotFound(self): def test_07_oidNotFound(self):
p = Packet() p = protocol.oidNotFound(1, "no oid")
p.oidNotFound(1, "no oid")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_msg, "oid not found: no oid") self.assertEqual(error_msg, "oid not found: no oid")
def test_08_oidNotFound(self): def test_08_oidNotFound(self):
p = Packet() p = protocol.tidNotFound(1, "no tid")
p.tidNotFound(1, "no tid")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, TID_NOT_FOUND_CODE) self.assertEqual(error_code, TID_NOT_FOUND_CODE)
self.assertEqual(error_msg, "tid not found: no tid") self.assertEqual(error_msg, "tid not found: no tid")
def test_09_ping(self): def test_09_ping(self):
p = Packet() p = protocol.ping(1)
p.ping(1)
self.assertEqual(None, p.decode()) self.assertEqual(None, p.decode())
def test_10_pong(self): def test_10_pong(self):
p = Packet() p = protocol.pong(1)
p.pong(1)
self.assertEqual(None, p.decode()) self.assertEqual(None, p.decode())
def test_11_requestNodeIdentification(self): def test_11_requestNodeIdentification(self):
p = Packet()
uuid = self.getNewUUID() uuid = self.getNewUUID()
p.requestNodeIdentification(1, p = protocol.requestNodeIdentification(1, CLIENT_NODE_TYPE, uuid,
CLIENT_NODE_TYPE, "127.0.0.1", 9080, "unittest")
uuid,
"127.0.0.1",
9080,
"unittest"
)
node, p_uuid, ip, port, name = p.decode() node, p_uuid, ip, port, name = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, CLIENT_NODE_TYPE)
self.assertEqual(p_uuid, uuid) self.assertEqual(p_uuid, uuid)
...@@ -141,17 +127,9 @@ class testProtocol(unittest.TestCase): ...@@ -141,17 +127,9 @@ class testProtocol(unittest.TestCase):
self.assertEqual(name, "unittest") self.assertEqual(name, "unittest")
def test_12_acceptNodeIdentification(self): def test_12_acceptNodeIdentification(self):
p = Packet()
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID() uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p.acceptNodeIdentification(1, p = protocol.acceptNodeIdentification(1, CLIENT_NODE_TYPE, uuid1,
CLIENT_NODE_TYPE, "127.0.0.1", 9080, 10, 20, uuid2)
uuid1,
"127.0.0.1",
9080,
10,
20,
uuid2
)
node, p_uuid, ip, port, nb_partitions, nb_replicas, your_uuid = p.decode() node, p_uuid, ip, port, nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, CLIENT_NODE_TYPE)
self.assertEqual(p_uuid, uuid1) self.assertEqual(p_uuid, uuid1)
...@@ -162,12 +140,10 @@ class testProtocol(unittest.TestCase): ...@@ -162,12 +140,10 @@ class testProtocol(unittest.TestCase):
self.assertEqual(your_uuid, uuid2) self.assertEqual(your_uuid, uuid2)
def test_13_askPrimaryMaster(self): def test_13_askPrimaryMaster(self):
p = Packet() p = protocol.askPrimaryMaster(1)
p.askPrimaryMaster(1)
self.assertEqual(None, p.decode()) self.assertEqual(None, p.decode())
def test_14_answerPrimaryMaster(self): def test_14_answerPrimaryMaster(self):
p = Packet()
uuid = self.getNewUUID() uuid = self.getNewUUID()
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
...@@ -175,26 +151,20 @@ class testProtocol(unittest.TestCase): ...@@ -175,26 +151,20 @@ class testProtocol(unittest.TestCase):
master_list = [("127.0.0.1", 1, uuid1), master_list = [("127.0.0.1", 1, uuid1),
("127.0.0.2", 2, uuid2), ("127.0.0.2", 2, uuid2),
("127.0.0.3", 3, uuid3)] ("127.0.0.3", 3, uuid3)]
p.answerPrimaryMaster(1, p = protocol.answerPrimaryMaster(1, uuid, master_list)
uuid,
master_list
)
primary_uuid, p_master_list = p.decode() primary_uuid, p_master_list = p.decode()
self.assertEqual(primary_uuid, uuid) self.assertEqual(primary_uuid, uuid)
self.assertEqual(master_list, p_master_list) self.assertEqual(master_list, p_master_list)
def test_15_announcePrimaryMaster(self): def test_15_announcePrimaryMaster(self):
p = Packet() p = protocol.announcePrimaryMaster(1)
p.announcePrimaryMaster(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_16_reelectPrimaryMaster(self): def test_16_reelectPrimaryMaster(self):
p = Packet() p = protocol.reelectPrimaryMaster(1)
p.reelectPrimaryMaster(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_17_notifyNodeInformation(self): def test_17_notifyNodeInformation(self):
p = Packet()
uuid = self.getNewUUID() uuid = self.getNewUUID()
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
...@@ -202,37 +172,31 @@ class testProtocol(unittest.TestCase): ...@@ -202,37 +172,31 @@ class testProtocol(unittest.TestCase):
node_list = [(CLIENT_NODE_TYPE, "127.0.0.1", 1, uuid1, RUNNING_STATE), node_list = [(CLIENT_NODE_TYPE, "127.0.0.1", 1, uuid1, RUNNING_STATE),
(CLIENT_NODE_TYPE, "127.0.0.2", 2, uuid2, DOWN_STATE), (CLIENT_NODE_TYPE, "127.0.0.2", 2, uuid2, DOWN_STATE),
(CLIENT_NODE_TYPE, "127.0.0.3", 3, uuid3, BROKEN_STATE)] (CLIENT_NODE_TYPE, "127.0.0.3", 3, uuid3, BROKEN_STATE)]
p.notifyNodeInformation(1, p = protocol.notifyNodeInformation(1, node_list)
node_list) p_node_list = p.decode()[0]
p_node_list = p.decode()[0]
self.assertEqual(node_list, p_node_list) self.assertEqual(node_list, p_node_list)
def test_18_askLastIDs(self): def test_18_askLastIDs(self):
p = Packet() p = protocol.askLastIDs(1)
p.askLastIDs(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_19_answerLastIDs(self): def test_19_answerLastIDs(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
ptid = self.getNextTID() ptid = self.getNextTID()
p.answerLastIDs(1, oid, tid, ptid) p = protocol.answerLastIDs(1, oid, tid, ptid)
loid, ltid, lptid = p.decode() loid, ltid, lptid = p.decode()
self.assertEqual(loid, oid) self.assertEqual(loid, oid)
self.assertEqual(ltid, tid) self.assertEqual(ltid, tid)
self.assertEqual(lptid, ptid) self.assertEqual(lptid, ptid)
def test_20_askPartitionTable(self): def test_20_askPartitionTable(self):
p = Packet()
offset_list = [1, 523, 6, 124] offset_list = [1, 523, 6, 124]
p.askPartitionTable(1, p = protocol.askPartitionTable(1, offset_list)
offset_list)
p_offset_list = p.decode()[0] p_offset_list = p.decode()[0]
self.assertEqual(offset_list, p_offset_list) self.assertEqual(offset_list, p_offset_list)
def test_21_answerPartitionTable(self): def test_21_answerPartitionTable(self):
p = Packet()
ptid = self.getNextTID() ptid = self.getNextTID()
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
...@@ -240,14 +204,12 @@ class testProtocol(unittest.TestCase): ...@@ -240,14 +204,12 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))), cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))), (43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))] (124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
p.answerPartitionTable(1, ptid, p = protocol.answerPartitionTable(1, ptid, cell_list)
cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid) self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list) self.assertEqual(p_cell_list, cell_list)
def test_22_sendPartitionTable(self): def test_22_sendPartitionTable(self):
p = Packet()
ptid = self.getNextTID() ptid = self.getNextTID()
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
...@@ -255,14 +217,12 @@ class testProtocol(unittest.TestCase): ...@@ -255,14 +217,12 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))), cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))), (43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))] (124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
p.answerPartitionTable(1, ptid, p = protocol.answerPartitionTable(1, ptid, cell_list)
cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid) self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list) self.assertEqual(p_cell_list, cell_list)
def test_23_notifyPartitionChanges(self): def test_23_notifyPartitionChanges(self):
p = Packet()
ptid = self.getNextTID() ptid = self.getNextTID()
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
...@@ -270,177 +230,152 @@ class testProtocol(unittest.TestCase): ...@@ -270,177 +230,152 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, uuid1, UP_TO_DATE_STATE), cell_list = [(0, uuid1, UP_TO_DATE_STATE),
(43, uuid2, OUT_OF_DATE_STATE), (43, uuid2, OUT_OF_DATE_STATE),
(124, uuid1, DISCARDED_STATE)] (124, uuid1, DISCARDED_STATE)]
p.notifyPartitionChanges(1, ptid, p = protocol.notifyPartitionChanges(1, ptid,
cell_list) cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid) self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list) self.assertEqual(p_cell_list, cell_list)
def test_24_startOperation(self): def test_24_startOperation(self):
p = Packet() p = protocol.startOperation(1)
p.startOperation(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_25_stopOperation(self): def test_25_stopOperation(self):
p = Packet() p = protocol.stopOperation(1)
p.stopOperation(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_26_askUnfinishedTransaction(self): def test_26_askUnfinishedTransaction(self):
p = Packet() p = protocol.askUnfinishedTransactions(1)
p.askUnfinishedTransactions(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_27_answerUnfinishedTransaction(self): def test_27_answerUnfinishedTransaction(self):
p = Packet()
tid1 = self.getNextTID() tid1 = self.getNextTID()
tid2 = self.getNextTID() tid2 = self.getNextTID()
tid3 = self.getNextTID() tid3 = self.getNextTID()
tid4 = self.getNextTID() tid4 = self.getNextTID()
tid_list = [tid1, tid2, tid3, tid4] tid_list = [tid1, tid2, tid3, tid4]
p.answerUnfinishedTransactions(1,tid_list) p = protocol.answerUnfinishedTransactions(1,tid_list)
p_tid_list = p.decode()[0] p_tid_list = p.decode()[0]
self.assertEqual(p_tid_list, tid_list) self.assertEqual(p_tid_list, tid_list)
def test_28_askObjectPresent(self): def test_28_askObjectPresent(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
p.askObjectPresent(1, oid, tid) p = protocol.askObjectPresent(1, oid, tid)
loid, ltid = p.decode() loid, ltid = p.decode()
self.assertEqual(loid, oid) self.assertEqual(loid, oid)
self.assertEqual(ltid, tid) self.assertEqual(ltid, tid)
def test_29_answerObjectPresent(self): def test_29_answerObjectPresent(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
p.answerObjectPresent(1, oid, tid) p = protocol.answerObjectPresent(1, oid, tid)
loid, ltid = p.decode() loid, ltid = p.decode()
self.assertEqual(loid, oid) self.assertEqual(loid, oid)
self.assertEqual(ltid, tid) self.assertEqual(ltid, tid)
def test_30_deleteTransaction(self): def test_30_deleteTransaction(self):
p = Packet()
self.assertEqual(p.getId(), None)
self.assertEqual(p.getType(), None)
tid = self.getNextTID() tid = self.getNextTID()
p.deleteTransaction(1, tid) p = protocol.deleteTransaction(1, tid)
self.assertEqual(p.getId(), 1)
self.assertEqual(p.getType(), DELETE_TRANSACTION)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_31_commitTransaction(self): def test_31_commitTransaction(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.commitTransaction(1, tid) p = protocol.commitTransaction(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_32_askNewTID(self): def test_32_askNewTID(self):
p = Packet() p = protocol.askNewTID(1)
p.askNewTID(1)
self.assertEqual(p.decode(), None) self.assertEqual(p.decode(), None)
def test_33_answerNewTID(self): def test_33_answerNewTID(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.answerNewTID(1, tid) p = protocol.answerNewTID(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_34_askNewOIDs(self): def test_34_askNewOIDs(self):
p = Packet() p = protocol.askNewOIDs(1, 10)
p.askNewOIDs(1, 10)
nb = p.decode() nb = p.decode()
self.assertEqual(nb, (10,)) self.assertEqual(nb, (10,))
def test_35_answerNewOIDs(self): def test_35_answerNewOIDs(self):
p = Packet()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.answerNewOIDs(1,oid_list) p = protocol.answerNewOIDs(1,oid_list)
p_oid_list = p.decode()[0] p_oid_list = p.decode()[0]
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
def test_36_finishTransaction(self): def test_36_finishTransaction(self):
p = Packet()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.finishTransaction(1,oid_list, tid) p = protocol.finishTransaction(1,oid_list, tid)
p_oid_list, ptid = p.decode() p_oid_list, ptid = p.decode()
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
def test_37_notifyTransactionFinished(self): def test_37_notifyTransactionFinished(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.notifyTransactionFinished(1, tid) p = protocol.notifyTransactionFinished(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_38_lockInformation(self): def test_38_lockInformation(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.lockInformation(1, tid) p = protocol.lockInformation(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_39_notifyInformationLocked(self): def test_39_notifyInformationLocked(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.notifyInformationLocked(1, tid) p = protocol.notifyInformationLocked(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_40_invalidateObjects(self): def test_40_invalidateObjects(self):
p = Packet()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.invalidateObjects(1,oid_list, tid) p = protocol.invalidateObjects(1,oid_list, tid)
p_oid_list, ptid = p.decode() p_oid_list, ptid = p.decode()
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
def test_41_unlockInformation(self): def test_41_unlockInformation(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.unlockInformation(1, tid) p = protocol.unlockInformation(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_42_abortTransaction(self): def test_42_abortTransaction(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.abortTransaction(1, tid) p = protocol.abortTransaction(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_43_askStoreTransaction(self): def test_43_askStoreTransaction(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.askStoreTransaction(1, p = protocol.askStoreTransaction(1, tid, "moi", "transaction", "exti", oid_list)
tid,
"moi",
"transaction",
"exti",
oid_list)
ptid, user, desc, ext, p_oid_list = p.decode() ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
...@@ -449,24 +384,16 @@ class testProtocol(unittest.TestCase): ...@@ -449,24 +384,16 @@ class testProtocol(unittest.TestCase):
self.assertEqual(ext, "exti") self.assertEqual(ext, "exti")
def test_44_answerStoreTransaction(self): def test_44_answerStoreTransaction(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.answerStoreTransaction(1, tid) p = protocol.answerStoreTransaction(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
def test_45_askStoreObject(self): def test_45_askStoreObject(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
serial = self.getNextTID() serial = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
p.askStoreObject(1, p = protocol.askStoreObject(1, oid, serial, 1, 55, "to", tid)
oid,
serial,
1,
55,
"to",
tid)
poid, pserial, compression, checksum, data, ptid = p.decode() poid, pserial, compression, checksum, data, ptid = p.decode()
self.assertEqual(oid, poid) self.assertEqual(oid, poid)
self.assertEqual(serial, pserial) self.assertEqual(serial, pserial)
...@@ -476,44 +403,29 @@ class testProtocol(unittest.TestCase): ...@@ -476,44 +403,29 @@ class testProtocol(unittest.TestCase):
self.assertEqual(data, "to") self.assertEqual(data, "to")
def test_46_answerStoreObject(self): def test_46_answerStoreObject(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
serial = self.getNextTID() serial = self.getNextTID()
p.answerStoreObject(1, p = protocol.answerStoreObject(1, 1, oid, serial)
1,
oid,
serial)
conflicting, poid, pserial = p.decode() conflicting, poid, pserial = p.decode()
self.assertEqual(oid, poid) self.assertEqual(oid, poid)
self.assertEqual(serial, pserial) self.assertEqual(serial, pserial)
self.assertEqual(conflicting, 1) self.assertEqual(conflicting, 1)
def test_47_askObject(self): def test_47_askObject(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
serial = self.getNextTID() serial = self.getNextTID()
tid = self.getNextTID() tid = self.getNextTID()
p.askObject(1, p = protocol.askObject(1, oid, serial, tid)
oid,
serial,
tid)
poid, pserial, ptid = p.decode() poid, pserial, ptid = p.decode()
self.assertEqual(oid, poid) self.assertEqual(oid, poid)
self.assertEqual(serial, pserial) self.assertEqual(serial, pserial)
self.assertEqual(tid, ptid) self.assertEqual(tid, ptid)
def test_48_answerObject(self): def test_48_answerObject(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
serial_start = self.getNextTID() serial_start = self.getNextTID()
serial_end = self.getNextTID() serial_end = self.getNextTID()
p.answerObject(1, p = protocol.answerObject(1, oid, serial_start, serial_end, 1, 55, "to",)
oid,
serial_start,
serial_end,
1,
55,
"to",)
poid, pserial_start, pserial_end, compression, checksum, data= p.decode() poid, pserial_start, pserial_end, compression, checksum, data= p.decode()
self.assertEqual(oid, poid) self.assertEqual(oid, poid)
self.assertEqual(serial_start, pserial_start) self.assertEqual(serial_start, pserial_start)
...@@ -523,48 +435,37 @@ class testProtocol(unittest.TestCase): ...@@ -523,48 +435,37 @@ class testProtocol(unittest.TestCase):
self.assertEqual(data, "to") self.assertEqual(data, "to")
def test_49_askTIDs(self): def test_49_askTIDs(self):
p = Packet() p = protocol.askTIDs(1, 1, 10, 5)
p.askTIDs(1,
1,
10,
5)
first, last, partition = p.decode() first, last, partition = p.decode()
self.assertEqual(first, 1) self.assertEqual(first, 1)
self.assertEqual(last, 10) self.assertEqual(last, 10)
self.assertEqual(partition, 5) self.assertEqual(partition, 5)
def test_50_answerTIDs(self): def test_50_answerTIDs(self):
p = Packet()
tid1 = self.getNextTID() tid1 = self.getNextTID()
tid2 = self.getNextTID() tid2 = self.getNextTID()
tid3 = self.getNextTID() tid3 = self.getNextTID()
tid4 = self.getNextTID() tid4 = self.getNextTID()
tid_list = [tid1, tid2, tid3, tid4] tid_list = [tid1, tid2, tid3, tid4]
p.answerTIDs(1,tid_list) p = protocol.answerTIDs(1,tid_list)
p_tid_list = p.decode()[0] p_tid_list = p.decode()[0]
self.assertEqual(p_tid_list, tid_list) self.assertEqual(p_tid_list, tid_list)
def test_51_askTransactionInfomation(self): def test_51_askTransactionInfomation(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
p.askTransactionInformation(1, tid) p = protocol.askTransactionInformation(1, tid)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(tid, ptid) self.assertEqual(tid, ptid)
def test_52_answerTransactionInformation(self): def test_52_answerTransactionInformation(self):
p = Packet()
tid = self.getNextTID() tid = self.getNextTID()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.answerTransactionInformation(1, p = protocol.answerTransactionInformation(1, tid, "moi",
tid, "transaction", "exti", oid_list)
"moi",
"transaction",
"exti",
oid_list)
ptid, user, desc, ext, p_oid_list = p.decode() ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
...@@ -573,49 +474,39 @@ class testProtocol(unittest.TestCase): ...@@ -573,49 +474,39 @@ class testProtocol(unittest.TestCase):
self.assertEqual(ext, "exti") self.assertEqual(ext, "exti")
def test_53_askObjectHistory(self): def test_53_askObjectHistory(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
p.askObjectHistory(1, p = protocol.askObjectHistory(1, oid, 1, 10,)
oid,
1,
10,)
poid, first, last = p.decode() poid, first, last = p.decode()
self.assertEqual(first, 1) self.assertEqual(first, 1)
self.assertEqual(last, 10) self.assertEqual(last, 10)
self.assertEqual(poid, oid) self.assertEqual(poid, oid)
def test_54_answerObjectHistory(self): def test_54_answerObjectHistory(self):
p = Packet()
oid = self.getNextTID() oid = self.getNextTID()
hist1 = (self.getNextTID(), 15) hist1 = (self.getNextTID(), 15)
hist2 = (self.getNextTID(), 353) hist2 = (self.getNextTID(), 353)
hist3 = (self.getNextTID(), 326) hist3 = (self.getNextTID(), 326)
hist4 = (self.getNextTID(), 652) hist4 = (self.getNextTID(), 652)
hist_list = [hist1, hist2, hist3, hist4] hist_list = [hist1, hist2, hist3, hist4]
p.answerObjectHistory(1, oid, hist_list) p = protocol.answerObjectHistory(1, oid, hist_list)
poid, p_hist_list = p.decode() poid, p_hist_list = p.decode()
self.assertEqual(p_hist_list, hist_list) self.assertEqual(p_hist_list, hist_list)
self.assertEqual(oid, poid) self.assertEqual(oid, poid)
def test_55_askOIDs(self): def test_55_askOIDs(self):
p = Packet() p = protocol.askOIDs(1, 1, 10, 5)
p.askOIDs(1,
1,
10,
5)
first, last, partition = p.decode() first, last, partition = p.decode()
self.assertEqual(first, 1) self.assertEqual(first, 1)
self.assertEqual(last, 10) self.assertEqual(last, 10)
self.assertEqual(partition, 5) self.assertEqual(partition, 5)
def test_56_answerOIDs(self): def test_56_answerOIDs(self):
p = Packet()
oid1 = self.getNextTID() oid1 = self.getNextTID()
oid2 = self.getNextTID() oid2 = self.getNextTID()
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p.answerOIDs(1,oid_list) p = protocol.answerOIDs(1,oid_list)
p_oid_list = p.decode()[0] p_oid_list = p.decode()[0]
self.assertEqual(p_oid_list, oid_list) self.assertEqual(p_oid_list, oid_list)
......
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