Commit 2f580901 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix some unit tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1273 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 913bd7fa
......@@ -17,8 +17,9 @@
import unittest, os
from mock import Mock
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
BROKEN_STATE, UNKNOWN_STATE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \
CLIENT_NODE_TYPE, INVALID_UUID
from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager
from neo.tests import NeoTestBase
from time import time
......@@ -36,13 +37,15 @@ class NodesTests(NeoTestBase):
server = ("127.0.0.1", 10000)
uuid = self.getNewUUID()
node = Node(server, uuid)
self.assertEqual(node.state, RUNNING_STATE)
manager = Mock()
node.setManager(manager)
self.assertEqual(node.state, UNKNOWN_STATE)
self.assertEqual(node.server, server)
self.assertEqual(node.uuid, uuid)
self.assertEqual(node.manager, None)
self.assertEqual(node.manager, manager)
self.assertNotEqual(node.last_state_change, None)
# test getter
self.assertEqual(node.getState(), RUNNING_STATE)
self.assertEqual(node.getState(), UNKNOWN_STATE)
self.assertEqual(node.getServer(), server)
self.assertEqual(node.getUUID(), uuid)
self.assertRaises(NotImplementedError, node.getType)
......
......@@ -19,7 +19,7 @@ import unittest, os
from mock import Mock
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
BROKEN_STATE, INVALID_UUID
BROKEN_STATE, INVALID_UUID, UNKNOWN_STATE
from neo.pt import Cell, PartitionTable
from neo.node import StorageNode
from neo.tests import NeoTestBase
......@@ -39,7 +39,7 @@ class PartitionTableTests(NeoTestBase):
# check getter
self.assertEquals(cell.getNode(), sn)
self.assertEquals(cell.getState(), OUT_OF_DATE_STATE)
self.assertEquals(cell.getNodeState(), RUNNING_STATE)
self.assertEquals(cell.getNodeState(), UNKNOWN_STATE)
self.assertEquals(cell.getUUID(), uuid)
self.assertEquals(cell.getServer(), server)
# check state setter
......@@ -332,6 +332,7 @@ class PartitionTableTests(NeoTestBase):
pt.setCell(x, sn1, UP_TO_DATE_STATE)
self.assertTrue(pt.filled())
# it's up to date and running, so operational
sn1.setState(RUNNING_STATE)
self.assertTrue(pt.operational())
# same with feeding state
pt.clear()
......@@ -344,7 +345,8 @@ class PartitionTableTests(NeoTestBase):
for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE)
self.assertTrue(pt.filled())
# it's up to date and running, so operational
# it's feeding and running, so operational
sn1.setState(RUNNING_STATE)
self.assertTrue(pt.operational())
# same with feeding state but non running node
......
......@@ -60,9 +60,9 @@ class ProtocolTests(NeoTestBase):
self.assertEqual(len(p), PACKET_HEADER_SIZE)
def test_02_error(self):
p = protocol._error(10, "error message")
p = protocol._error(0, "error message")
code, msg = protocol._decodeError(p._body)
self.assertEqual(code, 10)
self.assertEqual(code, protocol.NO_ERROR_CODE)
self.assertEqual(msg, "error message")
def test_03_protocolError(self):
......@@ -282,8 +282,14 @@ class ProtocolTests(NeoTestBase):
def test_32_askBeginTransaction(self):
p = protocol.askBeginTransaction()
self.assertEqual(p.decode(), None)
# try with an invalid TID, None must be returned
tid = '\0' * 8
p = protocol.askBeginTransaction(tid)
self.assertEqual(p.decode(), (None, ))
# and with another TID
tid = '\1' * 8
p = protocol.askBeginTransaction(tid)
self.assertEqual(p.decode(), (tid, ))
def test_33_answerBeginTransaction(self):
tid = self.getNextTID()
......
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