Commit 8f08613c authored by Grégory Wisniewski's avatar Grégory Wisniewski

As previous commits, use new Enum class for cell states.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1339 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6d746894
......@@ -868,8 +868,8 @@ class Application(object):
last = first - last
# First get a list of transactions from all storage nodes.
# Each storage node will return TIDs only for UP_TO_DATE_STATE and
# FEEDING_STATE cells
# Each storage node will return TIDs only for UP_TO_DATE state and
# FEEDING state cells
pt = self._getPartitionTable()
storage_node_list = pt.getNodeList()
......
......@@ -18,10 +18,9 @@
from neo import logging
from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, OUT_OF_DATE_STATE, INTERNAL_ERROR_CODE
from neo.protocol import INTERNAL_ERROR_CODE
from neo.protocol import UnexpectedPacketError, CellStates
from neo.master.handlers import BaseServiceHandler
from neo.protocol import UnexpectedPacketError
from neo.exception import OperationFailure
from neo.util import dump
......@@ -90,7 +89,7 @@ class StorageServiceHandler(BaseServiceHandler):
new_cell_list = []
for cell in cell_list:
if cell[2] != UP_TO_DATE_STATE:
if cell[2] != CellStates.UP_TO_DATE:
logging.warn('only up-to-date state should be sent')
continue
......@@ -104,7 +103,8 @@ class StorageServiceHandler(BaseServiceHandler):
# check the storage said it is up to date for a partition it was assigne to
for xcell in app.pt.getCellList(offset):
if xcell.getNode().getUUID() == node.getUUID() and \
xcell.getState() not in (OUT_OF_DATE_STATE, UP_TO_DATE_STATE):
xcell.getState() not in (CellStates.OUT_OF_DATE,
CellStates.UP_TO_DATE):
msg = "node %s telling that it is UP TO DATE for offset \
%s but where %s for that offset" % (dump(node.getUUID()), offset,
xcell.getState())
......@@ -113,15 +113,15 @@ class StorageServiceHandler(BaseServiceHandler):
return
app.pt.setCell(offset, node, UP_TO_DATE_STATE)
app.pt.setCell(offset, node, CellStates.UP_TO_DATE)
new_cell_list.append(cell)
# If the partition contains a feeding cell, drop it now.
for feeding_cell in app.pt.getCellList(offset):
if feeding_cell.getState() == FEEDING_STATE:
if feeding_cell.getState() == CellStates.FEEDING:
app.pt.removeCell(offset, feeding_cell.getNode())
new_cell_list.append((offset, feeding_cell.getUUID(),
DISCARDED_STATE))
CellStates.DISCARDED))
break
if new_cell_list:
......
......@@ -17,7 +17,7 @@
import neo.pt
from struct import pack, unpack
from neo.protocol import OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.protocol import CellStates
class PartitionTable(neo.pt.PartitionTable):
"""This class manages a partition table for the primary master node"""
......@@ -88,12 +88,12 @@ class PartitionTable(neo.pt.PartitionTable):
node_list = [c.getNode() for c in row]
n = self.findLeastUsedNode(node_list)
if n is not None:
row.append(neo.pt.Cell(n, OUT_OF_DATE_STATE))
row.append(neo.pt.Cell(n, CellStates.OUT_OF_DATE))
self.count_dict[n] += 1
cell_list.append((offset, n.getUUID(),
OUT_OF_DATE_STATE))
CellStates.OUT_OF_DATE))
row.remove(cell)
cell_list.append((offset, uuid, DISCARDED_STATE))
cell_list.append((offset, uuid, CellStates.DISCARDED))
break
try:
......@@ -134,8 +134,8 @@ class PartitionTable(neo.pt.PartitionTable):
continue
if num_cells <= self.nr:
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE))
cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE))
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), CellStates.OUT_OF_DATE))
node_count += 1
else:
if max_count - node_count > 1:
......@@ -144,18 +144,18 @@ class PartitionTable(neo.pt.PartitionTable):
# out-of-date, just drop the node.
row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(),
DISCARDED_STATE))
CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1
else:
# Otherwise, use it as a feeding cell for safety.
max_cell.setState(FEEDING_STATE)
max_cell.setState(CellStates.FEEDING)
cell_list.append((offset, max_cell.getUUID(),
FEEDING_STATE))
CellStates.FEEDING))
# Don't count a feeding cell.
self.count_dict[max_cell.getNode()] -= 1
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE))
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(),
OUT_OF_DATE_STATE))
CellStates.OUT_OF_DATE))
node_count += 1
self.count_dict[node] = node_count
......@@ -220,7 +220,7 @@ class PartitionTable(neo.pt.PartitionTable):
row.remove(cell)
if not cell.isFeeding():
self.count_dict[cell.getNode()] -= 1
changed_cell_list.append((offset, cell.getUUID(), DISCARDED_STATE))
changed_cell_list.append((offset, cell.getUUID(), CellStates.DISCARDED))
# Add cells, if a row contains less than the number of replicas.
for offset, row in enumerate(self.partition_list):
......@@ -232,8 +232,8 @@ class PartitionTable(neo.pt.PartitionTable):
node = self.findLeastUsedNode([cell.getNode() for cell in row])
if node is None:
break
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE))
changed_cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE))
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
changed_cell_list.append((offset, node.getUUID(), CellStates.OUT_OF_DATE))
self.count_dict[node] += 1
num_cells += 1
......@@ -250,7 +250,7 @@ class PartitionTable(neo.pt.PartitionTable):
for offset, row in enumerate(self.partition_list):
for cell in row:
if not cell.getNode().isRunning() and not cell.isOutOfDate():
cell.setState(OUT_OF_DATE_STATE)
cell_list.append((offset, cell.getUUID(), OUT_OF_DATE_STATE))
cell.setState(CellStates.OUT_OF_DATE)
cell_list.append((offset, cell.getUUID(), CellStates.OUT_OF_DATE))
return cell_list
......@@ -318,26 +318,21 @@ error_codes = OldEnum({
})
class ClusterStates(Enum):
BOOTING = Enum.Item(1)
RECOVERING = Enum.Item(2)
VERIFYING = Enum.Item(3)
RUNNING = Enum.Item(4)
STOPPING = Enum.Item(5)
ClusterStates = ClusterStates()
class NodeTypes(Enum):
MASTER = Enum.Item(1)
STORAGE = Enum.Item(2)
CLIENT = Enum.Item(3)
ADMIN = Enum.Item(4)
NodeTypes = NodeTypes()
class NodeStates(Enum):
RUNNING = Enum.Item(1)
TEMPORARILY_DOWN = Enum.Item(2)
DOWN = Enum.Item(3)
......@@ -345,9 +340,15 @@ class NodeStates(Enum):
HIDDEN = Enum.Item(5)
PENDING = Enum.Item(6)
UNKNOWN = Enum.Item(7)
NodeStates = NodeStates()
class CellStates(Enum):
UP_TO_DATE = Enum.Item(1)
OUT_OF_DATE = Enum.Item(2)
FEEDING = Enum.Item(3)
DISCARDED = Enum.Item(4)
CellStates = CellStates()
# used for logging
node_state_prefix_dict = {
NodeStates.RUNNING: 'R',
......@@ -359,20 +360,12 @@ node_state_prefix_dict = {
NodeStates.UNKNOWN: 'U',
}
# Partition cell states.
cell_states = OldEnum({
'UP_TO_DATE_STATE': 0,
'OUT_OF_DATE_STATE': 1,
'FEEDING_STATE': 2,
'DISCARDED_STATE': 3,
})
# used for logging
cell_state_prefix_dict = {
UP_TO_DATE_STATE: 'U',
OUT_OF_DATE_STATE: 'O',
FEEDING_STATE: 'F',
DISCARDED_STATE: 'D',
CellStates.UP_TO_DATE: 'U',
CellStates.OUT_OF_DATE: 'O',
CellStates.FEEDING: 'F',
CellStates.DISCARDED: 'D',
}
# Other constants.
......@@ -693,7 +686,7 @@ def _decodeAnswerPartitionTable(body):
for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18])
index += 18
state = cell_states.get(state)
state = CellStates.get(state)
uuid = _decodeUUID(uuid)
cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list)))
......@@ -714,7 +707,7 @@ def _decodeSendPartitionTable(body):
for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18])
index += 18
state = cell_states.get(state)
state = CellStates.get(state)
uuid = _decodeUUID(uuid)
cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list)))
......@@ -729,7 +722,7 @@ def _decodeNotifyPartitionChanges(body):
cell_list = []
for i in xrange(n):
(offset, uuid, state) = unpack('!L16sH', body[12+i*22:34+i*22])
state = cell_states.get(state)
state = CellStates.get(state)
uuid = _decodeUUID(uuid)
cell_list.append((offset, uuid, state))
return ptid, cell_list
......@@ -1012,7 +1005,7 @@ def _decodeAnswerPartitionList(body):
for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18])
index += 18
state = cell_states.get(state)
state = CellStates.get(state)
uuid = _decodeUUID(uuid)
cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list)))
......
......@@ -18,6 +18,7 @@
from neo import logging
from neo import protocol
from neo.protocol import CellStates
from neo.util import dump, u64
from neo.locking import RLock
......@@ -25,7 +26,7 @@ from neo.locking import RLock
class Cell(object):
"""This class represents a cell in a partition table."""
def __init__(self, node, state = protocol.UP_TO_DATE_STATE):
def __init__(self, node, state = CellStates.UP_TO_DATE):
self.node = node
self.state = state
......@@ -36,13 +37,13 @@ class Cell(object):
self.state = state
def isUpToDate(self):
return self.state == protocol.UP_TO_DATE_STATE
return self.state == CellStates.UP_TO_DATE
def isOutOfDate(self):
return self.state == protocol.OUT_OF_DATE_STATE
return self.state == CellStates.OUT_OF_DATE
def isFeeding(self):
return self.state == protocol.FEEDING_STATE
return self.state == CellStates.FEEDING
def getNode(self):
return self.node
......@@ -107,13 +108,13 @@ class PartitionTable(object):
def getCellList(self, offset, readable=False, writable=False):
# allow all cell states
state_set = set(protocol.cell_states.values())
state_set = set(CellStates.values())
if readable or writable:
# except non readables
state_set.remove(protocol.DISCARDED_STATE)
state_set.remove(CellStates.DISCARDED)
if readable:
# except non writables
state_set.remove(protocol.OUT_OF_DATE_STATE)
state_set.remove(CellStates.OUT_OF_DATE)
allowed_states = tuple(state_set)
try:
return [cell for cell in self.partition_list[offset] \
......@@ -133,7 +134,7 @@ class PartitionTable(object):
return index % self.np
def setCell(self, offset, node, state):
if state == protocol.DISCARDED_STATE:
if state == CellStates.DISCARDED:
return self.removeCell(offset, node)
if node.isBroken() or node.isDown():
return
......@@ -143,7 +144,7 @@ class PartitionTable(object):
if len(row) == 0:
# Create a new row.
row = [Cell(node, state), ]
if state != protocol.FEEDING_STATE:
if state != CellStates.FEEDING:
self.count_dict[node] += 1
self.partition_list[offset] = row
......@@ -158,7 +159,7 @@ class PartitionTable(object):
self.count_dict[node] -= 1
break
row.append(Cell(node, state))
if state != protocol.FEEDING_STATE:
if state != CellStates.FEEDING:
self.count_dict[node] += 1
def removeCell(self, offset, node):
......@@ -220,7 +221,7 @@ class PartitionTable(object):
DEBUG:root:pt: 00000009: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U
Here, there are 4 nodes in RUNNING state.
The first partition has 2 replicas in UP_TO_DATE_STATE, on nodes 1 and
The first partition has 2 replicas in UP_TO_DATE state, on nodes 1 and
2 (nodes 0 and 3 are displayed as unused for that partition by
displaying a dot).
The 8-digits number on the left represents the number of the first
......
......@@ -20,7 +20,7 @@ import sys
from collections import deque
from neo import protocol
from neo.protocol import NodeTypes
from neo.protocol import NodeTypes, CellStates
from neo.node import NodeManager
from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager
......@@ -132,7 +132,7 @@ class Application(object):
new_cell_list = []
for offset, uuid, state in cell_list:
# convert from int to Enum
state = protocol.cell_states[state]
state = CellStates[state]
# register unknown nodes
if self.nm.getByUUID(uuid) is None:
self.nm.createStorage(uuid=uuid)
......
......@@ -18,8 +18,7 @@
from neo import logging
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.protocol import NodeTypes, NodeStates
from neo.protocol import NodeTypes, NodeStates, CellStates
class HiddenHandler(BaseMasterHandler):
"""This class implements a generic part of the event handlers."""
......@@ -81,9 +80,9 @@ class HiddenHandler(BaseMasterHandler):
for offset, uuid, state in cell_list:
if uuid == app.uuid and app.replicator is not None:
# If this is for myself, this can affect replications.
if state == DISCARDED_STATE:
if state == CellStates.DISCARDED:
app.replicator.removePartition(offset)
elif state == OUT_OF_DATE_STATE:
elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset)
def handleStartOperation(self, conn, packet):
......
......@@ -18,8 +18,8 @@
from neo import logging
from neo import protocol
from neo.protocol import CellStates
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.exception import OperationFailure
......@@ -52,9 +52,9 @@ class MasterOperationHandler(BaseMasterHandler):
for offset, uuid, state in cell_list:
if uuid == app.uuid and app.replicator is not None:
# If this is for myself, this can affect replications.
if state == DISCARDED_STATE:
if state == CellStates.DISCARDED:
app.replicator.removePartition(offset)
elif state == OUT_OF_DATE_STATE:
elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset)
def handleLockInformation(self, conn, packet, tid):
......
......@@ -25,7 +25,7 @@ from struct import pack, unpack
from neo.storage.database import DatabaseManager
from neo.exception import DatabaseFailure
from neo.protocol import DISCARDED_STATE
from neo.protocol import CellStates
from neo import util
LOG_QUERIES = False
......@@ -362,7 +362,7 @@ class MySQLDatabaseManager(DatabaseManager):
q("""TRUNCATE pt""")
for offset, uuid, state in cell_list:
uuid = e(util.dump(uuid))
if state == DISCARDED_STATE:
if state == CellStates.DISCARDED:
q("""DELETE FROM pt WHERE rid = %d AND uuid = '%s'""" \
% (offset, uuid))
else:
......
......@@ -20,8 +20,7 @@ from random import choice
from neo.storage.handlers import replication
from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE
from neo.protocol import NodeTypes, NodeStates
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.connection import ClientConnection
from neo.util import dump
......@@ -107,7 +106,7 @@ class Replicator(object):
partition_dict = {}
for offset in xrange(app.pt.getPartitions()):
for uuid, state in app.pt.getRow(offset):
if uuid == app.uuid and state == OUT_OF_DATE_STATE:
if uuid == app.uuid and state == CellStates.OUT_OF_DATE:
partition_dict[offset] = Partition(offset)
return partition_dict
......@@ -197,7 +196,7 @@ class Replicator(object):
# Notify to a primary master node that my cell is now up-to-date.
conn = self.primary_master_connection
p = protocol.notifyPartitionChanges(app.pt.getID(),
[(self.current_partition.getRID(), app.uuid, UP_TO_DATE_STATE)])
[(self.current_partition.getRID(), app.uuid, CellStates.UP_TO_DATE)])
conn.notify(p)
except KeyError:
pass
......
......@@ -23,8 +23,7 @@ from neo.tests import NeoTestBase
from neo import protocol
from neo.pt import PartitionTable
from neo.protocol import UnexpectedPacketError, INVALID_UUID
from neo.protocol import NodeTypes, NodeStates, INVALID_PTID, \
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.protocol import NodeTypes, NodeStates, CellStates, INVALID_PTID
from neo.client.handlers import BaseHandler
from neo.client.handlers.master import PrimaryBootstrapHandler
from neo.client.handlers.master import PrimaryNotificationsHandler, PrimaryAnswersHandler
......@@ -722,7 +721,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection(uuid=test_master_uuid)
test_storage_uuid = self.getNewUUID()
# TODO: use realistic values
test_cell_list = [(0, test_storage_uuid, UP_TO_DATE_STATE)]
test_cell_list = [(0, test_storage_uuid, CellStates.UP_TO_DATE)]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that a new node got added
add_call_list = app.nm.mockGetNamedCalls('add')
......@@ -751,10 +750,10 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=uuid1)
test_cell_list = [
(0, uuid1, UP_TO_DATE_STATE),
(0, uuid2, DISCARDED_STATE),
(0, uuid3, FEEDING_STATE),
(0, uuid4, UP_TO_DATE_STATE),
(0, uuid1, CellStates.UP_TO_DATE),
(0, uuid2, CellStates.DISCARDED),
(0, uuid3, CellStates.FEEDING),
(0, uuid4, CellStates.UP_TO_DATE),
]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that the three last node got added
......
......@@ -15,8 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo import protocol
import os
import sys
import time
......@@ -28,7 +26,8 @@ import unittest
import tempfile
import traceback
from neo.protocol import ClusterStates, NodeTypes
from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.protocol import ClusterStates, NodeTypes, CellStates
from neo.client.Storage import Storage
from neo.tests import getNewUUID
from neo.util import dump
......@@ -411,7 +410,7 @@ class NEOCluster(object):
number_of_oudated = 0
for row in row_list:
for cell in row[1]:
if cell[1] == protocol.OUT_OF_DATE_STATE:
if cell[1] == CellStates.OUT_OF_DATE:
number_of_oudated += 1
return number_of_oudated == number, number_of_oudated
self.expectCondition(callback, timeout, delay)
......
......@@ -18,9 +18,7 @@
import unittest, os
from mock import Mock
from neo.tests import NeoTestBase
from neo.protocol import NodeStates
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, INVALID_UUID
from neo.protocol import NodeStates, CellStates
from neo.pt import Cell
from neo.master.pt import PartitionTable
from neo.node import StorageNode
......@@ -73,18 +71,18 @@ class MasterPartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn2, UP_TO_DATE_STATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(1, sn2, CellStates.UP_TO_DATE)
uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, UP_TO_DATE_STATE)
pt.setCell(0, sn3, CellStates.UP_TO_DATE)
# test
node = pt.findLeastUsedNode()
self.assertEqual(node, sn3)
......@@ -114,15 +112,15 @@ class MasterPartitionTableTests(NeoTestBase):
num_partitions = 5
num_replicas = 3
pt = PartitionTable(num_partitions, num_replicas)
pt.setCell(0, sn1, OUT_OF_DATE_STATE)
pt.setCell(0, sn1, CellStates.OUT_OF_DATE)
sn1.setState(NodeStates.RUNNING)
pt.setCell(1, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn2, CellStates.UP_TO_DATE)
sn2.setState(NodeStates.TEMPORARILY_DOWN)
pt.setCell(2, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn3, CellStates.UP_TO_DATE)
sn3.setState(NodeStates.DOWN)
pt.setCell(3, sn4, UP_TO_DATE_STATE)
pt.setCell(3, sn4, CellStates.UP_TO_DATE)
sn4.setState(NodeStates.BROKEN)
pt.setCell(4, sn5, UP_TO_DATE_STATE)
pt.setCell(4, sn5, CellStates.UP_TO_DATE)
sn5.setState(NodeStates.RUNNING)
# outdate nodes
cells_outdated = pt.outdate()
......@@ -130,33 +128,33 @@ class MasterPartitionTableTests(NeoTestBase):
for offset, uuid, state in cells_outdated:
self.failUnless(offset in (1,2,3))
self.failUnless(uuid in (uuid2,uuid3,uuid4))
self.assertEqual(state, OUT_OF_DATE_STATE)
self.assertEqual(state, CellStates.OUT_OF_DATE)
# check each cell
# part 1, already outdated
cells = pt.getCellList(0)
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
# part 2, must be outdated
cells = pt.getCellList(1)
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
# part 3, must be outdated
cells = pt.getCellList(2)
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
# part 4, already outdated
cells = pt.getCellList(3)
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
# part 5, remains running
cells = pt.getCellList(4)
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
def test_14_addNode(self):
num_partitions = 5
......@@ -172,7 +170,7 @@ class MasterPartitionTableTests(NeoTestBase):
# it must be added to all partitions
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 1)
self.assertEqual(pt.getCellList(x)[0].getState(), OUT_OF_DATE_STATE)
self.assertEqual(pt.getCellList(x)[0].getState(), CellStates.OUT_OF_DATE)
self.assertEqual(pt.getCellList(x)[0].getNode(), sn1)
self.assertEqual(pt.count_dict[sn1], 5)
# add same node again, must remain the same
......@@ -180,7 +178,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cell_list), 0)
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 1)
self.assertEqual(pt.getCellList(x)[0].getState(), OUT_OF_DATE_STATE)
self.assertEqual(pt.getCellList(x)[0].getState(), CellStates.OUT_OF_DATE)
self.assertEqual(pt.getCellList(x)[0].getNode(), sn1)
self.assertEqual(pt.count_dict[sn1], 5)
# add a second node to fill the partition table
......@@ -192,7 +190,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cell_list), 5)
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 2)
self.assertEqual(pt.getCellList(x)[0].getState(), OUT_OF_DATE_STATE)
self.assertEqual(pt.getCellList(x)[0].getState(), CellStates.OUT_OF_DATE)
self.failUnless(pt.getCellList(x)[0].getNode() in (sn1, sn2))
# test the most used node is remove from some partition
uuid3 = self.getNewUUID()
......@@ -213,14 +211,14 @@ class MasterPartitionTableTests(NeoTestBase):
num_replicas = 1
pt = PartitionTable(num_partitions, num_replicas)
# node most used is out of date, just dropped
pt.setCell(0, sn1, OUT_OF_DATE_STATE)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn1, OUT_OF_DATE_STATE)
pt.setCell(1, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, OUT_OF_DATE_STATE)
pt.setCell(2, sn4, UP_TO_DATE_STATE)
pt.setCell(3, sn1, OUT_OF_DATE_STATE)
pt.setCell(3, sn5, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.OUT_OF_DATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(1, sn1, CellStates.OUT_OF_DATE)
pt.setCell(1, sn3, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.OUT_OF_DATE)
pt.setCell(2, sn4, CellStates.UP_TO_DATE)
pt.setCell(3, sn1, CellStates.OUT_OF_DATE)
pt.setCell(3, sn5, CellStates.UP_TO_DATE)
uuid6 = self.getNewUUID()
server6 = ("127.0.0.6", 19006)
sn6 = StorageNode(Mock(), server6, uuid6)
......@@ -230,9 +228,9 @@ class MasterPartitionTableTests(NeoTestBase):
for offset, uuid, state in cell_list:
if offset in (0,1):
if uuid == uuid1:
self.assertEqual(state, DISCARDED_STATE)
self.assertEqual(state, CellStates.DISCARDED)
elif uuid == uuid6:
self.assertEqual(state, OUT_OF_DATE_STATE)
self.assertEqual(state, CellStates.OUT_OF_DATE)
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
......@@ -241,27 +239,27 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getCellList(x)), 2)
# there is a feeding cell, just dropped
pt.clear()
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(0, sn3, FEEDING_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn2, FEEDING_STATE)
pt.setCell(1, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn4, FEEDING_STATE)
pt.setCell(2, sn5, UP_TO_DATE_STATE)
pt.setCell(3, sn1, UP_TO_DATE_STATE)
pt.setCell(3, sn4, UP_TO_DATE_STATE)
pt.setCell(3, sn5, FEEDING_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(0, sn3, CellStates.FEEDING)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn2, CellStates.FEEDING)
pt.setCell(1, sn3, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn4, CellStates.FEEDING)
pt.setCell(2, sn5, CellStates.UP_TO_DATE)
pt.setCell(3, sn1, CellStates.UP_TO_DATE)
pt.setCell(3, sn4, CellStates.UP_TO_DATE)
pt.setCell(3, sn5, CellStates.FEEDING)
cell_list = pt.addNode(sn6)
# sn1 is removed twice and sn6 is added twice
self.assertEqual(len(cell_list), 4)
for offset, uuid, state in cell_list:
if offset in (0,1):
if uuid == uuid1:
self.assertEqual(state, DISCARDED_STATE)
self.assertEqual(state, CellStates.DISCARDED)
elif uuid == uuid6:
self.assertEqual(state, OUT_OF_DATE_STATE)
self.assertEqual(state, CellStates.OUT_OF_DATE)
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
......@@ -270,23 +268,23 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getCellList(x)), 3)
# there is no feeding cell, marked as feeding
pt.clear()
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn4, UP_TO_DATE_STATE)
pt.setCell(3, sn1, UP_TO_DATE_STATE)
pt.setCell(3, sn5, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn3, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn4, CellStates.UP_TO_DATE)
pt.setCell(3, sn1, CellStates.UP_TO_DATE)
pt.setCell(3, sn5, CellStates.UP_TO_DATE)
cell_list = pt.addNode(sn6)
# sn1 is removed twice and sn6 is added twice
self.assertEqual(len(cell_list), 4)
for offset, uuid, state in cell_list:
if offset in (0,1):
if uuid == uuid1:
self.assertEqual(state, FEEDING_STATE)
self.assertEqual(state, CellStates.FEEDING)
elif uuid == uuid6:
self.assertEqual(state, OUT_OF_DATE_STATE)
self.assertEqual(state, CellStates.OUT_OF_DATE)
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
......@@ -318,22 +316,22 @@ class MasterPartitionTableTests(NeoTestBase):
# 3 : sn1, sn4
# node is not feeding, so retrive least use node to replace it
# so sn2 must be repaced by sn4 in partition 0
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn3, UP_TO_DATE_STATE)
pt.setCell(3, sn1, UP_TO_DATE_STATE)
pt.setCell(3, sn4, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn3, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn3, CellStates.UP_TO_DATE)
pt.setCell(3, sn1, CellStates.UP_TO_DATE)
pt.setCell(3, sn4, CellStates.UP_TO_DATE)
cell_list = pt.dropNode(sn2)
self.assertEqual(len(cell_list), 2)
for offset, uuid, state in cell_list:
self.assertEqual(offset, 0)
if uuid == uuid2:
self.assertEqual(state, DISCARDED_STATE)
self.assertEqual(state, CellStates.DISCARDED)
elif uuid == uuid4:
self.assertEqual(state, OUT_OF_DATE_STATE)
self.assertEqual(state, CellStates.OUT_OF_DATE)
else:
self.failUnless(uuid in (uuid2, uuid4))
......@@ -341,19 +339,19 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getCellList(x)), 2)
# same test but with feeding state, no other will be added
pt.clear()
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn2, FEEDING_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn3, UP_TO_DATE_STATE)
pt.setCell(3, sn1, UP_TO_DATE_STATE)
pt.setCell(3, sn4, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(0, sn2, CellStates.FEEDING)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn3, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn3, CellStates.UP_TO_DATE)
pt.setCell(3, sn1, CellStates.UP_TO_DATE)
pt.setCell(3, sn4, CellStates.UP_TO_DATE)
cell_list = pt.dropNode(sn2)
self.assertEqual(len(cell_list), 1)
for offset, uuid, state in cell_list:
self.assertEqual(offset, 0)
self.assertEqual(state, DISCARDED_STATE)
self.assertEqual(state, CellStates.DISCARDED)
self.assertEqual(uuid ,uuid2)
for x in xrange(num_replicas):
if x == 0:
......@@ -445,35 +443,35 @@ class MasterPartitionTableTests(NeoTestBase):
num_replicas = 2
pt = PartitionTable(num_partitions, num_replicas)
# part 0
pt.setCell(0, sn1, DISCARDED_STATE)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.DISCARDED)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
# part 1
pt.setCell(1, sn1, FEEDING_STATE)
pt.setCell(1, sn2, FEEDING_STATE)
pt.setCell(1, sn3, OUT_OF_DATE_STATE)
pt.setCell(1, sn1, CellStates.FEEDING)
pt.setCell(1, sn2, CellStates.FEEDING)
pt.setCell(1, sn3, CellStates.OUT_OF_DATE)
# part 2
pt.setCell(2, sn1, FEEDING_STATE)
pt.setCell(2, sn2, UP_TO_DATE_STATE)
pt.setCell(2, sn3, UP_TO_DATE_STATE)
pt.setCell(2, sn1, CellStates.FEEDING)
pt.setCell(2, sn2, CellStates.UP_TO_DATE)
pt.setCell(2, sn3, CellStates.UP_TO_DATE)
# part 3
pt.setCell(3, sn1, UP_TO_DATE_STATE)
pt.setCell(3, sn2, UP_TO_DATE_STATE)
pt.setCell(3, sn3, UP_TO_DATE_STATE)
pt.setCell(3, sn4, UP_TO_DATE_STATE)
pt.setCell(3, sn1, CellStates.UP_TO_DATE)
pt.setCell(3, sn2, CellStates.UP_TO_DATE)
pt.setCell(3, sn3, CellStates.UP_TO_DATE)
pt.setCell(3, sn4, CellStates.UP_TO_DATE)
# part 4
pt.setCell(4, sn1, UP_TO_DATE_STATE)
pt.setCell(4, sn5, UP_TO_DATE_STATE)
pt.setCell(4, sn1, CellStates.UP_TO_DATE)
pt.setCell(4, sn5, CellStates.UP_TO_DATE)
# now tweak the table
pt.tweak()
# check part 1
cells = pt.getCellList(0)
self.assertEqual(len(cells), 3)
for cell in cells:
self.assertNotEqual(cell.getState(), DISCARDED_STATE)
self.assertNotEqual(cell.getState(), CellStates.DISCARDED)
if cell.getNode() == sn2:
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
else:
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn2 in [x.getNode() for x in cells])
# check part 2
......@@ -481,9 +479,9 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cells), 4)
for cell in cells:
if cell.getNode() == sn1:
self.assertEqual(cell.getState(), FEEDING_STATE)
self.assertEqual(cell.getState(), CellStates.FEEDING)
else:
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn3 in [x.getNode() for x in cells])
self.failUnless(sn1 in [x.getNode() for x in cells])
......@@ -492,9 +490,9 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cells), 3)
for cell in cells:
if cell.getNode() in (sn2, sn3):
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
else:
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn3 in [x.getNode() for x in cells])
self.failUnless(sn2 in [x.getNode() for x in cells])
......@@ -502,16 +500,16 @@ class MasterPartitionTableTests(NeoTestBase):
cells = pt.getCellList(3)
self.assertEqual(len(cells), 3)
for cell in cells:
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
# check part 5
cells = pt.getCellList(4)
self.assertEqual(len(cells), 3)
for cell in cells:
if cell.getNode() in (sn1, sn5):
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
else:
self.assertEqual(cell.getState(), OUT_OF_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn1 in [x.getNode() for x in cells])
self.failUnless(sn5 in [x.getNode() for x in cells])
......
......@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
......@@ -39,11 +39,8 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
ASK_OIDS, ANSWER_OIDS, NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, INTERNAL_ERROR_CODE
from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -209,28 +206,28 @@ class MasterRecoveryTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid)
offset = 1
cell_list = [(offset, uuid, UP_TO_DATE_STATE)]
cell_list = [(offset, uuid, CellStates.UP_TO_DATE)]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
# from target node, taken into account
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid)
self.app.target_uuid = uuid
self.assertEquals(self.app.target_uuid, uuid)
offset = 1
cell_list = [(offset, ((uuid, UP_TO_DATE_STATE,),),)]
cell_list = [(offset, ((uuid, CellStates.UP_TO_DATE,),),)]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, UP_TO_DATE_STATE)
self.assertEquals(state, CellStates.UP_TO_DATE)
# give a bad offset, must send error
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertEquals(self.app.target_uuid, uuid)
......
......@@ -23,15 +23,14 @@ from struct import pack, unpack
from neo.tests import NeoTestBase
import neo.master
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
from neo.exception import OperationFailure, ElectionFailure
class MasterStorageHandlerTests(NeoTestBase):
......@@ -137,7 +136,7 @@ class MasterStorageHandlerTests(NeoTestBase):
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), BROKEN_STATE)
self.assertEquals(sn.getState(), CellStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID())
def test_06_handleAnswerLastIDs(self):
......@@ -257,53 +256,54 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address)
storage_uuid = self.identifyToMasterNode(port=self.storage_port+1)
offset = 1
cell_list = [(offset, uuid, FEEDING_STATE),]
cell_list = [(offset, uuid, CellStates.FEEDING),]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
# send for another node, must not be take into account
conn = self.getFakeConnection(uuid, self.storage_address)
offset = 1
cell_list = [(offset, storage_uuid, UP_TO_DATE_STATE),]
cell_list = [(offset, storage_uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
# send for itself, must be taken into account
# and the feeding node must be removed
conn = self.getFakeConnection(uuid, self.storage_address)
cell_list = [(offset, uuid, UP_TO_DATE_STATE),]
cell_list = [(offset, uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
# mark the second storage node as feeding and say we are up to date
# second node must go to discarded state and first one to up to date state
self.app.pt.setCell(offset, self.app.nm.getByUUID(storage_uuid), FEEDING_STATE)
cell_list = [(offset, uuid, UP_TO_DATE_STATE),]
self.app.pt.setCell(offset, self.app.nm.getByUUID(storage_uuid),
CellStates.FEEDING)
cell_list = [(offset, uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
if cell == storage_uuid:
self.assertEquals(state, FEEDING_STATE)
self.assertEquals(state, CellStates.FEEDING)
else:
self.assertEquals(state, OUT_OF_DATE_STATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
lptid = self.app.pt.getID()
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
self.failUnless(lptid < self.app.pt.getID())
cells = self.app.pt.getRow(offset)
for cell, state in cells:
if cell == uuid:
self.assertEquals(state, UP_TO_DATE_STATE)
self.assertEquals(state, CellStates.UP_TO_DATE)
else:
self.assertEquals(state, DISCARDED_STATE)
self.assertEquals(state, CellStates.DISCARDED)
def test_15_peerBroken(self):
......
......@@ -22,15 +22,14 @@ from mock import Mock
from struct import pack, unpack
import neo
from neo.tests import NeoTestBase
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application
from neo import protocol
from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......
......@@ -24,8 +24,8 @@ from neo import protocol
from neo.pt import PartitionTable
from neo.storage.app import Application
from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import Packet, CellStates, INVALID_UUID, \
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, \
......@@ -108,9 +108,9 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.app.nm.createStorage(uuid=node_2)
self.app.nm.createStorage(uuid=node_3)
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)))]
row_list = [(0, ((node_1, CellStates.UP_TO_DATE), (node_2, CellStates.UP_TO_DATE))),
(1, ((node_3, CellStates.UP_TO_DATE), (node_1, CellStates.UP_TO_DATE))),
(2, ((node_2, CellStates.UP_TO_DATE), (node_3, CellStates.UP_TO_DATE)))]
self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled
self.verification.handleSendPartitionTable(conn, packet, 1, row_list[:1])
......
......@@ -26,7 +26,7 @@ from neo.storage.app import Application
from neo.storage.handlers.master import MasterOperationHandler
from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable
from neo import protocol
from neo.protocol import CellStates
from neo.protocol import *
class StorageMasterHandlerTests(NeoTestBase):
......@@ -115,9 +115,9 @@ class StorageMasterHandlerTests(NeoTestBase):
# cases :
uuid1, uuid2, uuid3 = [self.getNewUUID() for i in range(3)]
cells = (
(0, uuid1, UP_TO_DATE_STATE),
(1, uuid2, DISCARDED_STATE),
(2, uuid3, OUT_OF_DATE_STATE),
(0, uuid1, CellStates.UP_TO_DATE),
(1, uuid2, CellStates.DISCARDED),
(2, uuid3, CellStates.OUT_OF_DATE),
)
# context
conn = Mock({
......
......@@ -19,8 +19,8 @@ import unittest, logging, os
from mock import Mock
from neo.tests import NeoTestBase
from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE
from neo.protocol import CellStates, INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
from collections import deque
from neo.pt import PartitionTable
......@@ -64,8 +64,8 @@ class StorageAppTests(NeoTestBase):
client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid)
self.app.pt.setCell(0, master, UP_TO_DATE_STATE)
self.app.pt.setCell(0, storage, UP_TO_DATE_STATE)
self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
self.app.pt.setCell(0, storage, CellStates.UP_TO_DATE)
self.assertEqual(len(self.app.pt.getNodeList()), 2)
self.assertFalse(self.app.pt.filled())
for x in xrange(num_partitions):
......@@ -82,8 +82,8 @@ class StorageAppTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(x))
# add some node
self.app.pt.setCell(0, master, UP_TO_DATE_STATE)
self.app.pt.setCell(0, storage, UP_TO_DATE_STATE)
self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
self.app.pt.setCell(0, storage, CellStates.UP_TO_DATE)
self.assertEqual(len(self.app.pt.getNodeList()), 2)
self.assertFalse(self.app.pt.filled())
for x in xrange(num_partitions):
......@@ -95,15 +95,15 @@ class StorageAppTests(NeoTestBase):
self.app.dm.setPTID(1)
self.app.dm.query('delete from pt;')
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(0, dump(client_uuid), UP_TO_DATE_STATE))
(0, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(client_uuid), UP_TO_DATE_STATE))
(1, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(storage_uuid), UP_TO_DATE_STATE))
(1, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(storage_uuid), UP_TO_DATE_STATE))
(2, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(master_uuid), UP_TO_DATE_STATE))
(2, dump(master_uuid), CellStates.UP_TO_DATE))
self.assertEqual(len(self.app.dm.getPartitionTable()), 5)
self.app.pt.clear()
self.app.loadPartitionTable()
......
......@@ -22,6 +22,7 @@ import MySQLdb
from mock import Mock
from neo.util import dump
from neo.protocol import *
from neo.protocol import CellStates
from neo.tests import NeoTestBase
from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
......@@ -329,32 +330,32 @@ class StorageMySQSLdbTests(NeoTestBase):
ptid = '1'
uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02'
cells = (
(0, uuid1, DISCARDED_STATE),
(1, uuid2, UP_TO_DATE_STATE),
(0, uuid1, CellStates.DISCARDED),
(1, uuid2, CellStates.UP_TO_DATE),
)
self.db.setPTID(INVALID_PTID)
# empty table -> insert for second cell
self.db.changePartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0))
self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid)
# delete previous entries for a DISCARDED_STATE node
# delete previous entries for a CellStates.DISCARDEDnode
self.db.query("delete from pt")
args = (0, dump(uuid1), DISCARDED_STATE)
args = (0, dump(uuid1), CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (0, dump(uuid1), 3))
self.assertEquals(result[0], (0, dump(uuid1), 4))
self.assertEquals(self.db.getPTID(), ptid)
self.db.changePartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0))
self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid)
# raise exception (config not set), check rollback
self.db.query("drop table config") # will generate the exception
args = (0, uuid1, DISCARDED_STATE)
args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.assertRaises(MySQLdb.ProgrammingError,
self.db.changePartitionTable, ptid, cells)
......@@ -367,34 +368,34 @@ class StorageMySQSLdbTests(NeoTestBase):
ptid = '1'
uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02'
cells = (
(0, uuid1, DISCARDED_STATE),
(1, uuid2, UP_TO_DATE_STATE),
(0, uuid1, CellStates.DISCARDED),
(1, uuid2, CellStates.UP_TO_DATE),
)
self.db.setPTID(INVALID_PTID)
# not empty table, reset -> clean table first
args = (0, uuid2, UP_TO_DATE_STATE)
args = (0, uuid2, CellStates.UP_TO_DATE)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.db.setPartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0))
self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid)
# delete previous entries for a DISCARDED_STATE node
# delete previous entries for a CellStates.DISCARDEDnode
self.db.query("delete from pt")
args = (0, uuid1, DISCARDED_STATE)
args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (0, uuid1, 3))
self.assertEquals(result[0], (0, uuid1, 4))
self.assertEquals(self.db.getPTID(), ptid)
self.db.setPartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0))
self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid)
# raise exception (config not set), check rollback
self.db.query("drop table config") # will generate the exception
args = (0, uuid1, DISCARDED_STATE)
args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.assertRaises(MySQLdb.ProgrammingError,
self.db.setPartitionTable, ptid, cells)
......
......@@ -24,15 +24,10 @@ from neo import protocol
from neo.pt import PartitionTable
from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import 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, NodeTypes
from neo.protocol import Packet, CellStates, NodeTypes, INVALID_OID, INVALID_TID
from neo.protocol import NOTIFY_PARTITION_CHANGES, STOP_OPERATION, \
ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
ASK_TRANSACTION_INFORMATION, COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS
from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
......@@ -164,7 +159,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
address=("127.7.9.9", 1),
uuid=self.getNewUUID()
)
self.app.pt.setCell(1, node, UP_TO_DATE_STATE)
self.app.pt.setCell(1, node, CellStates.UP_TO_DATE)
self.assertTrue(self.app.pt.hasOffset(1))
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -194,7 +189,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
})
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
new_uuid = self.getNewUUID()
cell = (0, new_uuid, UP_TO_DATE_STATE)
cell = (0, new_uuid, CellStates.UP_TO_DATE)
self.app.nm.createStorage(uuid=new_uuid)
self.app.pt = PartitionTable(1, 1)
self.app.dm = Mock({ })
......
......@@ -17,9 +17,7 @@
import unittest, os
from mock import Mock
from neo.protocol import NodeStates
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, INVALID_UUID
from neo.protocol import NodeStates, CellStates
from neo.pt import Cell, PartitionTable
from neo.node import StorageNode
from neo.tests import NeoTestBase
......@@ -32,19 +30,19 @@ class PartitionTableTests(NeoTestBase):
sn = StorageNode(Mock(), server, uuid)
cell = Cell(sn)
self.assertEquals(cell.node, sn)
self.assertEquals(cell.state, UP_TO_DATE_STATE)
cell = Cell(sn, OUT_OF_DATE_STATE)
self.assertEquals(cell.state, CellStates.UP_TO_DATE)
cell = Cell(sn, CellStates.OUT_OF_DATE)
self.assertEquals(cell.node, sn)
self.assertEquals(cell.state, OUT_OF_DATE_STATE)
self.assertEquals(cell.state, CellStates.OUT_OF_DATE)
# check getter
self.assertEquals(cell.getNode(), sn)
self.assertEquals(cell.getState(), OUT_OF_DATE_STATE)
self.assertEquals(cell.getState(), CellStates.OUT_OF_DATE)
self.assertEquals(cell.getNodeState(), NodeStates.UNKNOWN)
self.assertEquals(cell.getUUID(), uuid)
self.assertEquals(cell.getAddress(), server)
# check state setter
cell.setState(FEEDING_STATE)
self.assertEquals(cell.getState(), FEEDING_STATE)
cell.setState(CellStates.FEEDING)
self.assertEquals(cell.getState(), CellStates.FEEDING)
def test_03_setCell(self):
......@@ -58,69 +56,69 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.partition_list[x]), 0)
# add a cell to an empty row
self.assertFalse(pt.count_dict.has_key(sn1))
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 1)
for x in xrange(num_partitions):
if x == 0:
self.assertEqual(len(pt.partition_list[x]), 1)
cell = pt.partition_list[x][0]
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
else:
self.assertEqual(len(pt.partition_list[x]), 0)
# try to add to an unexistant partition
self.assertRaises(IndexError, pt.setCell, 10, sn1, UP_TO_DATE_STATE)
self.assertRaises(IndexError, pt.setCell, 10, sn1, CellStates.UP_TO_DATE)
# if we add in discardes state, must be removed
pt.setCell(0, sn1, DISCARDED_STATE)
pt.setCell(0, sn1, CellStates.DISCARDED)
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0)
# add a feeding node into empty row
pt.setCell(0, sn1, FEEDING_STATE)
pt.setCell(0, sn1, CellStates.FEEDING)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 0)
for x in xrange(num_partitions):
if x == 0:
self.assertEqual(len(pt.partition_list[x]), 1)
cell = pt.partition_list[x][0]
self.assertEqual(cell.getState(), FEEDING_STATE)
self.assertEqual(cell.getState(), CellStates.FEEDING)
else:
self.assertEqual(len(pt.partition_list[x]), 0)
# re-add it as feeding, nothing change
pt.setCell(0, sn1, FEEDING_STATE)
pt.setCell(0, sn1, CellStates.FEEDING)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 0)
for x in xrange(num_partitions):
if x == 0:
self.assertEqual(len(pt.partition_list[x]), 1)
cell = pt.partition_list[x][0]
self.assertEqual(cell.getState(), FEEDING_STATE)
self.assertEqual(cell.getState(), CellStates.FEEDING)
else:
self.assertEqual(len(pt.partition_list[x]), 0)
# now add it as up to date
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 1)
for x in xrange(num_partitions):
if x == 0:
self.assertEqual(len(pt.partition_list[x]), 1)
cell = pt.partition_list[x][0]
self.assertEqual(cell.getState(), UP_TO_DATE_STATE)
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
else:
self.assertEqual(len(pt.partition_list[x]), 0)
# now add broken and down state, must not be taken into account
pt.setCell(0, sn1, DISCARDED_STATE)
pt.setCell(0, sn1, CellStates.DISCARDED)
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0)
sn1.setState(NodeStates.BROKEN)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0)
sn1.setState(NodeStates.DOWN)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0)
......@@ -137,7 +135,7 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.partition_list[x]), 0)
# add a cell to an empty row
self.assertFalse(pt.count_dict.has_key(sn1))
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 1)
for x in xrange(num_partitions):
......@@ -151,7 +149,7 @@ class PartitionTableTests(NeoTestBase):
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
# add a feeding cell
pt.setCell(0, sn1, FEEDING_STATE)
pt.setCell(0, sn1, CellStates.FEEDING)
self.assertTrue(pt.count_dict.has_key(sn1))
self.assertEqual(pt.count_dict[sn1], 0)
for x in xrange(num_partitions):
......@@ -173,19 +171,19 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, OUT_OF_DATE_STATE)
pt.setCell(0, sn2, CellStates.OUT_OF_DATE)
uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, FEEDING_STATE)
pt.setCell(0, sn3, CellStates.FEEDING)
uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(Mock(), server4, uuid4)
pt.setCell(0, sn4, DISCARDED_STATE) # won't be added
pt.setCell(0, sn4, CellStates.DISCARDED) # won't be added
# now checks result
self.assertEqual(len(pt.partition_list[0]), 3)
for x in xrange(num_partitions):
......@@ -235,15 +233,15 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(1, sn2, OUT_OF_DATE_STATE)
pt.setCell(1, sn2, CellStates.OUT_OF_DATE)
uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(2, sn3, FEEDING_STATE)
pt.setCell(2, sn3, CellStates.FEEDING)
# now checks result
self.assertEqual(len(pt.partition_list[0]), 1)
self.assertEqual(len(pt.partition_list[1]), 1)
......@@ -265,19 +263,19 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, OUT_OF_DATE_STATE)
pt.setCell(0, sn2, CellStates.OUT_OF_DATE)
uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, FEEDING_STATE)
pt.setCell(0, sn3, CellStates.FEEDING)
uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(Mock(), server4, uuid4)
pt.setCell(0, sn4, DISCARDED_STATE) # won't be added
pt.setCell(0, sn4, CellStates.DISCARDED) # won't be added
# must get only two node as feeding and discarded not taken
# into account
self.assertEqual(len(pt.getNodeList()), 2)
......@@ -299,7 +297,7 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions):
pt.setCell(x, sn1, UP_TO_DATE_STATE)
pt.setCell(x, sn1, CellStates.UP_TO_DATE)
self.assertEqual(pt.num_filled_rows, num_partitions)
self.assertTrue(pt.filled())
......@@ -311,7 +309,7 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
# now test
self.assertTrue(pt.hasOffset(0))
self.assertFalse(pt.hasOffset(1))
......@@ -329,7 +327,7 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions):
pt.setCell(x, sn1, UP_TO_DATE_STATE)
pt.setCell(x, sn1, CellStates.UP_TO_DATE)
self.assertTrue(pt.filled())
# it's up to date and running, so operational
sn1.setState(NodeStates.RUNNING)
......@@ -343,7 +341,7 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE)
pt.setCell(x, sn1, CellStates.FEEDING)
self.assertTrue(pt.filled())
# it's feeding and running, so operational
sn1.setState(NodeStates.RUNNING)
......@@ -359,7 +357,7 @@ class PartitionTableTests(NeoTestBase):
sn1 = StorageNode(Mock(), server1, uuid1)
sn1.setState(NodeStates.TEMPORARILY_DOWN)
for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE)
pt.setCell(x, sn1, CellStates.FEEDING)
self.assertTrue(pt.filled())
# it's up to date and not running, so not operational
self.assertFalse(pt.operational())
......@@ -373,7 +371,7 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions):
pt.setCell(x, sn1, OUT_OF_DATE_STATE)
pt.setCell(x, sn1, CellStates.OUT_OF_DATE)
self.assertTrue(pt.filled())
# it's not up to date and running, so not operational
self.assertFalse(pt.operational())
......@@ -386,34 +384,34 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE)
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
pt.setCell(1, sn1, CellStates.UP_TO_DATE)
pt.setCell(2, sn1, CellStates.UP_TO_DATE)
uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn2, UP_TO_DATE_STATE)
pt.setCell(0, sn2, CellStates.UP_TO_DATE)
pt.setCell(1, sn2, CellStates.UP_TO_DATE)
uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, UP_TO_DATE_STATE)
pt.setCell(0, sn3, CellStates.UP_TO_DATE)
# test
row_0 = pt.getRow(0)
self.assertEqual(len(row_0), 3)
for uuid, state in row_0:
self.failUnless(uuid in (sn1.getUUID(), sn2.getUUID(), sn3.getUUID()))
self.assertEqual(state, UP_TO_DATE_STATE)
self.assertEqual(state, CellStates.UP_TO_DATE)
row_1 = pt.getRow(1)
self.assertEqual(len(row_1), 2)
for uuid, state in row_1:
self.failUnless(uuid in (sn1.getUUID(), sn2.getUUID()))
self.assertEqual(state, UP_TO_DATE_STATE)
self.assertEqual(state, CellStates.UP_TO_DATE)
row_2 = pt.getRow(2)
self.assertEqual(len(row_2), 1)
for uuid, state in row_2:
self.assertEqual(uuid, sn1.getUUID())
self.assertEqual(state, UP_TO_DATE_STATE)
self.assertEqual(state, CellStates.UP_TO_DATE)
row_3 = pt.getRow(3)
self.assertEqual(len(row_3), 0)
row_4 = pt.getRow(4)
......
......@@ -19,7 +19,7 @@ import unittest, os
from mock import Mock
from neo import protocol
from neo.protocol import *
from neo.protocol import NodeTypes, NodeStates
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.tests import NeoTestBase
from neo.util import getNextTID
from time import time, gmtime
......@@ -176,9 +176,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID()
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
cell_list = [(0, ((uuid1, CellStates.UP_TO_DATE), (uuid2, CellStates.OUT_OF_DATE))),
(43, ((uuid2, CellStates.OUT_OF_DATE),(uuid3, CellStates.DISCARDED))),
(124, ((uuid1, CellStates.DISCARDED), (uuid3, CellStates.UP_TO_DATE)))]
p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid)
......@@ -189,9 +189,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID()
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
cell_list = [(0, ((uuid1, CellStates.UP_TO_DATE), (uuid2, CellStates.OUT_OF_DATE))),
(43, ((uuid2, CellStates.OUT_OF_DATE),(uuid3, CellStates.DISCARDED))),
(124, ((uuid1, CellStates.DISCARDED), (uuid3, CellStates.UP_TO_DATE)))]
p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid)
......@@ -202,9 +202,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID()
cell_list = [(0, uuid1, UP_TO_DATE_STATE),
(43, uuid2, OUT_OF_DATE_STATE),
(124, uuid1, DISCARDED_STATE)]
cell_list = [(0, uuid1, CellStates.UP_TO_DATE),
(43, uuid2, CellStates.OUT_OF_DATE),
(124, uuid1, CellStates.DISCARDED)]
p = protocol.notifyPartitionChanges(ptid,
cell_list)
pptid, p_cell_list = p.decode()
......
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