Commit 10598deb authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove trailing whitespaces.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1420 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent fb85bde4
#
# Copyright (C) 2006-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
......
......@@ -118,7 +118,7 @@ class Application(object):
nm.createMaster(address=address)
# search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, NodeTypes.ADMIN,
bootstrap = BootstrapManager(self, self.name, NodeTypes.ADMIN,
self.uuid, self.server)
data = bootstrap.getPrimaryConnection(self.connector_handler)
(node, conn, uuid, num_partitions, num_replicas) = data
......
......@@ -27,7 +27,7 @@ class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster."""
def askPartitionList(self, conn, packet, min_offset, max_offset, uuid):
logging.info("ask partition list from %s to %s for %s" %
logging.info("ask partition list from %s to %s for %s" %
(min_offset, max_offset, dump(uuid)))
app = self.app
# check we have one pt otherwise ask it to PMN
......@@ -43,7 +43,7 @@ class AdminEventHandler(EventHandler):
'uuid' : uuid,
'msg_id' : packet.getId()})
else:
app.sendPartitionTable(conn, min_offset, max_offset, uuid,
app.sendPartitionTable(conn, min_offset, max_offset, uuid,
packet.getId())
......@@ -96,10 +96,10 @@ class AdminEventHandler(EventHandler):
'master.')
# required it from PMN first
msg_id = self.app.master_conn.ask(Packets.AskClusterState())
self.app.dispatcher.register(msg_id, conn,
self.app.dispatcher.register(msg_id, conn,
{'msg_id' : packet.getId()})
else:
conn.answer(Packets.AnswerClusterState(self.app.cluster_state),
conn.answer(Packets.AnswerClusterState(self.app.cluster_state),
packet.getId())
def askPrimary(self, conn, packet):
......
#
# Copyright (C) 2006-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
......@@ -26,14 +26,14 @@ from neo.connection import ClientConnection
NO_SERVER = ('0.0.0.0', 0)
class BootstrapManager(EventHandler):
"""
"""
Manage the bootstrap stage, lookup for the primary master then connect to it
"""
def __init__(self, app, name, node_type, uuid=None, server=NO_SERVER):
"""
Manage the bootstrap stage of a non-master node, it lookup for the
primary master node, connect to it then returns when the master node
primary master node, connect to it then returns when the master node
is ready.
"""
EventHandler.__init__(self, app)
......@@ -72,7 +72,7 @@ class BootstrapManager(EventHandler):
def notReady(self, conn, packet, message):
"""
The primary master send this message when it is still not ready to
handle the client node.
handle the client node.
Close connection and restart.
"""
# master are still electing on of them
......@@ -134,7 +134,7 @@ class BootstrapManager(EventHandler):
# retry until identified to the primary
while self.primary is None or conn.getUUID() != self.primary.getUUID():
if self.current is None:
# conn closed
# conn closed
conn = None
# select a master
master_list = nm.getMasterList()
......@@ -147,7 +147,7 @@ class BootstrapManager(EventHandler):
# open the connection
addr = self.current.getAddress()
conn = ClientConnection(em, self, addr, connector_handler)
# still processing
# still processing
em.poll(1)
node = nm.getByUUID(conn.getUUID())
return (node, conn, self.uuid, self.num_partitions, self.num_replicas)
......
#
# Copyright (C) 2006-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
......@@ -63,7 +63,7 @@ class Storage(BaseStorage.BaseStorage,
def tpc_begin(self, transaction, tid=None, status=' '):
if self._is_read_only:
raise POSException.ReadOnlyError()
return self.app.tpc_begin(transaction=transaction, tid=tid,
return self.app.tpc_begin(transaction=transaction, tid=tid,
status=status)
def tpc_vote(self, transaction):
......
This diff is collapsed.
#
# Copyright (C) 2006-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
......@@ -21,7 +21,7 @@ class NeoStorage(BaseConfig):
def open(self):
from Storage import Storage
return Storage(master_nodes=self.config.master_nodes,
return Storage(master_nodes=self.config.master_nodes,
name=self.config.name, connector = self.config.connector)
#
# Copyright (C) 2006-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
......@@ -17,11 +17,11 @@
from ZODB import POSException
class NEOStorageError(POSException.StorageError):
class NEOStorageError(POSException.StorageError):
pass
class NEOStorageConflictError(NEOStorageError):
class NEOStorageConflictError(NEOStorageError):
pass
class NEOStorageNotFoundError(NEOStorageError):
class NEOStorageNotFoundError(NEOStorageError):
pass
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -54,7 +54,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# got an uuid from the primary master
app.uuid = your_uuid
# Always create partition table
# Always create partition table
app.pt = PartitionTable(num_partitions, num_replicas)
def answerPrimary(self, conn, packet, primary_uuid,
......@@ -85,13 +85,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# The primary master node is not a primary master node
# any longer.
app.primary_master_node = None
app.trying_master_node = None
conn.close()
def answerPartitionTable(self, conn, packet, ptid, row_list):
pass
def answerNodeInformation(self, conn, packet):
pass
......@@ -106,7 +106,7 @@ class PrimaryNotificationsHandler(BaseHandler):
app.master_conn = None
app.primary_master_node = None
else:
logging.warn('app.master_conn is %s, but we are closing %s',
logging.warn('app.master_conn is %s, but we are closing %s',
app.master_conn, conn)
super(PrimaryNotificationsHandler, self).connectionClosed(conn)
......@@ -146,7 +146,7 @@ class PrimaryNotificationsHandler(BaseHandler):
finally:
app._cache_lock_release()
# For the two methods below, we must not use app._getPartitionTable()
# For the two methods below, we must not use app._getPartitionTable()
# to avoid a dead lock. It is safe to not check the master connection
# because it's in the master handler, so the connection is already
# established.
......
#
# Copyright (C) 2006-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
......@@ -29,7 +29,7 @@ class StorageEventHandler(BaseHandler):
assert node is not None
# Remove from pool connection
app.cp.removeConnection(node)
app.dispatcher.unregister(conn)
app.dispatcher.unregister(conn)
def connectionLost(self, conn, new_state):
self._dealWithStorageFailure(conn)
......@@ -51,7 +51,7 @@ class StorageBootstrapHandler(AnswerBaseHandler):
def notReady(self, conn, packet, message):
app = self.app
app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app
......@@ -74,11 +74,11 @@ class StorageBootstrapHandler(AnswerBaseHandler):
class StorageAnswersHandler(AnswerBaseHandler):
""" Handle all messages related to ZODB operations """
def answerObject(self, conn, packet, oid, start_serial, end_serial,
def answerObject(self, conn, packet, oid, start_serial, end_serial,
compression, checksum, data):
app = self.app
app.local_var.asked_object = (oid, start_serial, end_serial,
app.local_var.asked_object = (oid, start_serial, end_serial,
compression, checksum, data)
def answerStoreObject(self, conn, packet, conflicting, oid, serial):
......
#
# Copyright (C) 2006-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
......
......@@ -37,12 +37,12 @@ class Element(object):
This class defines an element of a FIFO buffer.
"""
pass
class FIFO(object):
"""
This class implements a FIFO buffer.
"""
def __init__(self):
self._head = None
self._tail = None
......@@ -56,10 +56,10 @@ class FIFO(object):
self.element = None
self.key = None
self.expire_time = None
def __len__(self):
return self._len
def append(self):
element = Element()
element.next = None
......@@ -74,10 +74,10 @@ class FIFO(object):
def head(self):
return self._head
def tail(self):
return self._tail
def shift(self):
element = self._head
if element is None:
......@@ -86,26 +86,26 @@ class FIFO(object):
del element.next
del element.prev
return element
def __delitem__(self, element):
if element.next is None:
self._tail = element.prev
else:
element.next.prev = element.prev
if element.prev is None:
self._head = element.next
else:
element.prev.next = element.next
self._len -= 1
self._len -= 1
class Data(object):
"""
Data for each element in a FIFO buffer.
"""
pass
def sizeof(o):
"""This function returns the estimated size of an object."""
if isinstance(o, tuple):
......@@ -116,22 +116,22 @@ def sizeof(o):
class MQ(object):
"""
This class manages cached data by a variant of Multi-Queue.
This class caches various sizes of objects. Here are some considerations:
- Expired objects are not really deleted immediately. But if GC is invoked too often,
it degrades the performance significantly.
- If large objects are cached, the number of cached objects decreases. This might affect
the cache hit ratio. It might be better to tweak a buffer level according to the size of
an object.
- Stored values must be strings.
- The size calculation is not accurate.
"""
def __init__(self, life_time=10000, buffer_levels=9,
def __init__(self, life_time=10000, buffer_levels=9,
max_history_size=100000, max_size=20*1024*1024):
self._history_buffer = FIFO()
self._cache_buffers = []
......@@ -144,16 +144,16 @@ class MQ(object):
self._max_history_size = max_history_size
self._max_size = max_size
self._size = 0
def has_key(self, key):
if key in self._data:
data = self._data[key]
if data.level >= 0:
return 1
return 0
__contains__ = has_key
def fetch(self, key):
"""
Fetch a value associated with the key.
......@@ -165,15 +165,15 @@ class MQ(object):
self.store(key, value)
return value
raise KeyError(key)
__getitem__ = fetch
def get(self, key, d=None):
try:
return self.fetch(key)
except KeyError:
return d
def _evict(self, key):
"""
Evict an element to the history buffer.
......@@ -190,7 +190,7 @@ class MQ(object):
if len(self._history_buffer) > self._max_history_size:
element = self._history_buffer.shift()
del self._data[element.data.key]
def store(self, key, value):
cache_buffers = self._cache_buffers
......@@ -203,8 +203,8 @@ class MQ(object):
del self._history_buffer[element]
except KeyError:
counter = 1
# XXX It might be better to adjust the level according to the object
# XXX It might be better to adjust the level according to the object
# size.
level = min(int(log(counter, 2)), self._buffer_levels - 1)
element = cache_buffers[level].append()
......@@ -219,7 +219,7 @@ class MQ(object):
self._data[key] = data
self._size += sizeof(value)
del value
self._time += 1
# Expire old elements.
......@@ -239,7 +239,7 @@ class MQ(object):
data.element = element
else:
self._evict(data.key)
# Limit the size.
size = self._size
max_size = self._max_size
......@@ -256,9 +256,9 @@ class MQ(object):
if size <= max_size:
break
self._size = size
__setitem__ = store
def invalidate(self, key):
if id in self._data:
data = self._data[key]
......@@ -269,14 +269,14 @@ class MQ(object):
raise KeyError, "%s was not found in the cache" % key
__delitem__ = invalidate
# Here is a test.
if __name__ == '__main__':
import hotshot, hotshot.stats
def test():
cache = MQ(life_time=100, buffer_levels=9, max_history_size=10000,
cache = MQ(life_time=100, buffer_levels=9, max_history_size=10000,
max_size=2*1024*1024)
for i in xrange(10000):
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -20,7 +20,7 @@ from neo.util import bin, parseMasterList
class ConfigurationManager(object):
"""
"""
Configuration manager that load options from a configuration file and
command line arguments
"""
......@@ -52,7 +52,7 @@ class ConfigurationManager(object):
return []
# load master node list except itself
return parseMasterList(masters, except_node=self.getBind())
def getBind(self):
""" Get the address to bind to """
bind = self.__get('bind')
......
#
# Copyright (C) 2006-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
......@@ -70,9 +70,9 @@ class BaseConnection(object):
if connector is not None:
self.connector_handler = connector.__class__
event_manager.register(self)
else:
else:
self.connector_handler = connector_handler
def lock(self):
return 1
......@@ -104,7 +104,7 @@ class BaseConnection(object):
if self.connector is not None:
em.removeReader(self)
em.removeWriter(self)
em.unregister(self)
em.unregister(self)
self.connector.shutdown()
self.connector.close()
self.connector = None
......@@ -202,7 +202,7 @@ class Connection(BaseConnection):
return next_id
def close(self):
logging.debug('closing a connector for %s (%s:%d)',
logging.debug('closing a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
BaseConnection.close(self)
for event in self.event_dict.itervalues():
......@@ -213,7 +213,7 @@ class Connection(BaseConnection):
def abort(self):
"""Abort dealing with this connection."""
logging.debug('aborting a connector for %s (%s:%d)',
logging.debug('aborting a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
self.aborted = True
......@@ -307,14 +307,14 @@ class Connection(BaseConnection):
self.handler.connectionClosed(self)
return
self.read_buf += data
except ConnectorTryAgainException:
except ConnectorTryAgainException:
pass
except ConnectorConnectionRefusedException:
# should only occur while connecting
self.close()
self.handler.connectionFailed(self)
except ConnectorConnectionClosedException:
# connection resetted by peer, according to the man, this error
# connection resetted by peer, according to the man, this error
# should not occurs but it seems it's false
logging.debug('Connection reset by peer: %r', self.connector)
self.close()
......@@ -350,7 +350,7 @@ class Connection(BaseConnection):
# unhandled connector exception
self.close()
self.handler.connectionClosed(self)
raise
raise
def _addPacket(self, packet):
"""Add a packet into the write buffer."""
......@@ -405,8 +405,8 @@ class Connection(BaseConnection):
@not_closed
def ask(self, packet, timeout=5, additional_timeout=30):
"""
Send a packet with a new ID and register the expectation of an answer
"""
Send a packet with a new ID and register the expectation of an answer
"""
msg_id = self._getNextId()
packet.setId(msg_id)
......
#
# 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
......@@ -52,13 +52,13 @@ class SocketConnector:
self.remote_addr = accepted_from
self.is_listening = False
self.is_closed = False
if s is None:
if s is None:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else:
self.socket = s
# always use non-blocking sockets
self.socket.setblocking(0)
def makeClientConnection(self, addr):
self.is_closed = False
self.remote_addr = addr
......@@ -92,8 +92,8 @@ class SocketConnector:
return self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
def getDescriptor(self):
# this descriptor must only be used by the event manager, where it
# guarantee unicity only while the connector is opened and registered
# this descriptor must only be used by the event manager, where it
# guarantee unicity only while the connector is opened and registered
# in epoll
return self.socket.fileno()
......@@ -135,7 +135,7 @@ class SocketConnector:
raise ConnectorTryAgainException
if err == errno.ECONNRESET:
raise ConnectorConnectionClosedException
raise ConnectorException, 'send failed: %s:%s' % (err, errmsg)
raise ConnectorException, 'send failed: %s:%s' % (err, errmsg)
def close(self):
self.is_closed = True
......@@ -167,18 +167,18 @@ class SocketConnector:
registerConnectorHandler(SocketConnector)
class ConnectorException(Exception):
class ConnectorException(Exception):
pass
class ConnectorTryAgainException(ConnectorException):
class ConnectorTryAgainException(ConnectorException):
pass
class ConnectorInProgressException(ConnectorException):
class ConnectorInProgressException(ConnectorException):
pass
class ConnectorConnectionClosedException(ConnectorException):
class ConnectorConnectionClosedException(ConnectorException):
pass
class ConnectorConnectionRefusedException(ConnectorException):
class ConnectorConnectionRefusedException(ConnectorException):
pass
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -81,7 +81,7 @@ class Epoll(object):
timeout *= 1000
timeout = int(timeout)
while 1:
n = epoll_wait(self.efd, byref(self.events), self.maxevents,
n = epoll_wait(self.efd, byref(self.events), self.maxevents,
timeout)
if n == -1:
e = errno.value
......
#
# Copyright (C) 2006-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
......@@ -52,7 +52,7 @@ class IdleEvent(object):
# long, although being responsive at network level.
conn.lock()
try:
logging.info('timeout for %r with %s:%d',
logging.info('timeout for %r with %s:%d',
self._id, *(conn.getAddress()))
conn.close()
conn.getHandler().timeoutExpired(conn)
......@@ -143,7 +143,7 @@ class SelectEventManager(object):
self._addPendingConnection(to_process)
def _poll(self, timeout = 1):
rlist, wlist, xlist = select(self.reader_set, self.writer_set,
rlist, wlist, xlist = select(self.reader_set, self.writer_set,
self.exc_list, timeout)
for s in rlist:
conn = self.connection_dict[s]
......@@ -175,7 +175,7 @@ class SelectEventManager(object):
t = time()
if t - self.prev_time >= 1:
self.prev_time = t
event_list.sort(key = lambda event: event.getTime(),
event_list.sort(key = lambda event: event.getTime(),
reverse = True)
while event_list:
event = event_list.pop()
......
#
# Copyright (C) 2006-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
......@@ -15,20 +15,20 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NeoException(Exception):
class NeoException(Exception):
pass
class ElectionFailure(NeoException):
class ElectionFailure(NeoException):
pass
class PrimaryFailure(NeoException):
class PrimaryFailure(NeoException):
pass
class VerificationFailure(NeoException):
class VerificationFailure(NeoException):
pass
class OperationFailure(NeoException):
class OperationFailure(NeoException):
pass
class DatabaseFailure(NeoException):
class DatabaseFailure(NeoException):
pass
#
# Copyright (C) 2006-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
......@@ -34,10 +34,10 @@ class EventHandler(object):
"""Called when a packet is malformed."""
args = (conn.getAddress()[0], conn.getAddress()[1], message)
if packet is None:
# if decoding fail, there's no packet instance
# if decoding fail, there's no packet instance
logging.error('malformed packet from %s:%d: %s', *args)
else:
logging.error('malformed packet %s from %s:%d: %s',
logging.error('malformed packet %s from %s:%d: %s',
packet.getType(), *args)
response = protocol.protocolError(message)
if packet is not None:
......@@ -270,7 +270,7 @@ class EventHandler(object):
def askTransactionInformation(self, conn, packet, tid):
raise UnexpectedPacketError
def answerTransactionInformation(self, conn, packet, tid,
def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list):
raise UnexpectedPacketError
......
......@@ -48,7 +48,7 @@ class LockUser(object):
return isinstance(other, self.__class__) and self.ident == other.ident
def __repr__(self):
return '%s@%s:%s %s' % (self.ident, self.caller[0], self.caller[1],
return '%s@%s:%s %s' % (self.ident, self.caller[0], self.caller[1],
self.caller[3])
def formatStack(self):
......@@ -60,7 +60,7 @@ class VerboseLockBase(object):
self.debug_lock = debug_lock
self.owner = None
self.waiting = []
self._note('%s@%X created by %r', self.__class__.__name__, id(self),
self._note('%s@%X created by %r', self.__class__.__name__, id(self),
LockUser(1))
def _note(self, fmt, *args):
......@@ -85,7 +85,7 @@ class VerboseLockBase(object):
self._note('[%r]%s.acquire(%s): Deadlock detected: ' \
' I already own this lock:%r', me, self, blocking, owner)
else:
self._note('[%r]%s.acquire(%s): debug lock triggered: %r',
self._note('[%r]%s.acquire(%s): debug lock triggered: %r',
me, self, blocking, owner)
self._note('Owner traceback:\n%s', owner.formatStack())
self._note('My traceback:\n%s', me.formatStack())
......@@ -95,7 +95,7 @@ class VerboseLockBase(object):
finally:
self.owner = me
self.waiting.remove(me)
self._note('[%r]%s.acquire(%s) Lock granted. Waiting: %r',
self._note('[%r]%s.acquire(%s) Lock granted. Waiting: %r',
me, self, blocking, self.waiting)
def release(self):
......@@ -111,7 +111,7 @@ class VerboseLockBase(object):
class VerboseRLock(VerboseLockBase):
def __init__(self, verbose=None, debug_lock=False):
super(VerboseRLock, self).__init__(reentrant=True,
super(VerboseRLock, self).__init__(reentrant=True,
debug_lock=debug_lock)
self.lock = threading_RLock()
......
#
# Copyright (C) 2006-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
......@@ -28,7 +28,7 @@ class PacketLogger(EventHandler):
def dispatch(self, conn, packet, direction):
"""This is a helper method to handle various packet types."""
# default log message
# default log message
klass = packet.getType()
uuid = dump(conn.getUUID())
ip, port = conn.getAddress()
......@@ -188,7 +188,7 @@ class PacketLogger(EventHandler):
def askTransactionInformation(self, conn, packet, tid):
pass
def answerTransactionInformation(self, conn, packet, tid,
def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list):
pass
......
#
# Copyright (C) 2006-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
......@@ -73,7 +73,7 @@ class Application(object):
self.cluster_state = None
# Generate an UUID for self
uuid = config.getUUID()
uuid = config.getUUID()
if uuid is None or uuid == '':
uuid = self.getNewUUID(NodeTypes.MASTER)
self.uuid = uuid
......@@ -105,7 +105,7 @@ class Application(object):
self.nm.createMaster(address=address)
# Make a listening port.
self.listening_conn = ListeningConnection(self.em, None,
self.listening_conn = ListeningConnection(self.em, None,
addr = self.server, connector_handler = self.connector_handler)
self.cluster_state = ClusterStates.BOOTING
......@@ -157,7 +157,7 @@ class Application(object):
if node.isRunning():
self.unconnected_master_node_set.add(node.getAddress())
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# 10 seconds to avoid stopping the whole cluster for a long time.
# Note that even if not all master are up in the first 20 seconds
# this is not an issue because the first up will timeout and take
......@@ -227,7 +227,7 @@ class Application(object):
if conn.getAddress() != addr:
conn.close()
# But if there is no such connection, something wrong
# But if there is no such connection, something wrong
# happened.
for conn in em.getClientList():
if conn.getAddress() == addr:
......@@ -326,7 +326,7 @@ class Application(object):
row_list.append((offset, self.pt.getRow(offset)))
# Split the packet if too huge.
if len(row_list) == 1000:
conn.notify(Packets.SendPartitionTable(self.pt.getID(),
conn.notify(Packets.SendPartitionTable(self.pt.getID(),
row_list))
del row_list[:]
if row_list:
......@@ -373,16 +373,16 @@ class Application(object):
def recoverStatus(self):
"""
Recover the status about the cluster. Obtain the last OID, the last
TID, and the last Partition Table ID from storage nodes, then get
back the latest partition table or make a new table from scratch,
Recover the status about the cluster. Obtain the last OID, the last
TID, and the last Partition Table ID from storage nodes, then get
back the latest partition table or make a new table from scratch,
if this is the first time.
"""
logging.info('begin the recovery of the status')
self.changeClusterState(ClusterStates.RECOVERING)
em = self.em
self.loid = None
self.ltid = None
self.pt.setID(None)
......@@ -565,7 +565,7 @@ class Application(object):
self.changeClusterState(ClusterStates.RUNNING)
# This dictionary is used to hold information on transactions being
# This dictionary is used to hold information on transactions being
# finished.
self.finishing_transaction_dict = {}
......@@ -574,12 +574,12 @@ class Application(object):
try:
em.poll(1)
except OperationFailure:
# If not operational, send Stop Operation packets to storage
# If not operational, send Stop Operation packets to storage
# nodes and client nodes. Abort connections to client nodes.
logging.critical('No longer operational, stopping the service')
for conn in em.getConnectionList():
node = nm.getByUUID(conn.getUUID())
if node is not None and (node.isStorage()
if node is not None and (node.isStorage()
or node.isClient()):
conn.notify(Packets.StopOperation())
if node.isClient():
......@@ -589,7 +589,7 @@ class Application(object):
return
def playPrimaryRole(self):
logging.info('play the primary role with %s (%s:%d)',
logging.info('play the primary role with %s (%s:%d)',
dump(self.uuid), *(self.server))
# all incoming connections identify through this handler
......@@ -610,7 +610,7 @@ class Application(object):
conn.setHandler(handler)
# If I know any storage node, make sure that they are not in the
# If I know any storage node, make sure that they are not in the
# running state, because they are not connected at this stage.
for node in nm.getStorageList():
if node.isRunning():
......@@ -630,7 +630,7 @@ class Application(object):
"""
I play a secondary role, thus only wait for a primary master to fail.
"""
logging.info('play the secondary role with %s (%s:%d)',
logging.info('play the secondary role with %s (%s:%d)',
dump(self.uuid), *(self.server))
......@@ -647,8 +647,8 @@ class Application(object):
self.em.poll(1)
def changeClusterState(self, state):
"""
Change the cluster state and apply right handler on each connections
"""
Change the cluster state and apply right handler on each connections
"""
if self.cluster_state == state:
return
......@@ -737,7 +737,7 @@ class Application(object):
for c in self.em.getConnectionList():
node = self.nm.getByUUID(c.getUUID())
if node.isClient():
node_list = [(node.getType(), node.getAddress(),
node_list = [(node.getType(), node.getAddress(),
node.getUUID(), NodeStates.DOWN)]
c.notify(Packets.NotifyNodeInformation(node_list))
# then ask storages and master nodes to shutdown
......@@ -745,7 +745,7 @@ class Application(object):
for c in self.em.getConnectionList():
node = self.nm.getByUUID(c.getUUID())
if node.isStorage() or node.isMaster():
node_list = [(node.getType(), node.getAddress(),
node_list = [(node.getType(), node.getAddress(),
node.getUUID(), NodeStates.DOWN)]
c.notify(Packets.NotifyNodeInformation(node_list))
# then shutdown
......@@ -764,7 +764,7 @@ class Application(object):
# if node is unknown, it has been forget when the current
# partition was validated by the admin
# Here the uuid is not cleared to allow lookup pending nodes by
# uuid from the test framework. It's safe since nodes with a
# uuid from the test framework. It's safe since nodes with a
# conflicting UUID are rejected in the identification handler.
state = NodeStates.PENDING
handler = verification.VerificationHandler
......
#
# Copyright (C) 2006-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
......@@ -86,7 +86,7 @@ class BaseServiceHandler(MasterHandler):
node = self.app.nm.getByUUID(conn.getUUID())
assert node is not None
if new_state != NodeStates.BROKEN:
new_state = DISCONNECTED_STATE_DICT.get(node.getType(),
new_state = DISCONNECTED_STATE_DICT.get(node.getType(),
NodeStates.DOWN)
if node.getState() == new_state:
return
......
......@@ -43,7 +43,7 @@ class AdministrationHandler(MasterHandler):
self.app.shutdown()
def setNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s : %s" %
logging.info("set node state for %s-%s : %s" %
(dump(uuid), state, modify_partition_table))
app = self.app
node = app.nm.getByUUID(uuid)
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -125,7 +125,7 @@ class ClientElectionHandler(ElectionHandler):
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress())
......@@ -171,7 +171,7 @@ class ClientElectionHandler(ElectionHandler):
# told me at the moment.
if n.getUUID() is None or n.getUUID() != uuid:
n.setUUID(uuid)
if primary_uuid is not None:
# The primary master is defined.
if app.primary_master_node is not None \
......@@ -200,8 +200,8 @@ class ClientElectionHandler(ElectionHandler):
# Request a node idenfitication.
conn.ask(Packets.RequestIdentification(
NodeTypes.MASTER,
app.uuid,
app.server,
app.uuid,
app.server,
app.name
))
......@@ -251,11 +251,11 @@ class ServerElectionHandler(ElectionHandler):
conn.setUUID(uuid)
p = Packets.AcceptIdentification(
NodeTypes.MASTER,
app.uuid,
app.server,
app.pt.getPartitions(),
app.pt.getReplicas(),
NodeTypes.MASTER,
app.uuid,
app.server,
app.pt.getPartitions(),
app.pt.getReplicas(),
uuid
)
conn.answer(p, packet.getId())
......
#
# Copyright (C) 2006-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
......@@ -57,9 +57,9 @@ class IdentificationHandler(MasterHandler):
node.setAddress(address)
node.setRunning()
# ask the app the node identification, if refused, an exception is
# ask the app the node identification, if refused, an exception is
# raised
result = self.app.identifyNode(node_type, uuid, node)
result = self.app.identifyNode(node_type, uuid, node)
(uuid, node, state, handler, node_ctor) = result
if uuid is None:
# no valid uuid, give it one
......@@ -75,7 +75,7 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid)
conn.setHandler(handler)
# answer
args = (NodeTypes.MASTER, app.uuid, app.server,
args = (NodeTypes.MASTER, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid)
conn.answer(Packets.AcceptIdentification(*args), packet.getId())
# trigger the event
......
#
# Copyright (C) 2006-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
......@@ -52,7 +52,7 @@ class RecoveryHandler(MasterHandler):
# load unknown storage nodes
for offset, row in row_list:
for uuid, state in row:
node = app.nm.getByUUID(uuid)
node = app.nm.getByUUID(uuid)
if node is None:
app.nm.createStorage(uuid=uuid)
# load partition in memory
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -44,7 +44,7 @@ class StorageServiceHandler(BaseServiceHandler):
def askLastIDs(self, conn, packet):
app = self.app
conn.answer(Packets.AnswerLastIDs(app.loid, app.ltid, app.pt.getID()),
conn.answer(Packets.AnswerLastIDs(app.loid, app.ltid, app.pt.getID()),
packet.getId())
def askUnfinishedTransactions(self, conn, packet):
......@@ -80,7 +80,7 @@ class StorageServiceHandler(BaseServiceHandler):
p = Packets.NotifyTransactionFinished(tid)
c.answer(p, t.getMessageId())
else:
p = Packets.InvalidateObjects(t.getOIDList(),
p = Packets.InvalidateObjects(t.getOIDList(),
tid)
c.notify(p)
elif node.isStorage():
......@@ -110,20 +110,20 @@ class StorageServiceHandler(BaseServiceHandler):
continue
offset = cell[0]
logging.debug("node %s is up for offset %s" %
logging.debug("node %s is up for offset %s" %
(dump(node.getUUID()), offset))
# check the storage said it is up to date for a partition it was
# 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 (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()),
%s but where %s for that offset" % (dump(node.getUUID()),
offset, xcell.getState())
raise ProtocolError(msg)
app.pt.setCell(offset, node, CellStates.UP_TO_DATE)
new_cell_list.append(cell)
......@@ -132,7 +132,7 @@ class StorageServiceHandler(BaseServiceHandler):
for feeding_cell in app.pt.getCellList(offset):
if feeding_cell.getState() == CellStates.FEEDING:
app.pt.removeCell(offset, feeding_cell.getNode())
new_cell_list.append((offset, feeding_cell.getUUID(),
new_cell_list.append((offset, feeding_cell.getUUID(),
CellStates.DISCARDED))
break
......
#
# Copyright (C) 2006-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
......@@ -40,7 +40,7 @@ class VerificationHandler(BaseServiceHandler):
def answerUnfinishedTransactions(self, conn, packet, tid_list):
uuid = conn.getUUID()
logging.info('got unfinished transactions %s from %s:%d',
logging.info('got unfinished transactions %s from %s:%d',
tid_list, *(conn.getAddress()))
app = self.app
if app.asking_uuid_dict.get(uuid, True):
......
#
# Copyright (C) 2006-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
......@@ -47,7 +47,7 @@ class PartitionTable(neo.pt.PartitionTable):
raise RuntimeError, 'cannot make a partition table with an ' \
'empty storage node list'
# Take it into account that the number of storage nodes may be less
# Take it into account that the number of storage nodes may be less
# than the number of replicas.
repeats = min(self.nr + 1, len(node_list))
index = 0
......@@ -136,7 +136,7 @@ class PartitionTable(neo.pt.PartitionTable):
if num_cells <= self.nr:
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(),
cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE))
node_count += 1
else:
......@@ -145,18 +145,18 @@ class PartitionTable(neo.pt.PartitionTable):
# If there is a feeding cell already or it is
# out-of-date, just drop the node.
row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(),
cell_list.append((offset, max_cell.getUUID(),
CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1
else:
# Otherwise, use it as a feeding cell for safety.
max_cell.setState(CellStates.FEEDING)
cell_list.append((offset, max_cell.getUUID(),
cell_list.append((offset, max_cell.getUUID(),
CellStates.FEEDING))
# Don't count a feeding cell.
self.count_dict[max_cell.getNode()] -= 1
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(),
cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE))
node_count += 1
......@@ -223,7 +223,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(),
changed_cell_list.append((offset, cell.getUUID(),
CellStates.DISCARDED))
# Add cells, if a row contains less than the number of replicas.
......@@ -237,7 +237,7 @@ class PartitionTable(neo.pt.PartitionTable):
if node is None:
break
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
changed_cell_list.append((offset, node.getUUID(),
changed_cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE))
self.count_dict[node] += 1
num_cells += 1
......@@ -256,7 +256,7 @@ class PartitionTable(neo.pt.PartitionTable):
for cell in row:
if not cell.getNode().isRunning() and not cell.isOutOfDate():
cell.setState(CellStates.OUT_OF_DATE)
cell_list.append((offset, cell.getUUID(),
cell_list.append((offset, cell.getUUID(),
CellStates.OUT_OF_DATE))
return cell_list
......@@ -193,11 +193,11 @@ class Application(object):
def execute(self, args):
"""Execute the command given."""
# print node type : print list of node of the given type
# print node type : print list of node of the given type
# (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
# set node uuid state [1|0] : set the node for the given uuid to the
# set node uuid state [1|0] : set the node for the given uuid to the
# state (RUNNING, DOWN...) and modify the partition if asked
# set cluster name [shutdown|operational] : either shutdown the
# set cluster name [shutdown|operational] : either shutdown the
# cluster or mark it as operational
current_action = action_dict
level = 0
......
#
# Copyright (C) 2006-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
......@@ -24,7 +24,7 @@ from neo.protocol import NodeTypes, NodeStates
class Node(object):
"""This class represents a node."""
def __init__(self, manager, address=None, uuid=None,
def __init__(self, manager, address=None, uuid=None,
state=NodeStates.UNKNOWN):
self._state = state
self._address = address
......@@ -64,7 +64,7 @@ class Node(object):
def __repr__(self):
return '<%s(uuid=%s, address=%s, state=%s)>' % (
self.__class__.__name__,
self.__class__.__name__,
dump(self._uuid),
self._address,
self._state,
......@@ -91,13 +91,13 @@ class Node(object):
return self._state == NodeStates.RUNNING
def isTemporarilyDown(self):
# FIXME: is it like 'unconnected' or UNKNOWN state ?
# FIXME: is it like 'unconnected' or UNKNOWN state ?
return self._state == NodeStates.TEMPORARILY_DOWN
def isDown(self):
# FIXME: is it like 'unconnected' or 'forgotten' ?
return self._state == NodeStates.DOWN
def isBroken(self):
return self._state == NodeStates.BROKEN
......@@ -151,19 +151,19 @@ class MasterNode(Node):
class StorageNode(Node):
"""This class represents a storage node."""
def isStorage(self):
return True
class ClientNode(Node):
"""This class represents a client node."""
def isClient(self):
return True
class AdminNode(Node):
"""This class represents an admin node."""
def isAdmin(self):
return True
......@@ -194,7 +194,7 @@ class NodeManager(object):
def add(self, node):
if node in self._node_set:
return
self._node_set.add(node)
self._node_set.add(node)
self._updateAddress(node, None)
self._updateUUID(node, None)
self.__updateSet(self._type_dict, None, node.__class__, node)
......@@ -305,7 +305,7 @@ class NodeManager(object):
def createClient(self, **kw):
""" Create and register a new client """
return self._createNode(ClientNode, **kw)
def createAdmin(self, **kw):
""" Create and register a new admin """
return self._createNode(AdminNode, **kw)
......@@ -315,7 +315,7 @@ class NodeManager(object):
if klass is None:
raise RuntimeError('Unknown node type : %s' % node_type)
return self._createNode(klass, **kw)
def clear(self, filter=None):
self._node_set.clear()
self._type_dict.clear()
......
This diff is collapsed.
#
# Copyright (C) 2006-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
......@@ -180,7 +180,7 @@ class PartitionTable(object):
break
def load(self, ptid, row_list, nm):
"""
"""
Load the partition table with the specified PTID, discard all previous
content and can be done in multiple calls
"""
......@@ -190,7 +190,7 @@ class PartitionTable(object):
for offset, row in row_list:
assert offset < self.getPartitions() and not self.hasOffset(offset)
for uuid, state in row:
node = nm.getByUUID(uuid)
node = nm.getByUUID(uuid)
# XXX: the node should be known before we receive the partition
# table, so remove this assert when this is checked.
assert node is not None
......@@ -207,7 +207,7 @@ class PartitionTable(object):
return
self.id = ptid
for offset, uuid, state in cell_list:
node = nm.getByUUID(uuid)
node = nm.getByUUID(uuid)
assert node is not None
self.setCell(offset, node, state)
logging.debug('partition table updated')
......@@ -256,7 +256,7 @@ class PartitionTable(object):
line.append('X' * len(node_list))
else:
cell = []
cell_dict = dict([(node_dict.get(x.getUUID(), None), x)
cell_dict = dict([(node_dict.get(x.getUUID(), None), x)
for x in row])
for node in xrange(len(node_list)):
if node in cell_dict:
......@@ -268,7 +268,7 @@ class PartitionTable(object):
logging.debug('pt: %08d: %s', offset - len(line) + 1,
'|'.join(line))
def operational(self):
def operational(self):
if not self.filled():
return False
for row in self.partition_list:
......
......@@ -42,7 +42,7 @@ class Application(object):
# set the cluster name
self.name = config.getCluster()
# set the bind address
self.server = config.getBind()
logging.debug('IP address is %s, port is %d', *(self.server))
......@@ -50,7 +50,7 @@ class Application(object):
# load master node list
self.master_node_list = config.getMasters()
logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes.
self.em = EventManager()
self.nm = NodeManager()
......@@ -108,7 +108,7 @@ class Application(object):
raise RuntimeError('name does not match with the database')
ptid = dm.getPTID()
logging.info("Configuration: uuid=%s, ptid=%s, name=%s, np=%s, nr=%s" \
% (dump(self.uuid), dump(ptid), name, num_partitions,
% (dump(self.uuid), dump(ptid), name, num_partitions,
num_replicas))
def loadPartitionTable(self):
......@@ -137,7 +137,7 @@ class Application(object):
# Make a listening port
handler = identification.IdentificationHandler(self)
self.listening_conn = ListeningConnection(self.em, handler,
self.listening_conn = ListeningConnection(self.em, handler,
addr=self.server, connector_handler=self.connector_handler)
# Connect to a primary master node, verify data, and
......@@ -228,7 +228,7 @@ class Application(object):
self.has_node_information = False
self.has_partition_table = False
self.pt.clear()
self.master_conn.ask(Packets.AskNodeInformation())
self.master_conn.ask(Packets.AskNodeInformation())
self.master_conn.ask(Packets.AskPartitionTable(()))
while not self.has_node_information or not self.has_partition_table:
self.em.poll(1)
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -105,7 +105,7 @@ class MySQLDatabaseManager(DatabaseManager):
return self.query(query)
raise DatabaseFailure('MySQL error %d: %s' % (m[0], m[1]))
return r
def escape(self, s):
"""Escape special characters in a string."""
return self.conn.escape_string(s)
......@@ -326,9 +326,9 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query
self.begin()
try:
q("""DELETE FROM obj WHERE MOD(oid, %d) = %d""" %
q("""DELETE FROM obj WHERE MOD(oid, %d) = %d""" %
(num_partitions, offset))
q("""DELETE FROM trans WHERE MOD(tid, %d) = %d""" %
q("""DELETE FROM trans WHERE MOD(tid, %d) = %d""" %
(num_partitions, offset))
except:
self.rollback()
......@@ -436,7 +436,7 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query
r = q("""SELECT DISTINCT oid FROM obj WHERE MOD(oid, %d) in (%s)
ORDER BY oid DESC LIMIT %d,%d""" \
% (num_partitions, ','.join([str(p) for p in partition_list]),
% (num_partitions, ','.join([str(p) for p in partition_list]),
offset, length))
return [util.p64(t[0]) for t in r]
......@@ -454,8 +454,8 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query
r = q("""SELECT tid FROM trans WHERE MOD(tid, %d) in (%s)
ORDER BY tid DESC LIMIT %d,%d""" \
% (num_partitions,
','.join([str(p) for p in partition_list]),
% (num_partitions,
','.join([str(p) for p in partition_list]),
offset, length))
return [util.p64(t[0]) for t in r]
......
#
# Copyright (C) 2006-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
......@@ -37,7 +37,7 @@ class BaseMasterHandler(BaseStorageHandler):
raise PrimaryFailure('re-election occurs')
def notifyClusterInformation(self, conn, packet, state):
logging.error('ignoring notify cluster information in %s' %
logging.error('ignoring notify cluster information in %s' %
self.__class__.__name__)
def notifyLastOID(self, conn, packet, oid):
......@@ -105,7 +105,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
if t is None:
p = protocol.tidNotFound('%s does not exist' % dump(tid))
else:
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
t[0])
conn.answer(p, packet.getId())
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -38,7 +38,7 @@ class IdentificationHandler(BaseStorageHandler):
node = app.nm.getByUUID(uuid)
# choose the handler according to the node type
if node_type == NodeTypes.CLIENT:
from neo.storage.handlers.client import ClientOperationHandler
from neo.storage.handlers.client import ClientOperationHandler
handler = ClientOperationHandler
if node is None:
node = app.nm.createClient()
......@@ -58,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler):
conn.setHandler(handler)
conn.setUUID(uuid)
node.setUUID(uuid)
args = (NodeTypes.STORAGE, app.uuid, app.server,
args = (NodeTypes.STORAGE, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid)
# accept the identification and trigger an event
conn.answer(Packets.AcceptIdentification(*args), packet.getId())
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -57,13 +57,13 @@ class ReplicationHandler(BaseStorageHandler):
# And, ask more TIDs.
app.replicator.tid_offset += 1000
offset = app.replicator.tid_offset
p = Packets.AskTIDs(offset, offset + 1000,
p = Packets.AskTIDs(offset, offset + 1000,
app.replicator.current_partition.getRID())
conn.ask(p, timeout=300)
else:
# If no more TID, a replication of transactions is finished.
# So start to replicate objects now.
p = Packets.AskOIDs(0, 1000,
p = Packets.AskOIDs(0, 1000,
app.replicator.current_partition.getRID())
conn.ask(p, timeout=300)
app.replicator.oid_offset = 0
......@@ -92,7 +92,7 @@ class ReplicationHandler(BaseStorageHandler):
# Nothing remains, so the replication for this partition is
# finished.
app.replicator.replication_done = True
def answerObjectHistory(self, conn, packet, oid, history_list):
app = self.app
if app.replicator.current_connection is not conn:
......@@ -123,7 +123,7 @@ class ReplicationHandler(BaseStorageHandler):
# Otherwise, acquire more OIDs.
app.replicator.oid_offset += 1000
offset = app.replicator.oid_offset
p = Packets.AskOIDs(offset, offset + 1000,
p = Packets.AskOIDs(offset, offset + 1000,
app.replicator.current_partition.getRID())
conn.ask(p, timeout=300)
......
#
# Copyright (C) 2006-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
......
#
# Copyright (C) 2006-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
......@@ -83,7 +83,7 @@ class VerificationHandler(BaseMasterHandler):
if t is None:
p = protocol.tidNotFound('%s does not exist' % dump(tid))
else:
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
t[0])
conn.answer(p, packet.getId())
......
#
# Copyright (C) 2006-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
......@@ -51,7 +51,7 @@ class Partition(object):
class Replicator(object):
"""This class handles replications of objects and transactions.
Assumptions:
- Client nodes recognize partition changes reasonably quickly.
......@@ -126,7 +126,7 @@ class Replicator(object):
partition.setCriticalTID(tid)
del self.critical_tid_dict[msg_id]
except KeyError:
logging.debug("setCriticalTID raised KeyError for msg_id %s" %
logging.debug("setCriticalTID raised KeyError for msg_id %s" %
(msg_id, ))
def _askCriticalTID(self):
......@@ -152,7 +152,7 @@ class Replicator(object):
# Choose a storage node for the source.
app = self.app
try:
cell_list = app.pt.getCellList(self.current_partition.getRID(),
cell_list = app.pt.getCellList(self.current_partition.getRID(),
readable=True)
node_list = [cell.getNode() for cell in cell_list
if cell.getNodeState() == NodeStates.RUNNING]
......@@ -165,7 +165,7 @@ class Replicator(object):
addr = node.getAddress()
if addr is None:
logging.error("no address known for the selected node %s" %
logging.error("no address known for the selected node %s" %
(dump(node.getUUID()), ))
return
if self.current_connection is not None:
......@@ -178,9 +178,9 @@ class Replicator(object):
if self.current_connection is None:
handler = replication.ReplicationHandler(app)
self.current_connection = ClientConnection(app.em, handler,
self.current_connection = ClientConnection(app.em, handler,
addr = addr, connector_handler = app.connector_handler)
p = Packets.RequestIdentification(NodeTypes.STORAGE,
p = Packets.RequestIdentification(NodeTypes.STORAGE,
app.uuid, app.server, app.name)
self.current_connection.ask(p)
......@@ -196,8 +196,8 @@ class Replicator(object):
self.partition_dict.pop(self.current_partition.getRID())
# Notify to a primary master node that my cell is now up-to-date.
conn = self.primary_master_connection
p = Packets.NotifyPartitionChanges(app.pt.getID(),
[(self.current_partition.getRID(), app.uuid,
p = Packets.NotifyPartitionChanges(app.pt.getID(),
[(self.current_partition.getRID(), app.uuid,
CellStates.UP_TO_DATE)])
conn.notify(p)
except KeyError:
......@@ -209,7 +209,7 @@ class Replicator(object):
# TID to a primary master node.
if self.new_partition_dict:
self._askCriticalTID()
if self.current_partition is None:
# I need to choose something.
if self.waiting_for_unfinished_tids:
......@@ -236,7 +236,7 @@ class Replicator(object):
self._askUnfinishedTIDs()
else:
if self.replication_done:
logging.info('replication is done for %s' %
logging.info('replication is done for %s' %
(self.current_partition.getRID(), ))
self._finishReplication()
......
#
# 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
......@@ -53,12 +53,12 @@ class NeoTestBase(unittest.TestCase):
database = "%s%d" % (prefix, i)
cursor.execute('DROP DATABASE IF EXISTS %s' % (database, ))
cursor.execute('CREATE DATABASE %s' % (database, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(database, user))
cursor.close()
sql_connection.close()
def getMasterConfiguration(self, cluster='main', master_number=2,
def getMasterConfiguration(self, cluster='main', master_number=2,
replicas=2, partitions=1009, uuid=None):
assert master_number >= 1 and master_number <= 10
masters = [('127.0.0.1', 10010 + i) for i in xrange(master_number)]
......@@ -71,7 +71,7 @@ class NeoTestBase(unittest.TestCase):
'getUUID': uuid,
})
def getStorageConfiguration(self, cluster='main', master_number=2,
def getStorageConfiguration(self, cluster='main', master_number=2,
index=0, prefix=DB_PREFIX, uuid=None):
assert master_number >= 1 and master_number <= 10
assert index >= 0 and index <= 9
......@@ -87,9 +87,9 @@ class NeoTestBase(unittest.TestCase):
'getReset': False,
'getAdapter': 'MySQL',
})
# XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods
# XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods
def getNewUUID(self):
self.uuid = getNewUUID()
return self.uuid
......@@ -343,11 +343,11 @@ class TestElectionConnector(DoNothingConnector):
# second : answer primary master nodes
logging.info("in patched analyse / ANSWER PM")
p = protocol.Packet()
p.answerPrimary(2, protocol.INVALID_UUID, [])
p.answerPrimary(2, protocol.INVALID_UUID, [])
self.packet_cpt += 1
return p.encode()
else:
# then do nothing
from neo.connector import ConnectorTryAgainException
raise ConnectorTryAgainException
This diff is collapsed.
#
# 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
......@@ -92,8 +92,8 @@ class ClientHandlerTests(NeoTestBase):
storage_port = 10011
fake_storage_node_uuid = self.getNewUUID()
fake_storage_node = Mock({
'getUUID': fake_storage_node_uuid,
'getAddress': (storage_ip, storage_port),
'getUUID': fake_storage_node_uuid,
'getAddress': (storage_ip, storage_port),
'getType': NodeTypes.STORAGE
})
master_node_next_packet_id = 1
......@@ -121,7 +121,7 @@ class ClientHandlerTests(NeoTestBase):
key_2: queue_2}
dispatcher = Dispatcher()
method(dispatcher, app, handler_class, conn=conn)
# The master should be notified, but this is done in app.py
# The master should be notified, but this is done in app.py
# Check that failed connection got removed from connection pool
removeConnection_call_list = app.cp.mockGetNamedCalls('removeConnection')
# Test sanity check
......@@ -143,7 +143,7 @@ class ClientHandlerTests(NeoTestBase):
self._testInitialMasterWithMethod(self._testConnectionFailed)
def test_storageConnectionFailed(self):
self._testStorageWithMethod(self._testConnectionFailed,
self._testStorageWithMethod(self._testConnectionFailed,
StorageBootstrapHandler)
def _testConnectionClosed(self, dispatcher, app, handler_class, uuid=None, conn=None):
......@@ -160,7 +160,7 @@ class ClientHandlerTests(NeoTestBase):
PrimaryNotificationsHandler)
def test_storageConnectionClosed(self):
self._testStorageWithMethod(self._testConnectionClosed,
self._testStorageWithMethod(self._testConnectionClosed,
StorageBootstrapHandler)
def _testTimeoutExpired(self, dispatcher, app, handler_class, uuid=None, conn=None):
......@@ -176,7 +176,7 @@ class ClientHandlerTests(NeoTestBase):
self._testMasterWithMethod(self._testTimeoutExpired, PrimaryNotificationsHandler)
def test_storageTimeoutExpired(self):
self._testStorageWithMethod(self._testTimeoutExpired,
self._testStorageWithMethod(self._testTimeoutExpired,
StorageBootstrapHandler)
def _testPeerBroken(self, dispatcher, app, handler_class, uuid=None, conn=None):
......@@ -215,9 +215,9 @@ class ClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID()
app.uuid = 'C' * 16
client_handler.acceptIdentification(
conn, None,
conn, None,
NodeTypes.CLIENT,
uuid, ('127.0.0.1', 10010),
uuid, ('127.0.0.1', 10010),
0, 0, INVALID_UUID
)
self.checkClosed(conn)
......@@ -242,7 +242,7 @@ class ClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID()
your_uuid = 'C' * 16
app.uuid = INVALID_UUID
client_handler.AcceptIdentification(conn, None,
client_handler.AcceptIdentification(conn, None,
NodeTypes.MASTER, uuid, ('127.0.0.1', 10010), 10, 2, your_uuid)
self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid)
......@@ -262,7 +262,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection()
uuid = self.getNewUUID()
app.uuid = 'C' * 16
client_handler.acceptIdentification(conn, None,
client_handler.acceptIdentification(conn, None,
NodeTypes.STORAGE, uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID)
self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid)
......@@ -538,7 +538,7 @@ class ClientHandlerTests(NeoTestBase):
conn, None, None)
def _testNotifyNodeInformation(self, test_node, getByAddress=None, getByUUID=MARKER):
invalid_uid_test_node = (test_node[0], (test_node[1][0],
invalid_uid_test_node = (test_node[0], (test_node[1][0],
test_node[1][1] + 1), INVALID_UUID, test_node[3])
test_node_list = [test_node, invalid_uid_test_node]
test_master_uuid = self.getNewUUID()
......
#
# 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
......
#
# 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
......@@ -128,7 +128,7 @@ class NEOCluster(object):
partitions=1, replicas=0, port_base=10000,
db_user='neo', db_password='neo',
db_super_user='root', db_super_password=None,
cleanup_on_delete=False, temp_dir=None,
cleanup_on_delete=False, temp_dir=None,
clear_databases=True, adapter='MySQL'):
self.cleanup_on_delete = cleanup_on_delete
self.uuid_set = set()
......@@ -187,7 +187,7 @@ class NEOCluster(object):
arguments['--verbose'] = None
logfile = arguments['--name']
arguments['--logfile'] = os.path.join(self.temp_dir, '%s.log' % (logfile, ))
self.process_dict.setdefault(command, []).append(
self.process_dict.setdefault(command, []).append(
NEOProcess(command, uuid, arguments))
def __allocatePort(self):
......@@ -387,13 +387,13 @@ class NEOCluster(object):
current_try = self.__getNodeState(node_type, uuid)
return current_try in state, current_try
self.expectCondition(callback, timeout, delay)
def expectMasterState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(NodeTypes.MASTER, uuid, state, timeout,
delay)
def expectStorageState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
timeout,delay)
def expectPrimary(self, uuid=None, timeout=0, delay=1):
......@@ -464,5 +464,5 @@ class NEOFunctionalTest(unittest.TestCase):
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
return temp_dir
#
# 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
......@@ -29,7 +29,7 @@ class ClusterTests(NEOFunctionalTest):
self.neo.stop()
def testClusterBreaks(self):
self.neo = NEOCluster(['test_neo1'], port_base=20000,
self.neo = NEOCluster(['test_neo1'], port_base=20000,
master_node_count=1, temp_dir=self.getTempDirectory())
neoctl = self.neo.getNEOCTL()
self.neo.setupDB()
......
#
# 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
......@@ -69,7 +69,7 @@ class ImportExportTests(NEOFunctionalTest):
storage = FileStorage(file_name=name)
db = ZODB.DB(storage=storage)
return (db, storage)
def __populate(self, db, tree_size=TREE_SIZE):
conn = db.open()
root = conn.root()
......@@ -111,7 +111,7 @@ class ImportExportTests(NEOFunctionalTest):
root = conn.root()
self.__checkTree(root['trees'])
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
......@@ -26,7 +26,7 @@ class MasterTests(NEOFunctionalTest):
def setUp(self):
NEOFunctionalTest.setUp(self)
self.neo = NEOCluster([], port_base=20000,
self.neo = NEOCluster([], port_base=20000,
master_node_count=MASTER_NODE_COUNT,
temp_dir=self.getTempDirectory())
self.neo.stop()
......@@ -68,7 +68,7 @@ class MasterTests(NEOFunctionalTest):
self.assertNotEqual(new_uuid, uuid)
def testStoppingPrimaryWithOneSecondary(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT,
self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=NodeStates.RUNNING)
# Kill one secondary master.
......@@ -92,7 +92,7 @@ class MasterTests(NEOFunctionalTest):
self.assertNotEqual(new_uuid, uuid)
def testMasterSequentialStart(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT,
self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=NodeStates.RUNNING)
master_list = self.neo.getMasterProcessList()
......@@ -112,11 +112,11 @@ class MasterTests(NEOFunctionalTest):
# Start a second master.
second_master = master_list[1]
# Check that the second master is known as being down.
self.assertEqual(self.neo.getMasterNodeState(second_master.getUUID()),
self.assertEqual(self.neo.getMasterNodeState(second_master.getUUID()),
None)
second_master.start()
# Check that the second master is running under his known UUID.
self.neo.expectMasterState(second_master.getUUID(),
self.neo.expectMasterState(second_master.getUUID(),
NodeStates.RUNNING)
# Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimary(), first_master_uuid)
......@@ -124,11 +124,11 @@ class MasterTests(NEOFunctionalTest):
# Start a third master.
third_master = master_list[2]
# Check that the third master is known as being down.
self.assertEqual(self.neo.getMasterNodeState(third_master.getUUID()),
self.assertEqual(self.neo.getMasterNodeState(third_master.getUUID()),
None)
third_master.start()
# Check that the third master is running under his known UUID.
self.neo.expectMasterState(third_master.getUUID(),
self.neo.expectMasterState(third_master.getUUID(),
NodeStates.RUNNING)
# Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimary(), first_master_uuid)
......
#
# 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
......@@ -23,7 +23,7 @@ from neo.tests.functional import NEOCluster, NEOFunctionalTest
from neo.protocol import ClusterStates, NodeStates
class PObject(Persistent):
def __init__(self, value):
self.value = value
......@@ -45,7 +45,7 @@ class StorageTests(NEOFunctionalTest):
result = db.store_result().fetch_row()[0][0]
return result
def __setup(self, storage_number=2, pending_number=0, replicas=1,
def __setup(self, storage_number=2, pending_number=0, replicas=1,
partitions=10, master_node_count=2):
# create a neo cluster
self.neo = NEOCluster(['test_neo%d' % i for i in xrange(storage_number)],
......@@ -68,7 +68,7 @@ class StorageTests(NEOFunctionalTest):
db, conn = self.neo.getZODBConnection()
root = conn.root()
for i in xrange(OBJECT_NUMBER):
root[i] = PObject(i)
root[i] = PObject(i)
transaction.commit()
conn.close()
db.close()
......@@ -86,7 +86,7 @@ class StorageTests(NEOFunctionalTest):
# One revision per object and two for the root, before and after
revisions = self.queryCount(db, 'select count(*) from obj')
self.assertEqual(revisions, OBJECT_NUMBER + 2)
# One object more for the root
# One object more for the root
query = 'select count(*) from (select * from obj group by oid) as t'
objects = self.queryCount(db, query)
self.assertEqual(objects, OBJECT_NUMBER + 1)
......@@ -111,7 +111,7 @@ class StorageTests(NEOFunctionalTest):
def __expectPending(self, process):
self.neo.expectStorageState(process.getUUID(), NodeStates.PENDING)
def __expectUnavailable(self, process):
self.neo.expectStorageState(process.getUUID(),
NodeStates.TEMPORARILY_DOWN)
......@@ -124,7 +124,7 @@ class StorageTests(NEOFunctionalTest):
return False, storage
return True, None
self.neo.expectCondition(expected_storage_not_known)
def testReplicationWithoutBreak(self):
""" Start a cluster with two storage, one replicas, the two databasqes
must have the same content """
......@@ -178,7 +178,7 @@ class StorageTests(NEOFunctionalTest):
self.neo.expectAssignedCells(stopped[0].getUUID(), number=10)
self.neo.expectClusterRunning()
# wait for replication to finish then check
# wait for replication to finish then check
self.__checkReplicationDone()
self.neo.expectClusterRunning()
......@@ -284,7 +284,7 @@ class StorageTests(NEOFunctionalTest):
with one storage and no replicas """
# start with one storage and no replicas
(started, stopped) = self.__setup(storage_number=2, pending_number=1,
(started, stopped) = self.__setup(storage_number=2, pending_number=1,
partitions=10, replicas=0)
self.__expectRunning(started[0])
self.neo.expectClusterRunning()
......@@ -299,10 +299,10 @@ class StorageTests(NEOFunctionalTest):
self.neo.expectClusterRunning()
self.neo.expectOudatedCells(number=0)
# the partition table must change, each node should be assigned to
# the partition table must change, each node should be assigned to
# five partitions
self.neo.expectAssignedCells(started[0].getUUID(), 5)
self.neo.expectAssignedCells(stopped[0].getUUID(), 5)
self.neo.expectAssignedCells(started[0].getUUID(), 5)
self.neo.expectAssignedCells(stopped[0].getUUID(), 5)
def testPartitionTableReorganizedAfterDrop(self):
""" Check that the partition change when dropping a replicas from a
......@@ -324,7 +324,7 @@ class StorageTests(NEOFunctionalTest):
# and the partition table must not change
self.neo.expectAssignedCells(started[0].getUUID(), 10)
self.neo.expectAssignedCells(started[1].getUUID(), 10)
# ask neoctl to drop it
self.neo.neoctl.dropNode(started[0].getUUID())
self.__expectNotKnown(started[0])
......@@ -335,7 +335,7 @@ class StorageTests(NEOFunctionalTest):
""" Add a replicas to a cluster, wait for the replication to finish,
shutdown the first storage then check the new storage content """
# start with one storage
# start with one storage
(started, stopped) = self.__setup(storage_number=2, replicas=1,
pending_number=1, partitions=10)
self.__expectRunning(started[0])
......@@ -416,6 +416,6 @@ class StorageTests(NEOFunctionalTest):
self.__expectPending(started[0])
self.__expectRunning(started[1])
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
......@@ -50,7 +50,7 @@ class MasterClientHandlerTests(NeoTestBase):
# register the storage
kw = {'uuid':self.getNewUUID(), 'address': self.master_address}
self.app.nm.createStorage(**kw)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -64,7 +64,7 @@ class MasterClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID()
self.app.nm.createFromNodeType(
node_type,
address=(ip, port),
address=(ip, port),
uuid=uuid,
state=NodeStates.RUNNING,
)
......@@ -104,7 +104,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care
self.app.nm.createStorage(
address=("127.0.0.1", 11011),
address=("127.0.0.1", 11011),
uuid=self.getNewUUID(),
)
conn = self.getFakeConnection(uuid, self.storage_address)
......@@ -141,7 +141,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(sn.getState(), NodeStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID())
def test_06_answerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
......@@ -167,9 +167,9 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID())
def test_07_askBeginTransaction(self):
def test_07_askBeginTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packets.AskBeginTransaction()
......@@ -184,7 +184,7 @@ class MasterClientHandlerTests(NeoTestBase):
tid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, self.app.ltid)
def test_08_askNewOIDs(self):
def test_08_askNewOIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packets.AskNewOIDs()
......@@ -243,7 +243,7 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
service.abortTransaction(conn, packet, None)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
# give a known tid
conn = self.getFakeConnection(client_uuid, self.client_address)
tid = self.app.ltid
......@@ -268,7 +268,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEqual(loid, self.app.loid)
self.assertEqual(ltid, self.app.ltid)
self.assertEqual(lptid, ptid)
def test_13_askUnfinishedTransactions(self):
service = self.service
......@@ -292,7 +292,7 @@ class MasterClientHandlerTests(NeoTestBase):
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3)
def test_15_peerBroken(self):
service = self.service
......@@ -310,14 +310,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -333,10 +333,10 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_16_timeoutExpired(self):
service = self.service
......@@ -354,14 +354,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -377,7 +377,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......@@ -398,14 +398,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -421,7 +421,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......
This diff is collapsed.
#
# 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
......@@ -49,11 +49,11 @@ class MasterAppTests(NeoTestBase):
def test_06_broadcastNodeInformation(self):
# defined some nodes to which data will be send
master_uuid = self.getNewUUID()
master_uuid = self.getNewUUID()
self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID()
storage_uuid = self.getNewUUID()
storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID()
client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid)
self.app.nm.add(storage)
self.app.nm.add(client)
......@@ -77,7 +77,7 @@ class MasterAppTests(NeoTestBase):
client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createClient(
uuid = self.getNewUUID(),
uuid = self.getNewUUID(),
address=("127.1.0.1", 3361)
)
self.app.broadcastNodeInformation(c_node)
......@@ -85,14 +85,14 @@ class MasterAppTests(NeoTestBase):
self.checkNoPacketSent(client_conn)
self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn)
# address defined and storage type
master_conn = Mock({"getUUID" : master_uuid})
storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createStorage(
uuid=self.getNewUUID(),
uuid=self.getNewUUID(),
address=("127.0.0.1", 1351)
)
......
#
# 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
......@@ -154,7 +154,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
def test_14_addNode(self):
num_partitions = 5
num_replicas = 2
......@@ -233,9 +233,9 @@ class MasterPartitionTableTests(NeoTestBase):
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
self.failUnless(offset in (0, 1))
self.failUnless(offset in (0, 1))
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 2)
self.assertEqual(len(pt.getCellList(x)), 2)
# there is a feeding cell, just dropped
pt.clear()
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
......@@ -262,9 +262,9 @@ class MasterPartitionTableTests(NeoTestBase):
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
self.failUnless(offset in (0, 1))
self.failUnless(offset in (0, 1))
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 3)
self.assertEqual(len(pt.getCellList(x)), 3)
# there is no feeding cell, marked as feeding
pt.clear()
pt.setCell(0, sn1, CellStates.UP_TO_DATE)
......@@ -287,10 +287,10 @@ class MasterPartitionTableTests(NeoTestBase):
else:
self.failUnless(uuid in (uuid1, uuid6))
else:
self.failUnless(offset in (0, 1))
self.failUnless(offset in (0, 1))
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 3)
def test_15_dropNode(self):
num_partitions = 4
num_replicas = 2
......@@ -333,7 +333,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(state, CellStates.OUT_OF_DATE)
else:
self.failUnless(uuid in (uuid2, uuid4))
for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 2)
# same test but with feeding state, no other will be added
......@@ -357,7 +357,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getCellList(x)), 1)
else:
self.assertEqual(len(pt.getCellList(x)), 2)
def test_16_make(self):
num_partitions = 5
num_replicas = 1
......@@ -408,7 +408,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(node, sn1)
self.assertTrue(pt.filled())
self.assertTrue(pt.operational())
def test_17_tweak(self):
# remove broken node
# remove if too many feeding nodes
......@@ -472,7 +472,7 @@ class MasterPartitionTableTests(NeoTestBase):
else:
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn2 in [x.getNode() for x in cells])
# check part 2
cells = pt.getCellList(1)
self.assertEqual(len(cells), 4)
......@@ -483,7 +483,7 @@ class MasterPartitionTableTests(NeoTestBase):
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])
# check part 3
cells = pt.getCellList(2)
self.assertEqual(len(cells), 3)
......
#
# 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
......@@ -46,7 +46,7 @@ class MasterRecoveryTests(NeoTestBase):
self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -66,29 +66,29 @@ class MasterRecoveryTests(NeoTestBase):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
NodeStates.RUNNING)
self.recovery.connectionClosed(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
NodeStates.TEMPORARILY_DOWN)
def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
NodeStates.RUNNING)
self.recovery.timeoutExpired(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
NodeStates.TEMPORARILY_DOWN)
def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
NodeStates.RUNNING)
self.recovery.peerBroken(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN)
NodeStates.BROKEN)
def test_08_notifyNodeInformation(self):
recovery = self.recovery
......@@ -146,7 +146,7 @@ class MasterRecoveryTests(NeoTestBase):
recovery.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.DOWN)
def test_09_answerLastIDs(self):
recovery = self.recovery
......@@ -213,8 +213,8 @@ class MasterRecoveryTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(offset))
cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)]
self.checkUnexpectedPacketRaised(recovery.answerPartitionTable, conn, packet, None, cell_list)
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
......@@ -47,8 +47,8 @@ class MasterStorageHandlerTests(NeoTestBase):
self.master_address = ('127.0.0.1', self.master_port)
self.client_address = ('127.0.0.1', self.client_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -96,7 +96,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care
self.app.nm.createStorage(
address=("127.0.0.1", 11011),
address=("127.0.0.1", 11011),
uuid=self.getNewUUID(),
)
conn = self.getFakeConnection(uuid, self.storage_address)
......@@ -150,7 +150,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID())
def test_10_notifyInformationLocked(self):
service = self.service
uuid = self.identifyToMasterNode(port=10020)
......@@ -192,7 +192,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.checkNotifyTransactionFinished(conn)
self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2)
def test_12_askLastIDs(self):
service = self.service
......@@ -210,7 +210,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
self.assertEqual(lptid, ptid)
def test_13_askUnfinishedTransactions(self):
service = self.service
......@@ -235,7 +235,7 @@ class MasterStorageHandlerTests(NeoTestBase):
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3)
def test_14_notifyPartitionChanges(self):
service = self.service
......@@ -245,7 +245,7 @@ class MasterStorageHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
self.checkUnexpectedPacketRaised(service.notifyPartitionChanges,
self.checkUnexpectedPacketRaised(service.notifyPartitionChanges,
conn, packet, None, None)
# send a bad state, must not be take into account
......@@ -290,7 +290,7 @@ class MasterStorageHandlerTests(NeoTestBase):
if cell == storage_uuid:
self.assertEquals(state, CellStates.FEEDING)
else:
self.assertEquals(state, CellStates.OUT_OF_DATE)
self.assertEquals(state, CellStates.OUT_OF_DATE)
lptid = self.app.pt.getID()
service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
self.failUnless(lptid < self.app.pt.getID())
......@@ -300,7 +300,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(state, CellStates.UP_TO_DATE)
else:
self.assertEquals(state, CellStates.DISCARDED)
def test_15_peerBroken(self):
service = self.service
......@@ -323,14 +323,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -346,10 +346,10 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_16_timeoutExpired(self):
service = self.service
......@@ -372,14 +372,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -395,7 +395,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......@@ -421,14 +421,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -444,7 +444,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......
#
# 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
......@@ -23,7 +23,7 @@ from neo.protocol import Packet, Packets
from neo.protocol import NodeTypes, NodeStates, ErrorCodes
from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application
from neo.exception import VerificationFailure
from neo.exception import VerificationFailure
class MasterVerificationTests(NeoTestBase):
......@@ -53,7 +53,7 @@ class MasterVerificationTests(NeoTestBase):
self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -67,7 +67,7 @@ class MasterVerificationTests(NeoTestBase):
"""
uuid = self.getNewUUID()
self.app.nm.createFromNodeType(
node_type,
node_type,
address=(ip, port),
uuid=uuid,
)
......@@ -141,7 +141,7 @@ class MasterVerificationTests(NeoTestBase):
upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10)
verification.answerUnfinishedTransactions(conn, packet, [new_tid])
self.assertEquals(len(self.app.unfinished_tid_set), 0)
self.assertEquals(len(self.app.unfinished_tid_set), 0)
# update dict
conn = self.getFakeConnection(uuid, self.storage_address)
self.app.asking_uuid_dict[uuid] = False
......@@ -171,7 +171,7 @@ class MasterVerificationTests(NeoTestBase):
new_oid = pack('!Q', oid + 1)
verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None)
self.assertEquals(self.app.unfinished_oid_set, None)
# do nothing as asking_uuid_dict is True
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
......@@ -226,7 +226,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.tidNotFound(conn, packet, "msg")
self.assertEqual(self.app.unfinished_oid_set, None)
def test_14_answerObjectPresent(self):
verification = self.verification
uuid = self.identifyToMasterNode()
......@@ -248,7 +248,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertFalse(self.app.asking_uuid_dict[uuid])
verification.answerObjectPresent(conn, packet, new_oid, new_tid)
self.assertTrue(self.app.asking_uuid_dict[uuid])
def test_15_oidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
......@@ -270,7 +270,7 @@ class MasterVerificationTests(NeoTestBase):
verification.oidNotFound(conn, packet, "msg")
self.assertFalse(self.app.object_present)
self.assertTrue(self.app.asking_uuid_dict[uuid ])
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
......@@ -33,9 +33,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageClientHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
packet = Packet(msg_type=_msg_type)
# hook
......@@ -130,9 +130,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet.setId(0)
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn)
......@@ -145,9 +145,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0)
......@@ -162,9 +162,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn)
......@@ -256,7 +256,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.app.store_lock_dict[oid] = tid1
self.assertTrue(oid in self.app.store_lock_dict)
t_before = self.app.transaction_dict.items()[:]
self.operation.askStoreObject(conn, packet, oid,
self.operation.askStoreObject(conn, packet, oid,
INVALID_SERIAL, 0, 0, '', tid2)
self.assertEquals(len(self.app.event_queue), 1)
t_after = self.app.transaction_dict.items()[:]
......@@ -271,14 +271,14 @@ class StorageClientHandlerTests(NeoTestBase):
conn = Mock({'getUUID': self.app.uuid})
tid1, tid2 = self.getTwoIDs()
self.app.store_lock_dict[INVALID_OID] = tid2
self.operation.askStoreObject(conn, packet, INVALID_OID,
self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', tid1)
self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2)
# conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_askStoreObject4(self):
# resolvable conflict => answer
packet = Packets.AskStoreObject()
......@@ -286,20 +286,20 @@ class StorageClientHandlerTests(NeoTestBase):
conn = Mock({'getUUID': self.app.uuid})
self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )})
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
self.operation.askStoreObject(conn, packet, INVALID_OID,
self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID)
self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
# conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_askStoreObject5(self):
# no conflict => answer
packet = Packets.AskStoreObject()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
self.operation.askStoreObject(conn, packet, INVALID_OID,
self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID)
t = self.app.transaction_dict.get(INVALID_TID, None)
self.assertNotEquals(t, None)
......
#
# 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
......@@ -48,7 +48,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
# Common methods
def getLastUUID(self):
return self.uuid
def test_02_timeoutExpired(self):
# client connection
uuid = self.getNewUUID()
......@@ -91,7 +91,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
node_1 = self.getNewUUID()
node_2 = self.getNewUUID()
node_3 = self.getNewUUID()
# SN already know all nodes
# SN already know all nodes
self.app.nm.createStorage(uuid=node_1)
self.app.nm.createStorage(uuid=node_2)
self.app.nm.createStorage(uuid=node_3)
......@@ -118,7 +118,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.assertEqual(self.app.pt.getID(), 2)
self.assertNotEqual(self.app.dm.getPartitionTable(), [])
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
......@@ -32,9 +32,9 @@ from neo.protocol import INVALID_TID, INVALID_OID
class StorageMasterHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
packet = Packet(msg_type=_msg_type)
# hook
......@@ -97,7 +97,7 @@ class StorageMasterHandlerTests(NeoTestBase):
app = self.app
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port),
})
app.replicator = Mock({})
packet = Packets.NotifyPartitionChanges()
......@@ -122,7 +122,7 @@ class StorageMasterHandlerTests(NeoTestBase):
# context
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packets.NotifyPartitionChanges()
app = self.app
......
#
# 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
......@@ -32,7 +32,7 @@ class StorageAppTests(NeoTestBase):
config = self.getStorageConfiguration(master_number=1)
self.app = Application(config)
self.app.event_queue = deque()
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -55,11 +55,11 @@ class StorageAppTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(x))
# add some node, will be remove when loading table
master_uuid = self.getNewUUID()
master_uuid = self.getNewUUID()
master = self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID()
storage_uuid = self.getNewUUID()
storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID()
client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid)
self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
......@@ -92,21 +92,21 @@ class StorageAppTests(NeoTestBase):
# fill partition table
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)" %
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(0, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(master_uuid), CellStates.UP_TO_DATE))
self.assertEqual(len(self.app.dm.getPartitionTable()), 5)
self.app.pt.clear()
self.app.loadPartitionTable()
self.assertTrue(self.app.pt.filled())
for x in xrange(num_partitions):
for x in xrange(num_partitions):
self.assertTrue(self.app.pt.hasOffset(x))
# check each row
cell_list = self.app.pt.getCellList(0)
......@@ -120,7 +120,7 @@ class StorageAppTests(NeoTestBase):
self.assertEqual(len(cell_list), 2)
self.failUnless(cell_list[0].getUUID() in (master_uuid, storage_uuid))
self.failUnless(cell_list[1].getUUID() in (master_uuid, storage_uuid))
def test_02_queueEvent(self):
self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136})
......@@ -131,7 +131,7 @@ class StorageAppTests(NeoTestBase):
self.assertEqual(len(args), 1)
self.assertEqual(args[0], "test")
self.assertEqual(kw, {"key" : "value"})
def test_03_executeQueuedEvents(self):
self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136})
......
#
# 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
......@@ -30,9 +30,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageStorageHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
packet = Packet(msg_type=_msg_type)
# hook
......@@ -87,9 +87,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject()
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn)
......@@ -102,9 +102,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0)
......@@ -119,9 +119,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn)
......
#
# 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
......@@ -85,13 +85,13 @@ class StorageMySQSLdbTests(NeoTestBase):
self.db.rollback()
self.assertEquals(len(self.db.conn.mockGetNamedCalls('rollback')), 1)
self.assertEquals(self.db.isUnderTransaction(), False)
def test_07_query1(self):
# fake result object
from array import array
result_object = Mock({
"num_rows": 1,
"fetch_row": ((1, 2, array('b', (1, 2, ))), ),
"fetch_row": ((1, 2, array('b', (1, 2, ))), ),
})
# expected formatted result
expected_result = (
......@@ -180,7 +180,7 @@ class StorageMySQSLdbTests(NeoTestBase):
def test_12_UUID(self):
self.checkConfigEntry(
get_call=self.db.getUUID,
get_call=self.db.getUUID,
set_call=self.db.setUUID,
value='TEST_VALUE')
......@@ -209,7 +209,7 @@ class StorageMySQSLdbTests(NeoTestBase):
# insert an entry and check it
self.db.setup()
rid, uuid, state = '\x00' * 8, '\x00' * 16, 0
self.db.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
self.db.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(dump(rid), dump(uuid), state))
pt = self.db.getPartitionTable()
self.assertEquals(pt, [(0L, uuid, state)])
......@@ -276,7 +276,7 @@ class StorageMySQSLdbTests(NeoTestBase):
self.assertTrue(self.db.objectPresent(oid1, tid1, all=True))
self.assertTrue(self.db.objectPresent(oid2, tid2, all=False))
self.assertTrue(self.db.objectPresent(oid2, tid2, all=True))
def test_21_getObject(self):
self.db.setup()
oid1, tid1 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x01'
......@@ -473,7 +473,7 @@ class StorageMySQSLdbTests(NeoTestBase):
result = self.db.query('select * from ttrans')
self.assertEquals(len(result), 1)
self.assertEquals(result[0], (2L, oid1 + oid2, 'u', 'd', 'e',))
def test_26_deleteTransaction(self):
# data set
tid1, tid2 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x02'
......@@ -561,7 +561,7 @@ class StorageMySQSLdbTests(NeoTestBase):
self.db.query("""replace into trans (tid, oids, user, description, ext)
values ('%s', '%s', 'u', 'd', 'e')""" % (u64(tid1), 'OIDs_'))
self.assertRaises(DatabaseFailure, self.db.getTransaction, tid1)
def test_28_getOIDList(self):
# there are two partitions and two objects in each of them
# o1 & o3 in p1, o2 & o4 in p2
......@@ -569,9 +569,9 @@ class StorageMySQSLdbTests(NeoTestBase):
tid = '\x00' * 7 + '\x01'
oid1, oid2, oid3, oid4 = ['\x00' * 7 + chr(i) for i in xrange(4)]
for oid in (oid1, oid2, oid3, oid4):
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid)))
# get all oids for all partitions
# get all oids for all partitions
result = self.db.getOIDList(0, 4, 2, (0, 1))
self.assertEquals(result, [oid4, oid3, oid2, oid1])
# get all oids but from the second with a limit a two
......@@ -596,7 +596,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tids = ['\x00' * 7 + chr(i) for i in xrange(4)]
oid = '\x00' * 8
for tid in tids:
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid)))
# unkwown object
result = self.db.getObjectHistory(oid='\x01' * 8)
......@@ -619,9 +619,9 @@ class StorageMySQSLdbTests(NeoTestBase):
tids = ['\x00' * 7 + chr(i) for i in xrange(4)]
tid1, tid2, tid3, tid4 = tids
for tid in tids:
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
(u64(tid)))
# get all tids for all partitions
# get all tids for all partitions
result = self.db.getTIDList(0, 4, 2, (0, 1))
self.assertEquals(result, [tid4, tid3, tid2, tid1])
# get all tids but from the second with a limit a two
......@@ -646,7 +646,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tid = '\x00' * 7 + '\x01'
tid1, tid2, tid3, tid4 = ['\x00' * 7 + chr(i) for i in xrange(4)]
for tid in (tid1, tid2, tid3, tid4):
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
(u64(tid)))
# all match
result = self.db.getTIDListPresent((tid1, tid2, tid3, tid4))
......@@ -666,7 +666,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tid1, tid2, tid3, tid4 = tids
oid = '\x00' * 8
for tid in tids:
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid)))
# all match
result = self.db.getSerialListPresent(oid, tids)
......
#
# 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
......@@ -44,7 +44,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.load_lock_dict = {}
self.app.pt = PartitionTable(self.num_partitions, self.num_replicas)
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -131,7 +131,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.assertEqual(oid, last_oid)
self.assertEqual(u64(tid), 4)
self.assertEqual(ptid, self.app.pt.getID())
def test_08_askPartitionTable(self):
uuid = self.getNewUUID()
packet = Mock()
......@@ -151,7 +151,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# try to get known offset
node = self.app.nm.createStorage(
address=("127.7.9.9", 1),
address=("127.7.9.9", 1),
uuid=self.getNewUUID()
)
self.app.pt.setCell(1, node, CellStates.UP_TO_DATE)
......@@ -170,7 +170,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# old partition change
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packets.NotifyPartitionChanges()
self.verification.notifyPartitionChanges(conn, packet, 1, ())
......@@ -180,7 +180,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# new node
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packets.NotifyPartitionChanges()
new_uuid = self.getNewUUID()
......@@ -250,7 +250,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.query("""insert into ttrans (tid, oids, user,
description, ext) values (3, '%s', 'u1', 'd1', 'e1')""" %(p64(4),))
self.app.dm.query("""insert into trans (tid, oids, user,
description, ext) values (1,'%s', 'u2', 'd2', 'e2')""" %(p64(2),))
description, ext) values (1,'%s', 'u2', 'd2', 'e2')""" %(p64(2),))
self.app.dm.commit()
# object from trans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
......@@ -299,7 +299,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(2))
code, message = self.checkErrorPacket(conn, decode=True)
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
def test_15_askObjectPresent(self):
......
#
# 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
......@@ -37,7 +37,7 @@ class BootstrapManagerTests(NeoTestBase):
self.storage_port = 10020
self.num_partitions = 1009
self.num_replicas = 2
def tearDown(self):
NeoTestBase.tearDown(self)
......@@ -54,14 +54,14 @@ class BootstrapManagerTests(NeoTestBase):
self.checkAskPrimary(conn)
def testHandleNotReady(self):
# the primary is not ready
# the primary is not ready
conn = Mock({})
packet = Mock({})
self.bootstrap.notReady(conn, packet, '')
self.checkClosed(conn)
self.checkNoPacketSent(conn)
if __name__ == "__main__":
unittest.main()
This diff is collapsed.
#
# 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
......
#
# 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
......@@ -67,7 +67,7 @@ class EventTests(NeoTestBase):
event = Mock()
self.assertEqual(len(em.event_list), 0)
em.addIdleEvent(event)
self.assertEqual(len(em.event_list), 1)
self.assertEqual(len(em.event_list), 1)
em.removeIdleEvent(event)
self.assertEqual(len(em.event_list), 0)
em.removeIdleEvent(event) # must not fail
......@@ -146,7 +146,7 @@ class EventTests(NeoTestBase):
critical_time = event.getCriticalTime()
self.assertEqual(critical_time, time+20)
# call with t < time < critical_time
# call with t < time < critical_time
t = time - 10
r = event(t)
self.assertFalse(r)
......@@ -157,7 +157,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time
t = time + 5
self.failUnless(t < critical_time)
......@@ -170,7 +170,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("ping")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < critical_time < t
t = critical_time + 5
self.failUnless(t > critical_time)
......@@ -197,7 +197,7 @@ class EventTests(NeoTestBase):
critical_time = event.getCriticalTime()
self.assertEqual(critical_time, time+3)
# call with t < time < critical_time
# call with t < time < critical_time
t = time - 10
r = event(t)
self.assertFalse(r)
......@@ -208,7 +208,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time
t = time + 1
self.failUnless(t < critical_time)
......@@ -221,7 +221,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < critical_time < t
t = critical_time + 5
self.failUnless(t > critical_time)
......@@ -234,7 +234,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1)
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
......@@ -47,36 +47,36 @@ class HandlerTests(NeoTestBase):
# all is ok
self.setFakeMethod(lambda c, p: None)
self.handler.dispatch(conn, packet)
# raise UnexpectedPacketError
conn.mockCalledMethods = {}
# raise UnexpectedPacketError
conn.mockCalledMethods = {}
def fake(c, p): raise UnexpectedPacketError('fake packet')
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise PacketMalformedError
conn.mockCalledMethods = {}
conn.mockCalledMethods = {}
def fake(c, p): raise PacketMalformedError('message')
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise BrokenNodeDisallowedError
conn.mockCalledMethods = {}
conn.mockCalledMethods = {}
def fake(c, p): raise BrokenNodeDisallowedError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise NotReadyError
conn.mockCalledMethods = {}
conn.mockCalledMethods = {}
def fake(c, p): raise NotReadyError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise ProtocolError
conn.mockCalledMethods = {}
conn.mockCalledMethods = {}
def fake(c, p): raise ProtocolError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
......
#
# 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
......@@ -47,7 +47,7 @@ class NodesTests(NeoTestBase):
self.assertEqual(node.getState(), NodeStates.UNKNOWN)
self.assertEqual(node.getAddress(), address)
self.assertEqual(node.getUUID(), uuid)
self.assertTrue(time() - 1 < node.getLastStateChange() < time())
self.assertTrue(time() - 1 < node.getLastStateChange() < time())
def testState(self):
""" Check if the last changed time is updated when state is changed """
......@@ -150,7 +150,7 @@ class NodeManagerTests(NeoTestBase):
def checkByServer(self, node):
node_found = self.manager.getByAddress(node.getAddress())
self.assertEqual(node_found, node)
def checkByUUID(self, node):
node_found = self.manager.getByUUID(node.getUUID())
self.assertEqual(node_found, node)
......@@ -273,7 +273,7 @@ class NodeManagerTests(NeoTestBase):
self.checkNodes([self.master, self.admin, new_storage])
self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN)
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
......@@ -122,8 +122,8 @@ class PartitionTableTests(NeoTestBase):
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0)
def test_04_removeCell(self):
num_partitions = 5
num_replicas = 2
......@@ -162,7 +162,7 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(pt.count_dict[sn1], 0)
for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0)
def test_05_getCellList(self):
num_partitions = 5
num_replicas = 2
......@@ -281,7 +281,7 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getNodeList()), 2)
nodes = pt.getNodeList()
self.failUnless(sn1 in nodes)
self.failUnless(sn2 in nodes)
self.failUnless(sn2 in nodes)
self.failUnless(sn3 not in nodes)
self.failUnless(sn4 not in nodes)
......@@ -297,8 +297,8 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions):
pt.setCell(x, sn1, CellStates.UP_TO_DATE)
self.assertEqual(pt.num_filled_rows, num_partitions)
pt.setCell(x, sn1, CellStates.UP_TO_DATE)
self.assertEqual(pt.num_filled_rows, num_partitions)
self.assertTrue(pt.filled())
def test_09_hasOffset(self):
......
......@@ -429,7 +429,7 @@ class ProtocolTests(NeoTestBase):
oid3 = self.getNextTID()
oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = Packets.AnswerTransactionInformation(tid, "moi",
p = Packets.AnswerTransactionInformation(tid, "moi",
"transaction", "exti", oid_list)
ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid)
......
#
# Copyright (C) 2006-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
......@@ -19,7 +19,7 @@ import unittest
from neo.tests import NeoTestBase
from neo import util
class UtilTests(NeoTestBase):
def test_getNextTID(self):
......
This diff is collapsed.
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