Commit f2d36e8e authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move master/connector.py content into tests/__init__.py to be consistent with

the base test class placement.
Fix imports in test files for this modification the NeoTestBase class.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@980 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a13a11ba
...@@ -19,6 +19,7 @@ import os ...@@ -19,6 +19,7 @@ import os
import unittest import unittest
import tempfile import tempfile
import MySQLdb import MySQLdb
import logging
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
...@@ -323,3 +324,69 @@ class NeoTestBase(unittest.TestCase): ...@@ -323,3 +324,69 @@ class NeoTestBase(unittest.TestCase):
def checkAnswerObjectPresent(self, conn, **kw): def checkAnswerObjectPresent(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_PRESENT, **kw) return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_PRESENT, **kw)
# XXX: imported from neo.master.test.connector since it's used at many places
connector_cpt = 0
# master node with the highest uuid will be declared as PMN
previous_uuid = None
def getNewUUID():
uuid = protocol.INVALID_UUID
previous = globals()["previous_uuid"]
while uuid == protocol.INVALID_UUID or (previous is \
not None and uuid > previous):
uuid = os.urandom(16)
logging.info("previous > uuid %s"%(previous > uuid))
globals()["previous_uuid"] = uuid
return uuid
class DoNothingConnector(Mock):
def __init__(self, s=None):
logging.info("initializing connector")
self.desc = globals()['connector_cpt']
globals()['connector_cpt'] = globals()['connector_cpt']+ 1
self.packet_cpt = 0
Mock.__init__(self)
def getAddress(self):
return self.addr
def makeClientConnection(self, addr):
self.addr = addr
def getDescriptor(self):
return self.desc
class TestElectionConnector(DoNothingConnector):
def receive(self):
""" simulate behavior of election """
if self.packet_cpt == 0:
# first : identify
logging.info("in patched analyse / IDENTIFICATION")
p = protocol.Packet()
self.uuid = getNewUUID()
p.acceptNodeIdentification(1,
protocol.MASTER_NODE_TYPE,
self.uuid,
self.getAddress()[0],
self.getAddress()[1],
1009,
2
)
self.packet_cpt += 1
return p.encode()
elif self.packet_cpt == 1:
# second : answer primary master nodes
logging.info("in patched analyse / ANSWER PM")
p = protocol.Packet()
p.answerPrimaryMaster(2, protocol.INVALID_UUID, [])
self.packet_cpt += 1
return p.encode()
else:
# then do nothing
from neo.connector import ConnectorTryAgainException
raise ConnectorTryAgainException
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import unittest import unittest
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from ZODB.POSException import StorageTransactionError, UndoError, ConflictError from ZODB.POSException import StorageTransactionError, UndoError, ConflictError
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.client.app import Application from neo.client.app import Application
from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \ from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \
NEOStorageConflictError NEOStorageConflictError
...@@ -782,7 +782,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -782,7 +782,7 @@ class ClientApplicationTests(NeoTestBase):
# the third will not be ready # the third will not be ready
# after the third, the partition table will be operational # after the third, the partition table will be operational
# (as if it was connected to the primary master node) # (as if it was connected to the primary master node)
from neo.master.tests.connector import DoNothingConnector from neo.tests import DoNothingConnector
# will raise IndexError at the third iteration # will raise IndexError at the third iteration
app = self.getApp('127.0.0.1:10010 127.0.0.1:10011') app = self.getApp('127.0.0.1:10010 127.0.0.1:10011')
# TODO: test more connection failure cases # TODO: test more connection failure cases
......
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
import logging import logging
import threading import threading
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import UnexpectedPacketError, INVALID_UUID from neo.protocol import UnexpectedPacketError, INVALID_UUID
from neo.protocol import \ from neo.protocol import \
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import unittest import unittest
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.client.app import ConnectionPool from neo.client.app import ConnectionPool
class ConnectionPoolTests(NeoTestBase): class ConnectionPoolTests(NeoTestBase):
......
from mock import Mock
import logging
connector_cpt = 0
from neo.protocol import Packet, INVALID_UUID, MASTER_NODE_TYPE
import os
# master node with the highest uuid will be declared as PMN
previous_uuid = None
def getNewUUID():
uuid = INVALID_UUID
previous = globals()["previous_uuid"]
while uuid == INVALID_UUID or (previous is \
not None and uuid > previous):
uuid = os.urandom(16)
logging.info("previous > uuid %s"%(previous > uuid))
globals()["previous_uuid"] = uuid
return uuid
class DoNothingConnector(Mock):
def __init__(self, s=None):
logging.info("initializing connector")
self.desc = globals()['connector_cpt']
globals()['connector_cpt'] = globals()['connector_cpt']+ 1
self.packet_cpt = 0
Mock.__init__(self)
def getAddress(self):
return self.addr
def makeClientConnection(self, addr):
self.addr = addr
def getDescriptor(self):
return self.desc
class TestElectionConnector(DoNothingConnector):
def receive(self):
""" simulate behavior of election """
if self.packet_cpt == 0:
# first : identify
logging.info("in patched analyse / IDENTIFICATION")
p = Packet()
self.uuid = getNewUUID()
p.acceptNodeIdentification(1,
MASTER_NODE_TYPE,
self.uuid,
self.getAddress()[0],
self.getAddress()[1],
1009,
2
)
self.packet_cpt += 1
return p.encode()
elif self.packet_cpt == 1:
# second : answer primary master nodes
logging.info("in patched analyse / ANSWER PM")
p = Packet()
p.answerPrimaryMaster(2,
INVALID_UUID,
[]
)
self.packet_cpt += 1
return p.encode()
else:
# then do nothing
from neo.connector import ConnectorTryAgainException
raise ConnectorTryAgainException
...@@ -20,7 +20,7 @@ import unittest ...@@ -20,7 +20,7 @@ import unittest
import logging import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
......
...@@ -20,7 +20,7 @@ import unittest ...@@ -20,7 +20,7 @@ import unittest
import logging import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
...@@ -48,7 +48,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -48,7 +48,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode from neo.node import MasterNode, StorageNode
from neo.master.tests.connector import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
# patch connection so that we can register _addPacket messages # patch connection so that we can register _addPacket messages
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import unittest, logging, os import unittest, logging, os
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \ from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
BROKEN_STATE, INVALID_UUID BROKEN_STATE, INVALID_UUID
......
...@@ -20,7 +20,7 @@ import unittest ...@@ -20,7 +20,7 @@ import unittest
import logging import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.handlers.recovery import RecoveryHandler from neo.master.handlers.recovery import RecoveryHandler
...@@ -48,7 +48,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -48,7 +48,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
from neo.node import MasterNode, StorageNode from neo.node import MasterNode, StorageNode
from neo.master.tests.connector import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
class MasterRecoveryTests(NeoTestBase): class MasterRecoveryTests(NeoTestBase):
......
...@@ -20,7 +20,7 @@ import unittest ...@@ -20,7 +20,7 @@ import unittest
import logging import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
......
...@@ -21,7 +21,7 @@ import logging ...@@ -21,7 +21,7 @@ import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
import neo import neo
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.master.handlers.verification import VerificationHandler from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application from neo.master.app import Application
...@@ -35,7 +35,7 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -35,7 +35,7 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.node import MasterNode, StorageNode from neo.node import MasterNode, StorageNode
from neo.master.tests.connector import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
......
...@@ -21,7 +21,7 @@ import logging ...@@ -21,7 +21,7 @@ import logging
from struct import pack, unpack from struct import pack, unpack
from mock import Mock from mock import Mock
from collections import deque from collections import deque
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import MasterNode from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode from neo.storage.app import Application, StorageNode
from neo.storage.handlers.client import TransactionInformation from neo.storage.handlers.client import TransactionInformation
......
...@@ -19,7 +19,7 @@ import os ...@@ -19,7 +19,7 @@ import os
import unittest import unittest
import logging import logging
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.node import MasterNode from neo.node import MasterNode
from neo.pt import PartitionTable from neo.pt import PartitionTable
......
...@@ -21,7 +21,7 @@ import logging ...@@ -21,7 +21,7 @@ import logging
from struct import pack, unpack from struct import pack, unpack
from mock import Mock from mock import Mock
from collections import deque from collections import deque
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import MasterNode from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode from neo.storage.app import Application, StorageNode
from neo.storage.handlers.master import MasterOperationHandler from neo.storage.handlers.master import MasterOperationHandler
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import unittest, logging, os import unittest, logging, os
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_TID, \ from neo.protocol import INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE
......
...@@ -21,7 +21,7 @@ import logging ...@@ -21,7 +21,7 @@ import logging
from struct import pack, unpack from struct import pack, unpack
from mock import Mock from mock import Mock
from collections import deque from collections import deque
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import MasterNode from neo.master.app import MasterNode
from neo.storage.app import Application, StorageNode from neo.storage.app import Application, StorageNode
from neo.storage.handlers.storage import StorageOperationHandler from neo.storage.handlers.storage import StorageOperationHandler
......
...@@ -21,7 +21,7 @@ import logging ...@@ -21,7 +21,7 @@ import logging
import MySQLdb import MySQLdb
from mock import Mock from mock import Mock
from neo.protocol import * from neo.protocol import *
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
......
...@@ -19,7 +19,7 @@ import os ...@@ -19,7 +19,7 @@ import os
import unittest import unittest
import logging import logging
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.node import MasterNode from neo.node import MasterNode
from neo.pt import PartitionTable from neo.pt import PartitionTable
......
...@@ -19,7 +19,7 @@ import os ...@@ -19,7 +19,7 @@ import os
import unittest import unittest
import logging import logging
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import MasterNode from neo.master.app import MasterNode
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode from neo.storage.app import Application, StorageNode
......
...@@ -25,7 +25,7 @@ from neo.connection import BaseConnection, ListeningConnection, Connection, \ ...@@ -25,7 +25,7 @@ from neo.connection import BaseConnection, ListeningConnection, Connection, \
ClientConnection, ServerConnection, MTClientConnection, MTServerConnection ClientConnection, ServerConnection, MTClientConnection, MTServerConnection
from neo.connector import getConnectorHandler, registerConnectorHandler from neo.connector import getConnectorHandler, registerConnectorHandler
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.master.tests.connector import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connector import ConnectorException, ConnectorTryAgainException, \ from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException ConnectorInProgressException, ConnectorConnectionRefusedException
from neo.protocol import Packet, ProtocolError, PROTOCOL_ERROR_CODE, ERROR,INTERNAL_ERROR_CODE, \ from neo.protocol import Packet, ProtocolError, PROTOCOL_ERROR_CODE, ERROR,INTERNAL_ERROR_CODE, \
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from time import time from time import time
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.epoll import Epoll from neo.epoll import Epoll
from neo.event import EpollEventManager, IdleEvent from neo.event import EpollEventManager, IdleEvent
from neo.protocol import Packet, PING from neo.protocol import Packet, PING
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import unittest, os import unittest, os
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \ from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \
CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE
......
...@@ -22,7 +22,7 @@ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \ ...@@ -22,7 +22,7 @@ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
BROKEN_STATE, INVALID_UUID BROKEN_STATE, INVALID_UUID
from neo.pt import Cell, PartitionTable from neo.pt import Cell, PartitionTable
from neo.node import StorageNode from neo.node import StorageNode
from neo.tests.base import NeoTestBase from neo.tests import NeoTestBase
class PartitionTableTests(NeoTestBase): class PartitionTableTests(NeoTestBase):
......
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