Commit 46bbf87c authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fi many tests for storage application.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@813 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent af26ef94
from neo.storage.tests.testStorageApp import StorageAppTests
from neo.storage.tests.testStorageBootstrapHandler import StorageBootstrapTests
from neo.storage.tests.testStorageMySQLdb import StorageMySQSLdbTests
from neo.storage.tests.testStorageVerificationHandler import StorageVerificationTests
from neo.storage.tests.testInitializationHandler import StorageInitializationHandlerTests
from neo.storage.tests.testVerificationHandler import StorageVerificationHandlerTests
from neo.storage.tests.testBootstrapHandler import StorageBootstrapHandlerTests
from neo.storage.tests.testStorageHandler import StorageStorageHandlerTests
from neo.storage.tests.testClientHandler import StorageClientHandlerTests
from neo.storage.tests.testMasterHandler import StorageMasterHandlerTests
from neo.storage.tests.testStorageHandler import StorageStorageHandlerTests
__all__ = [
'StorageAppTests',
'StorageBootstrapTests',
'StorageMySQSLdbTests',
'StorageVerificationTests',
'StorageInitializationHandlerTests',
'StorageClientHandlerTests',
'StorageMasterHandlerTests',
'StorageStorageHandlerTests',
'StorageInitializationHandlerTests',
]
......@@ -32,7 +32,7 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER
class StorageBootstrapTests(NeoTestBase):
class StorageBootstrapHandlerTests(NeoTestBase):
def setUp(self):
logging.basicConfig(level = logging.ERROR)
......@@ -59,24 +59,18 @@ class StorageBootstrapTests(NeoTestBase):
# Tests
def test_01_connectionCompleted(self):
# trying mn is None -> RuntimeError
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.app.trying_master_node = None
self.assertRaises(RuntimeError, self.bootstrap.connectionCompleted, conn)
# request identification
self.app.trying_master_node = self.trying_master_node
self.bootstrap.connectionCompleted(conn)
self.checkRequestNodeIdentification(conn)
self.checkAskPrimaryMaster(conn)
def test_02_connectionFailed(self):
# trying mn is None -> RuntimeError
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.app.trying_master_node = None
self.assertRaises(RuntimeError, self.bootstrap.connectionFailed, conn)
# the primary is dead
self.app.trying_master_node = self.trying_master_node
self.app.primary_master_node = self.app.trying_master_node
......@@ -192,139 +186,6 @@ class StorageBootstrapTests(NeoTestBase):
self.checkClosed(conn)
self.checkNoPacketSent(conn)
def test_08_handleRequestNodeIdentification1(self):
# client socket connection -> rejected
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
self.checkUnexpectedPacketRaised(
self.bootstrap.handleRequestNodeIdentification,
conn=conn,
uuid=self.getNewUUID(),
packet=packet,
port=self.master_port,
node_type=MASTER_NODE_TYPE,
ip_address='127.0.0.1',
name='',)
self.checkNoUUIDSet(conn)
def test_08_handleRequestNodeIdentification2(self):
# not a master node -> rejected
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.checkNotReadyErrorRaised(
self.bootstrap.handleRequestNodeIdentification,
conn=conn,
uuid=self.getNewUUID(),
packet=packet,
port=self.master_port,
node_type=STORAGE_NODE_TYPE,
ip_address='127.0.0.1',
name=self.app.name,)
self.checkNoUUIDSet(conn)
def test_08_handleRequestNodeIdentification3(self):
# bad app name -> rejected
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.checkProtocolErrorRaised(
self.bootstrap.handleRequestNodeIdentification,
conn=conn,
uuid=self.getNewUUID(),
packet=packet,
port=self.master_port,
node_type=MASTER_NODE_TYPE,
ip_address='127.0.0.1',
name='INVALID_NAME',)
self.checkNoUUIDSet(conn)
def test_08_handleRequestNodeIdentification4(self):
# new master
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("192.168.1.1", self.master_port), })
# master not known
mn = self.app.nm.getNodeByServer(('192.168.1.1', self.master_port))
self.assertEquals(mn, None)
count = len(self.app.nm.getNodeList())
uuid = self.getNewUUID()
self.bootstrap.handleRequestNodeIdentification(
conn=conn,
uuid=uuid,
packet=packet,
port=self.master_port,
node_type=MASTER_NODE_TYPE,
ip_address='192.168.1.1',
name=self.app.name,)
self.assertEquals(len(self.app.nm.getNodeList()), count + 1)
self.checkAcceptNodeIdentification(conn, answered_packet=packet, decode=True)
self.checkUUIDSet(conn, uuid)
self.checkAborted(conn)
def test_08_handleRequestNodeIdentification5(self):
# broken node -> rejected
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
master = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
uuid=self.getNewUUID()
master.setState(BROKEN_STATE)
master.setUUID(uuid)
self.checkBrokenNodeDisallowedErrorRaised(
self.bootstrap.handleRequestNodeIdentification,
conn=conn,
uuid=uuid,
packet=packet,
port=self.master_port,
node_type=MASTER_NODE_TYPE,
ip_address='127.0.0.1',
name=self.app.name,)
self.checkNoUUIDSet(conn)
def test_08_handleRequestNodeIdentification6(self):
# master node is already known
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
# master known
mn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
self.assertNotEquals(mn, None)
uuid = self.getNewUUID()
self.bootstrap.handleRequestNodeIdentification(
conn=conn,
uuid=uuid,
packet=packet,
port=self.master_port,
node_type=MASTER_NODE_TYPE,
ip_address='127.0.0.1',
name=self.app.name)
master = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
self.assertEquals(master.getUUID(), uuid)
self.checkAcceptNodeIdentification(conn, answered_packet=packet, decode=True)
self.checkUUIDSet(conn, uuid)
self.checkAborted(conn)
def test_09_handleAcceptNodeIdentification1(self):
# server socket connection -> rejected
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.app.trying_master_node = self.trying_master_node
self.checkUnexpectedPacketRaised(
self.bootstrap.handleAcceptNodeIdentification,
conn=conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=self.getNewUUID(),
ip_address='127.0.0.1',
port=self.master_port,
num_partitions=self.app.num_partitions,
num_replicas=self.app.num_replicas,
your_uuid=self.getNewUUID())
def test_09_handleAcceptNodeIdentification2(self):
# not a master node -> rejected
conn = Mock({"isServerConnection": False,
......@@ -395,18 +256,6 @@ class StorageBootstrapTests(NeoTestBase):
**args)
self.checkNoUUIDSet(conn)
self.checkNoPacketSent(conn)
# create a new partition table
self.bootstrap.handleAcceptNodeIdentification(
num_partitions=self.num_partitions,
num_replicas=self.num_replicas + 1,
**args)
self.assertEquals(self.app.num_partitions, self.num_partitions)
self.assertEquals(self.app.num_replicas, self.num_replicas + 1)
self.assertEqual(self.app.num_partitions, self.app.dm.getNumPartitions())
self.assertTrue(isinstance(self.app.pt, PartitionTable))
self.assertEquals(self.app.ptid, self.app.dm.getPTID())
self.checkUUIDSet(conn, uuid)
self.checkAskPrimaryMaster(conn)
def test_09_handleAcceptNodeIdentification5(self):
# no errors
......@@ -442,23 +291,6 @@ class StorageBootstrapTests(NeoTestBase):
self.assertEquals(self.app.trying_master_node.getUUID(), uuid)
self.assertEquals(self.app.uuid, self.app.dm.getUUID())
self.assertEquals(self.app.uuid, your_uuid)
def test_10_handleAnswerPrimaryMaster01(self):
# server connection rejected
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.app.trying_master_node = self.trying_master_node
self.app.primary_master_node = None
self.checkUnexpectedPacketRaised(
self.bootstrap.handleAnswerPrimaryMaster,
conn=conn,
packet=packet,
primary_uuid=self.getNewUUID(),
known_master_list=()
)
self.assertEquals(self.app.trying_master_node, self.trying_master_node)
self.assertEquals(self.app.primary_master_node, None)
def test_10_handleAnswerPrimaryMaster02(self):
# register new master nodes
......@@ -484,8 +316,7 @@ class StorageBootstrapTests(NeoTestBase):
self.assertTrue(isinstance(n, MasterNode))
self.assertEquals(n.getUUID(), new_master[2])
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.checkNoPacketSent(conn)
self.checkNotClosed(conn)
self.checkRequestNodeIdentification(conn)
def test_10_handleAnswerPrimaryMaster03(self):
# invalid primary master uuid -> close connection
......@@ -546,12 +377,8 @@ class StorageBootstrapTests(NeoTestBase):
known_master_list=()
)
self.assertEquals(self.app.primary_master_node, pmn)
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 1)
call = conn.mockGetNamedCalls('setHandler')[0]
self.assertTrue(isinstance(call.getParam(0), VerificationHandler))
self.assertEquals(self.app.trying_master_node, pmn)
self.checkNoPacketSent(conn)
self.checkNotClosed(conn)
self.checkRequestNodeIdentification(conn)
def test_10_handleAnswerPrimaryMaster06(self):
# primary_uuid not known -> nothing happen
......@@ -570,8 +397,7 @@ class StorageBootstrapTests(NeoTestBase):
self.assertEquals(self.app.primary_master_node, None)
self.assertEquals(self.app.trying_master_node, None)
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.checkNoPacketSent(conn)
self.checkNotClosed(conn)
self.checkRequestNodeIdentification(conn)
if __name__ == "__main__":
unittest.main()
......
#
# Copyright (C) 2009 Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
import unittest
import logging
from mock import Mock
from neo.tests.base import NeoTestBase
from neo import protocol
from neo.node import MasterNode
from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode
from neo.storage.handlers import InitializationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER
from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
class StorageInitializationHandlerTests(NeoTestBase):
def setUp(self):
logging.basicConfig(level = logging.ERROR)
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
self.verification = InitializationHandler(self.app)
# define some variable to simulate client and storage node
self.master_port = 10010
self.storage_port = 10020
self.client_port = 11011
self.num_partitions = 1009
self.num_replicas = 2
self.app.num_partitions = 1009
self.app.num_replicas = 2
self.app.operational = False
self.app.load_lock_dict = {}
self.app.pt = PartitionTable(self.app.num_partitions, self.app.num_replicas)
def tearDown(self):
NeoTestBase.tearDown(self)
# Common methods
def getLastUUID(self):
return self.uuid
def test_02_timeoutExpired(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_09_handleSendPartitionTable(self):
packet = Packet(msg_type=SEND_PARTITION_TABLE)
uuid = self.getNewUUID()
# send a table
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID()
node_2 = self.getNewUUID()
node_3 = self.getNewUUID()
# SN already known one of the node
self.app.nm.add(StorageNode(uuid=node_1))
self.app.ptid = 1
self.app.num_partitions = 3
self.app.num_replicas =2
self.assertEqual(self.app.dm.getPartitionTable(), ())
row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))),
(1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))),
(2, ((node_2, UP_TO_DATE_STATE), (node_3, UP_TO_DATE_STATE)))]
self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled
self.verification.handleSendPartitionTable(conn, packet, "1", row_list[:1])
self.assertFalse(self.app.pt.filled())
self.assertEqual(self.app.ptid, "1")
self.assertEqual(self.app.dm.getPartitionTable(), ())
# send remaining of the table
self.verification.handleSendPartitionTable(conn, packet, "1", row_list[1:])
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.ptid, "1")
self.assertNotEqual(self.app.dm.getPartitionTable(), ())
# send a complete new table
self.verification.handleSendPartitionTable(conn, packet, "2", row_list)
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.ptid, "2")
self.assertNotEqual(self.app.dm.getPartitionTable(), ())
if __name__ == "__main__":
unittest.main()
......@@ -38,7 +38,7 @@ from neo.protocol import ANSWER_PRIMARY_MASTER
from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
class StorageVerificationTests(NeoTestBase):
class StorageVerificationHandlerTests(NeoTestBase):
def setUp(self):
logging.basicConfig(level = logging.ERROR)
......@@ -68,24 +68,7 @@ class StorageVerificationTests(NeoTestBase):
return self.uuid
# Tests
def test_01_connectionAccepted(self):
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
self.verification.connectionAccepted(conn, None, ("127.0.0.1", self.client_port))
# nothing happens
self.checkNoPacketSent(conn)
def test_02_timeoutExpired(self):
# listening connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.verification.timeoutExpired(conn)
# nothing happens
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
......@@ -96,15 +79,6 @@ class StorageVerificationTests(NeoTestBase):
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
# listening connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.verification.connectionClosed(conn)
# nothing happens
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
......@@ -114,17 +88,7 @@ class StorageVerificationTests(NeoTestBase):
# nothing happens
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
# listening connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.verification.peerBroken(conn)
# nothing happens
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
......@@ -134,128 +98,9 @@ class StorageVerificationTests(NeoTestBase):
# nothing happens
self.checkNoPacketSent(conn)
def test_05_handleRequestNodeIdentification(self):
# listening connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.checkNotReadyErrorRaised(
self.verification.handleRequestNodeIdentification,
conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
# not a master node
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.checkNotReadyErrorRaised(
self.verification.handleRequestNodeIdentification,
conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
# bad name
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.checkProtocolErrorRaised(
self.verification.handleRequestNodeIdentification,
conn, p, MASTER_NODE_TYPE, uuid, "127.0.0.1", self.client_port, "zatt")
# new node
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, "main")
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.checkAcceptNodeIdentification(conn)
self.checkAborted(conn)
# notify a node declared as broken
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
node = self.app.nm.getNodeByServer(conn.getAddress())
node.setState(BROKEN_STATE)
self.assertEqual(node.getUUID(), uuid)
self.checkBrokenNodeDisallowedErrorRaised(
self.verification.handleRequestNodeIdentification,
conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, "main")
# change uuid of a known node
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
node = self.app.nm.getNodeByServer(conn.getAddress())
node.setState(RUNNING_STATE)
self.assertNotEqual(node.getUUID(), uuid)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, "main")
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.checkAcceptNodeIdentification(conn)
self.checkAborted(conn)
def test_06_handleAcceptNodeIdentification(self):
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.checkUnexpectedPacketRaised(self.verification.handleAcceptNodeIdentification,
conn, p, CLIENT_NODE_TYPE, self.getNewUUID(),"127.0.0.1", self.client_port, 1009, 2, uuid)
def test_07_handleAnswerPrimaryMaster(self):
# reject server connection
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.checkUnexpectedPacketRaised(self.verification.handleAnswerPrimaryMaster, conn, packet,self.getNewUUID(), ())
# raise id uuid is different
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.app.primary_master_node = MasterNode(uuid=self.getNewUUID())
self.assertNotEqual(uuid, self.app.primary_master_node.getUUID())
self.assertRaises(PrimaryFailure, self.verification.handleAnswerPrimaryMaster, conn, packet,uuid, ())
# same uuid, do nothing
uuid = self.app.primary_master_node.getUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.assertEqual(uuid, self.app.primary_master_node.getUUID())
self.verification.handleAnswerPrimaryMaster(conn, packet,uuid, ())
def test_07_handleAskLastIDs(self):
# reject server connection
packet = Packet(msg_type=ASK_LAST_IDS)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.checkUnexpectedPacketRaised(self.verification.handleAskLastIDs, conn, packet)
packet = Mock()
# return invalid if db store nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -299,14 +144,8 @@ class StorageVerificationTests(NeoTestBase):
self.assertEqual(ptid, self.app.ptid)
def test_08_handleAskPartitionTable(self):
# reject server connection
packet = Packet(msg_type=ASK_PARTITION_TABLE)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.checkUnexpectedPacketRaised(self.verification.handleAskPartitionTable, conn, packet, [1,])
packet = Mock()
# try to get unknown offset
self.assertEqual(len(self.app.pt.getNodeList()), 0)
self.assertFalse(self.app.pt.hasOffset(1))
......@@ -335,63 +174,7 @@ class StorageVerificationTests(NeoTestBase):
self.assertEqual(offset, 1)
self.assertEqual(len(rows), 1)
def test_09_handleSendPartitionTable(self):
# reject server connection
packet = Packet(msg_type=SEND_PARTITION_TABLE)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.app.ptid = 1
self.checkUnexpectedPacketRaised(self.verification.handleSendPartitionTable, conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1)
# send a table
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID()
node_2 = self.getNewUUID()
node_3 = self.getNewUUID()
# SN already known one of the node
self.app.nm.add(StorageNode(uuid=node_1))
self.app.ptid = 1
self.app.num_partitions = 3
self.app.num_replicas =2
self.assertEqual(self.app.dm.getPartitionTable(), ())
row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))),
(1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))),
(2, ((node_2, UP_TO_DATE_STATE), (node_3, UP_TO_DATE_STATE)))]
self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled
self.verification.handleSendPartitionTable(conn, packet, "1", row_list[:1])
self.assertFalse(self.app.pt.filled())
self.assertEqual(self.app.ptid, "1")
self.assertEqual(self.app.dm.getPartitionTable(), ())
# send remaining of the table
self.verification.handleSendPartitionTable(conn, packet, "1", row_list[1:])
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.ptid, "1")
self.assertNotEqual(self.app.dm.getPartitionTable(), ())
# send a complete new table
self.verification.handleSendPartitionTable(conn, packet, "2", row_list)
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.ptid, "2")
self.assertNotEqual(self.app.dm.getPartitionTable(), ())
def test_10_handleNotifyPartitionChanges(self):
# reject server connection
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
self.app.ptid = 1
self.checkUnexpectedPacketRaised(self.verification.handleNotifyPartitionChanges, conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1)
# old partition change
conn = Mock({
"isServerConnection": False,
......@@ -423,10 +206,6 @@ class StorageVerificationTests(NeoTestBase):
self.assertEquals(calls[0].getParam(1), (cell, ))
def test_11_handleStartOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=STOP_OPERATION)
self.checkUnexpectedPacketRaised(self.verification.handleStartOperation, conn, packet)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
self.assertFalse(self.app.operational)
......@@ -435,21 +214,12 @@ class StorageVerificationTests(NeoTestBase):
self.assertTrue(self.app.operational)
def test_12_handleStopOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=STOP_OPERATION)
self.checkUnexpectedPacketRaised(self.verification.handleStopOperation, conn, packet)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
packet = Packet(msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet)
def test_13_handleAskUnfinishedTransactions(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.checkUnexpectedPacketRaised(self.verification.handleAskUnfinishedTransactions, conn, packet)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
......@@ -472,13 +242,6 @@ class StorageVerificationTests(NeoTestBase):
self.assertEqual(u64(tid_list[0]), 4)
def test_14_handleAskTransactionInformation(self):
# ask from server with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, TID_NOT_FOUND_CODE)
# ask from client conn with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
......@@ -541,11 +304,6 @@ class StorageVerificationTests(NeoTestBase):
self.assertEqual(code, TID_NOT_FOUND_CODE)
def test_15_handleAskObjectPresent(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.checkUnexpectedPacketRaised(self.verification.handleAskObjectPresent, conn, packet, p64(1), p64(2))
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
......@@ -568,11 +326,6 @@ class StorageVerificationTests(NeoTestBase):
self.assertEqual(u64(oid), 1)
def test_16_handleDeleteTransaction(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.checkUnexpectedPacketRaised(self.verification.handleDeleteTransaction, conn, packet, p64(1))
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
......@@ -588,14 +341,6 @@ class StorageVerificationTests(NeoTestBase):
self.assertEquals(len(result), 0)
def test_17_handleCommitTransaction(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_type=COMMIT_TRANSACTION)
self.checkUnexpectedPacketRaised(self.verification.handleCommitTransaction, conn, packet, p64(1))
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 0)
# commit a transaction
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
......@@ -608,22 +353,6 @@ class StorageVerificationTests(NeoTestBase):
tid = call.getParam(0)
self.assertEqual(u64(tid), 1)
def test_18_handleLockInformation(self):
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_type=LOCK_INFORMATION)
self.assertEquals(len(self.app.load_lock_dict), 0)
self.verification.handleLockInformation(conn, packet, p64(1))
self.assertEquals(len(self.app.load_lock_dict), 0)
def test_19_handleUnlockInformation(self):
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
self.app.load_lock_dict[p64(1)] = Mock()
packet = Packet(msg_type=UNLOCK_INFORMATION)
self.verification.handleUnlockInformation(conn, packet, p64(1))
self.assertEquals(len(self.app.load_lock_dict), 1)
if __name__ == "__main__":
unittest.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