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):
......
#
# 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 @@ from neo.client.mq import MQ
from neo.util import u64, parseMasterList
class ConnectionClosed(Exception):
class ConnectionClosed(Exception):
pass
......@@ -94,7 +94,7 @@ class ConnectionPool(object):
conn.unlock()
try:
app._waitMessage(conn, msg_id,
app._waitMessage(conn, msg_id,
handler=app.storage_bootstrap_handler)
except ConnectionClosed:
logging.error('Connection to storage node %s failed', node)
......@@ -213,7 +213,7 @@ class ThreadContext(object):
return thread_data[name]
except KeyError:
raise AttributeError, name
def __setattr__(self, name, value):
thread_data = self.__getThreadData()
thread_data[name] = value
......@@ -408,7 +408,7 @@ class Application(object):
self.trying_master_node = master_list[0]
index += 1
# Connect to master
conn = MTClientConnection(self.em, self.notifications_handler,
conn = MTClientConnection(self.em, self.notifications_handler,
addr=self.trying_master_node.getAddress(),
connector_handler=self.connector_handler,
dispatcher=self.dispatcher)
......@@ -420,12 +420,12 @@ class Application(object):
logging.error('Connection to master node %s failed',
self.trying_master_node)
continue
msg_id = conn.ask(self.local_var.queue,
msg_id = conn.ask(self.local_var.queue,
Packets.AskPrimary())
finally:
conn.unlock()
try:
self._waitMessage(conn, msg_id,
self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler)
except ConnectionClosed:
continue
......@@ -449,7 +449,7 @@ class Application(object):
finally:
conn.unlock()
try:
self._waitMessage(conn, msg_id,
self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler)
except ConnectionClosed:
self.primary_master_node = None
......@@ -473,7 +473,7 @@ class Application(object):
Packets.AskNodeInformation())
finally:
conn.unlock()
self._waitMessage(conn, msg_id,
self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler)
conn.lock()
try:
......@@ -481,14 +481,14 @@ class Application(object):
Packets.AskPartitionTable([]))
finally:
conn.unlock()
self._waitMessage(conn, msg_id,
self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler)
ready = self.uuid is not None and self.pt is not None \
and self.pt.operational()
logging.info("connected to primary master node %s" %
logging.info("connected to primary master node %s" %
self.primary_master_node)
return conn
def registerDB(self, db, limit):
self._db = db
......@@ -580,9 +580,9 @@ class Application(object):
break
if self.local_var.asked_object == 0:
# We didn't got any object from all storage node because of
# We didn't got any object from all storage node because of
# connection error
logging.warning('oid %s not found because of connection failure',
logging.warning('oid %s not found because of connection failure',
dump(oid))
raise NEOStorageNotFoundError()
......@@ -658,7 +658,7 @@ class Application(object):
self._askPrimary(Packets.AskBeginTransaction(tid))
if self.local_var.tid is None:
raise NEOStorageError('tpc_begin failed')
self.local_var.txn = transaction
self.local_var.txn = transaction
def store(self, oid, serial, data, version, transaction):
......@@ -680,7 +680,7 @@ class Application(object):
self.local_var.object_stored_counter = 0
for cell in cell_list:
conn = self.cp.getConnForCell(cell)
if conn is None:
if conn is None:
continue
self.local_var.object_stored = 0
......@@ -696,20 +696,20 @@ class Application(object):
if self.local_var.data_dict.has_key(oid):
# One storage already accept the object, is it normal ??
# remove from dict and raise ConflictError, don't care of
# previous node which already store data as it would be
# resent again if conflict is resolved or txn will be
# previous node which already store data as it would be
# resent again if conflict is resolved or txn will be
# aborted
del self.local_var.data_dict[oid]
self.local_var.conflict_serial = self.local_var.object_stored[1]
raise NEOStorageConflictError
# increase counter so that we know if a node has stored the object
# increase counter so that we know if a node has stored the object
# or not
self.local_var.object_stored_counter += 1
if self.local_var.object_stored_counter == 0:
# no storage nodes were available
raise NEOStorageError('tpc_store failed')
# Store object in tmp cache
self.local_var.data_dict[oid] = data
......@@ -729,14 +729,14 @@ class Application(object):
cell_list = self._getCellListForTID(self.local_var.tid, writable=True)
self.local_var.voted_counter = 0
for cell in cell_list:
logging.debug("voting object %s %s" %(cell.getAddress(),
logging.debug("voting object %s %s" %(cell.getAddress(),
cell.getState()))
conn = self.cp.getConnForCell(cell)
if conn is None:
continue
self.local_var.txn_voted = False
p = Packets.AskStoreTransaction(self.local_var.tid,
p = Packets.AskStoreTransaction(self.local_var.tid,
user, desc, ext, oid_list)
try:
self._askStorage(conn, p)
......@@ -761,7 +761,7 @@ class Application(object):
for oid in self.local_var.data_dict.iterkeys():
cell_set |= set(self._getCellListForOID(oid, writable=True))
# select nodes where transaction was stored
cell_set |= set(self._getCellListForTID(self.local_var.tid,
cell_set |= set(self._getCellListForTID(self.local_var.tid,
writable=True))
# cancel transaction one all those nodes
......@@ -869,12 +869,12 @@ class Application(object):
self.store(oid, transaction_id, data, None, txn)
except NEOStorageConflictError, serial:
if serial <= self.local_var.tid:
new_data = wrapper.tryToResolveConflict(oid,
new_data = wrapper.tryToResolveConflict(oid,
self.local_var.tid, serial, data)
if new_data is not None:
self.store(oid, self.local_var.tid, new_data, None, txn)
continue
raise ConflictError(oid = oid, serials = (self.local_var.tid,
raise ConflictError(oid = oid, serials = (self.local_var.tid,
serial),
data = data)
return self.local_var.tid, oid_list
......@@ -897,7 +897,7 @@ class Application(object):
continue
try:
conn.ask(self.local_var.queue, Packets.AskTIDs(first, last,
conn.ask(self.local_var.queue, Packets.AskTIDs(first, last,
protocol.INVALID_PARTITION))
finally:
conn.unlock()
......@@ -929,7 +929,7 @@ class Application(object):
if conn is not None:
self.local_var.txn_info = 0
try:
self._askStorage(conn,
self._askStorage(conn,
Packets.AskTransactionInformation(tid))
except ConnectionClosed:
continue
......@@ -951,7 +951,7 @@ class Application(object):
# Check we return at least one element, otherwise call
# again but extend offset
if len(undo_info) == 0 and not block:
undo_info = self.undoLog(first=first, last=last*5, filter=filter,
undo_info = self.undoLog(first=first, last=last*5, filter=filter,
block=1)
return undo_info
......@@ -1006,7 +1006,7 @@ class Application(object):
# ask transaction information
self.local_var.txn_info = None
try:
self._askStorage(conn,
self._askStorage(conn,
Packets.AskTransactionInformation(serial))
except ConnectionClosed:
continue
......
#
# 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()
......
#
# 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
......@@ -82,9 +82,9 @@ node_state_prefix_dict = {
}
# used for logging
cell_state_prefix_dict = {
CellStates.UP_TO_DATE: 'U',
CellStates.OUT_OF_DATE: 'O',
cell_state_prefix_dict = {
CellStates.UP_TO_DATE: 'U',
CellStates.OUT_OF_DATE: 'O',
CellStates.FEEDING: 'F',
CellStates.DISCARDED: 'D',
}
......@@ -97,14 +97,14 @@ INVALID_PTID = '\0' * 8
INVALID_SERIAL = INVALID_TID
INVALID_PARTITION = 0xffffffff
UUID_NAMESPACES = {
UUID_NAMESPACES = {
NodeTypes.STORAGE: 'S',
NodeTypes.MASTER: 'M',
NodeTypes.CLIENT: 'C',
NodeTypes.ADMIN: 'A',
}
class ProtocolError(Exception):
class ProtocolError(Exception):
""" Base class for protocol errors, close the connection """
pass
......@@ -112,17 +112,17 @@ class PacketMalformedError(ProtocolError):
""" Close the connection and set the node as broken"""
pass
class UnexpectedPacketError(ProtocolError):
class UnexpectedPacketError(ProtocolError):
""" Close the connection and set the node as broken"""
pass
class NotReadyError(ProtocolError):
class NotReadyError(ProtocolError):
""" Just close the connection """
pass
class BrokenNodeDisallowedError(ProtocolError):
class BrokenNodeDisallowedError(ProtocolError):
""" Just close the connection """
pass
pass
# packet parser
......@@ -147,7 +147,7 @@ def _decodeNodeType(original_node_type):
def _decodeErrorCode(original_error_code):
error_code = ErrorCodes.get(original_error_code)
if error_code is None:
raise PacketMalformedError('invalid error code %d' %
raise PacketMalformedError('invalid error code %d' %
original_error_code)
return error_code
......@@ -203,10 +203,10 @@ def _readString(buf, name, offset=0):
class Packet(object):
"""
Base class for any packet definition.
"""
Base class for any packet definition.
Each subclass should override _encode() and _decode() and return a string or
a tuple respectively.
a tuple respectively.
"""
_body = None
......@@ -222,7 +222,7 @@ class Packet(object):
body = ''
self._body = body
self._args = args
def decode(self):
assert self._body is not None
try:
......@@ -284,20 +284,20 @@ class Packet(object):
class Ping(Packet):
"""
"""
Check if a peer is still alive. Any -> Any.
"""
pass
class Pong(Packet):
"""
"""
Notify being alive. Any -> Any.
"""
pass
class RequestIdentification(Packet):
"""
"""
Request a node identification. This must be the first packet for any
connection. Any -> Any.
"""
......@@ -320,7 +320,7 @@ class RequestIdentification(Packet):
class AcceptIdentification(Packet):
"""
Accept a node identification. This should be a reply to Request Node
Accept a node identification. This should be a reply to Request Node
Identification. Any -> Any.
"""
def _encode(self, node_type, uuid, address,
......@@ -338,19 +338,19 @@ class AcceptIdentification(Packet):
node_type = _decodeNodeType(node_type)
uuid = _decodeUUID(uuid)
your_uuid == _decodeUUID(uuid)
return (node_type, uuid, address, num_partitions, num_replicas,
return (node_type, uuid, address, num_partitions, num_replicas,
your_uuid)
class AskPrimary(Packet):
"""
Ask a current primary master node. This must be the second message when
"""
Ask a current primary master node. This must be the second message when
connecting to a master node. Any -> M.
"""
pass
class AnswerPrimary(Packet):
"""
Reply to Ask Primary Master. This message includes a list of known master
"""
Reply to Ask Primary Master. This message includes a list of known master
nodes to make sure that a peer has the same information. M -> Any.
"""
def _encode(self, primary_uuid, known_master_list):
......@@ -374,7 +374,7 @@ class AnswerPrimary(Packet):
return (primary_uuid, known_master_list)
class AnnouncePrimary(Packet):
"""
"""
Announce a primary master node election. PM -> SM.
"""
pass
......@@ -386,19 +386,19 @@ class ReelectPrimary(Packet):
pass
class AskLastIDs(Packet):
"""
"""
Ask the last OID, the last TID and the last Partition Table ID that
a storage node stores. Used to recover information. PM -> S, S -> PM.
"""
pass
class AnswerLastIDs(Packet):
"""
"""
Reply to Ask Last IDs. S -> PM, PM -> S.
"""
def _encode(self, loid, ltid, lptid):
# in this case, loid is a valid OID but considered as invalid. This is
# not an issue because the OID 0 is hard coded and will never be
# in this case, loid is a valid OID but considered as invalid. This is
# not an issue because the OID 0 is hard coded and will never be
# generated
if loid is None:
loid = INVALID_OID
......@@ -412,7 +412,7 @@ class AnswerLastIDs(Packet):
return (loid, ltid, lptid)
class AskPartitionTable(Packet):
"""
"""
Ask rows in a partition table that a storage node stores. Used to recover
information. PM -> S.
"""
......@@ -431,7 +431,7 @@ class AskPartitionTable(Packet):
return (offset_list,)
class AnswerPartitionTable(Packet):
"""
"""
Answer rows in a partition table. S -> PM.
"""
def _encode(self, ptid, row_list):
......@@ -464,7 +464,7 @@ class AnswerPartitionTable(Packet):
return (ptid, row_list)
class SendPartitionTable(Packet):
"""
"""
Send rows in a partition table to update other nodes. PM -> S, C.
"""
def _encode(self, ptid, row_list):
......@@ -497,8 +497,8 @@ class SendPartitionTable(Packet):
return (ptid, row_list)
class NotifyPartitionChanges(Packet):
"""
Notify a subset of a partition table. This is used to notify changes.
"""
Notify a subset of a partition table. This is used to notify changes.
PM -> S, C.
"""
def _encode(self, ptid, cell_list):
......@@ -522,14 +522,14 @@ class NotifyPartitionChanges(Packet):
class StartOperation(Packet):
"""
Tell a storage nodes to start an operation. Until a storage node receives
Tell a storage nodes to start an operation. Until a storage node receives
this message, it must not serve client nodes. PM -> S.
"""
pass
class StopOperation(Packet):
"""
Tell a storage node to stop an operation. Once a storage node receives
Tell a storage node to stop an operation. Once a storage node receives
this message, it must not serve client nodes. PM -> S.
"""
pass
......@@ -559,7 +559,7 @@ class AnswerUnfinishedTransactions(Packet):
class AskObjectPresent(Packet):
"""
Ask if an object is present. If not present, OID_NOT_FOUND should be
Ask if an object is present. If not present, OID_NOT_FOUND should be
returned. PM -> S.
"""
def _decode(self, body):
......@@ -693,7 +693,7 @@ class UnlockInformation(Packet):
return _encodeTID(tid)
def _decode(self, body):
(tid, ) = unpack('8s', body)
(tid, ) = unpack('8s', body)
return (_decodeTID(tid), )
class AskNewOIDs(Packet):
......@@ -885,7 +885,7 @@ class AnswerTransactionInformation(Packet):
Answer information (user, description) about a transaction. S -> Any.
"""
def _encode(self, tid, user, desc, ext, oid_list):
body = [pack('!8sHHHL', tid, len(user), len(desc), len(ext),
body = [pack('!8sHHHL', tid, len(user), len(desc), len(ext),
len(oid_list))]
body.append(user)
body.append(desc)
......@@ -1112,8 +1112,8 @@ class AnswerNewNodes(Packet):
return (uuid_list, )
class NotifyNodeInformation(Packet):
"""
Notify information about one or more nodes. Any -> PM, PM -> Any.
"""
Notify information about one or more nodes. Any -> PM, PM -> Any.
"""
def _encode(self, node_list):
body = [pack('!L', len(node_list))]
......@@ -1122,7 +1122,7 @@ class NotifyNodeInformation(Packet):
address = _encodeAddress(address)
body.append(pack('!H6s16sH', node_type, address, uuid, state))
return ''.join(body)
def _decode(self, body):
(n,) = unpack('!L', body[:4])
node_list = []
......@@ -1200,8 +1200,8 @@ class NotifyLastOID(Packet):
class Error(Packet):
"""
Error is a special type of message, because this can be sent against
any other message, even if such a message does not expect a reply
Error is a special type of message, because this can be sent against
any other message, even if such a message does not expect a reply
usually. Any -> Any.
"""
def _encode(self, code, message):
......@@ -1224,7 +1224,7 @@ def register(code, cls):
class PacketRegistry(dict):
"""
"""
Packet registry that check packet code unicity and provide an index
"""
......@@ -1272,7 +1272,7 @@ class PacketRegistry(dict):
StartOperation = register(0x000B, StartOperation)
StopOperation = register(0x000C, StopOperation)
AskUnfinishedTransactions = register(0x000D, AskUnfinishedTransactions)
AnswerUnfinishedTransactions = register(0x800d,
AnswerUnfinishedTransactions = register(0x800d,
AnswerUnfinishedTransactions)
AskObjectPresent = register(0x000f, AskObjectPresent)
AnswerObjectPresent = register(0x800f, AnswerObjectPresent)
......@@ -1298,7 +1298,7 @@ class PacketRegistry(dict):
AskTIDs = register(0x001C, AskTIDs)
AnswerTIDs = register(0x801D, AnswerTIDs)
AskTransactionInformation = register(0x001E, AskTransactionInformation)
AnswerTransactionInformation = register(0x801E,
AnswerTransactionInformation = register(0x801E,
AnswerTransactionInformation)
AskObjectHistory = register(0x001F, AskObjectHistory)
AnswerObjectHistory = register(0x801F, AnswerObjectHistory)
......
#
# 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
#
# 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
......@@ -135,10 +135,10 @@ class ClientApplicationTests(NeoTestBase):
txn = app.local_var.txn
tid = app.local_var.tid
packet = Packets.NotifyTransactionFinished(tid)
app.master_conn = Mock({
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10010),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.tpc_finish(txn)
......@@ -154,7 +154,7 @@ class ClientApplicationTests(NeoTestBase):
app = self.getApp()
# Test sanity check
self.assertTrue(getattr(app, 'local_var', None) is not None)
# Test that queue is created
# Test that queue is created
self.assertTrue(getattr(app.local_var, 'queue', None) is not None)
def test_registerDB(self):
......@@ -197,7 +197,7 @@ class ClientApplicationTests(NeoTestBase):
app.getSerial(oid)
self.assertEquals(app.getSerial(oid), tid)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellListForOID')), 0)
def test_load(self):
app = self.getApp()
mq = app.mq_cache
......@@ -211,7 +211,7 @@ class ClientApplicationTests(NeoTestBase):
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({'getUUID': '\x10' * 16,
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.local_var.queue = Mock({'get_nowait' : (conn, None)})
app.pt = Mock({ 'getCellListForOID': (cell, ), })
......@@ -225,9 +225,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn})
......@@ -236,9 +236,9 @@ class ClientApplicationTests(NeoTestBase):
self.checkAskObject(conn)
# object found on storage nodes and put in cache
packet = Packets.AnswerObject(*an_object[1:])
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = an_object
......@@ -246,15 +246,15 @@ class ClientApplicationTests(NeoTestBase):
self.assertEquals(result, ('OBJ', tid1))
self.checkAskObject(conn)
self.assertTrue(oid in mq)
# object is now cached, try to reload it
conn = Mock({
# object is now cached, try to reload it
conn = Mock({
'getAddress': ('127.0.0.1', 0),
})
app.cp = Mock({ 'getConnForCell' : conn})
result = app.load(oid)
self.assertEquals(result, ('OBJ', tid1))
self.checkNoPacketSent(conn)
def test_loadSerial(self):
app = self.getApp()
mq = app.mq_cache
......@@ -265,9 +265,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn})
......@@ -276,14 +276,14 @@ class ClientApplicationTests(NeoTestBase):
self.checkAskObject(conn)
# object should not have been cached
self.assertFalse(oid in mq)
# now a cached version ewxists but should not be hit
# now a cached version ewxists but should not be hit
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = Packets.AnswerObject(*another_object[1:])
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = another_object
......@@ -302,9 +302,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn})
......@@ -314,9 +314,9 @@ class ClientApplicationTests(NeoTestBase):
# no previous versions -> return None
an_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum(''), '')
packet = Packets.AnswerObject(*an_object[1:])
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = an_object
......@@ -324,14 +324,14 @@ class ClientApplicationTests(NeoTestBase):
self.assertEquals(result, None)
# object should not have been cached
self.assertFalse(oid in mq)
# as for loadSerial, the object is cached but should be loaded from db
# as for loadSerial, the object is cached but should be loaded from db
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid1, tid2, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = Packets.AnswerObject(*another_object[1:])
conn = Mock({
conn = Mock({
'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = another_object
......@@ -344,7 +344,7 @@ class ClientApplicationTests(NeoTestBase):
app = self.getApp()
tid = self.makeTID()
txn = Mock()
# first, tid is supplied
# first, tid is supplied
self.assertNotEquals(getattr(app, 'tid', None), tid)
self.assertNotEquals(getattr(app, 'txn', None), txn)
packet = Packets.AnswerBeginTransaction(tid=tid)
......@@ -392,11 +392,11 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn
app.local_var.tid = tid
app.pt = Mock({ 'getCellListForOID': (), })
app.num_partitions = 2
app.num_partitions = 2
self.assertRaises(NEOStorageError, app.store, oid, tid, '', None, txn)
calls = app.pt.mockGetNamedCalls('getCellListForOID')
self.assertEquals(len(calls), 1)
self.assertEquals(calls[0].getParam(0), oid) # oid=11
self.assertEquals(calls[0].getParam(0), oid) # oid=11
def test_store2(self):
app = self.getApp()
......@@ -407,9 +407,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn
app.local_var.tid = tid
packet = Packets.AnswerStoreObject(conflicting=1, oid=oid, serial=tid)
conn = Mock({
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
'fakeReceived': packet,
})
cell = Mock({
'getAddress': 'FakeServer',
......@@ -436,9 +436,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn
app.local_var.tid = tid
packet = Packets.AnswerStoreObject(conflicting=0, oid=oid, serial=tid)
conn = Mock({
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
'fakeReceived': packet,
})
app.cp = Mock({ 'getConnForCell': ReturnValues(None, conn, ) })
cell = Mock({
......@@ -475,9 +475,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.tid = tid
# wrong answer -> failure
packet = Packets.AnswerTIDs(())
conn = Mock({
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
'fakeReceived': packet,
'getAddress': ('127.0.0.1', 0),
})
cell = Mock({
......@@ -502,9 +502,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.tid = tid
# response -> OK
packet = Packets.AnswerStoreTransaction(tid=tid)
conn = Mock({
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
'fakeReceived': packet,
})
cell = Mock({
'getAddress': 'FakeServer',
......@@ -552,9 +552,9 @@ class ClientApplicationTests(NeoTestBase):
cell1 = Mock({ 'getNode': 'NODE1', '__hash__': 1 })
cell2 = Mock({ 'getNode': 'NODE2', '__hash__': 2 })
conn1, conn2 = Mock({ 'getNextId': 1, }), Mock({ 'getNextId': 2, })
app.pt = Mock({
'getCellListForOID': ReturnValues((cell1, ), (cell1, )),
'getCellListForTID': (cell1, cell2),
app.pt = Mock({
'getCellListForOID': ReturnValues((cell1, ), (cell1, )),
'getCellListForTID': (cell1, cell2),
})
app.cp = Mock({ 'getConnForCell': ReturnValues(conn1, conn2), })
# fake data
......@@ -597,14 +597,14 @@ class ClientApplicationTests(NeoTestBase):
# test callable passed to tpc_finish
self.f_called = False
self.f_called_with_tid = None
def hook(tid):
def hook(tid):
self.f_called = True
self.f_called_with_tid = tid
packet = Packets.AnswerBeginTransaction(INVALID_TID)
app.master_conn = Mock({
packet = Packets.AnswerBeginTransaction(INVALID_TID)
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10000),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.dispatcher = Mock({})
app.local_var.txn_finished = False
......@@ -622,14 +622,14 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn, app.local_var.tid = txn, tid
self.f_called = False
self.f_called_with_tid = None
def hook(tid):
def hook(tid):
self.f_called = True
self.f_called_with_tid = tid
packet = Packets.NotifyTransactionFinished(tid)
app.master_conn = Mock({
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10010),
'fakeReceived': packet,
'fakeReceived': packet,
})
app.dispatcher = Mock({})
app.local_var.txn_finished = True
......@@ -706,13 +706,13 @@ class ClientApplicationTests(NeoTestBase):
u4p3 = Packets.AnswerStoreObject(conflicting=0, oid=oid2, serial=tid2)
# test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3)
conn = Mock({
'getNextId': 1,
conn = Mock({
'getNextId': 1,
'fakeReceived': ReturnValues(*packets),
'getAddress': ('127.0.0.1', 10010),
})
cell = Mock({ 'getAddress': 'FakeServer', 'getState': 'FakeState', })
app.pt = Mock({
app.pt = Mock({
'getCellListForTID': (cell, ),
'getCellListForOID': (cell, ),
})
......@@ -800,7 +800,7 @@ class ClientApplicationTests(NeoTestBase):
# the connection to the first will fail
# the second will have changed
# the third will not be ready
# after the third, the partition table will be operational
# after the third, the partition table will be operational
# (as if it was connected to the primary master node)
from neo.tests import DoNothingConnector
# will raise IndexError at the third iteration
......@@ -828,7 +828,7 @@ class ClientApplicationTests(NeoTestBase):
Application._waitMessage = _waitMessage6
# third iteration : node not ready
def _waitMessage4(app, conn=None, msg_id=None, handler=None):
app.setNodeNotReady()
app.setNodeNotReady()
app.trying_master_node = None
Application._waitMessage = _waitMessage5
# second iteration : master node changed
......
#
# 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)
......
#
# 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
......@@ -21,7 +21,7 @@ from neo.tests import NeoTestBase
from neo.protocol import Packet, Packets, NodeTypes, NodeStates, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.app import Application
from neo.exception import ElectionFailure
from neo.exception import ElectionFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -61,7 +61,7 @@ class MasterClientElectionTests(NeoTestBase):
self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
def tearDown(self):
# restore patched methods
ClientConnection._addPacket = self._addPacket
......@@ -84,7 +84,7 @@ class MasterClientElectionTests(NeoTestBase):
self.election.connectionStarted(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
def test_02_connectionCompleted(self):
uuid = self.identifyToMasterNode(port=self.master_port)
......@@ -92,7 +92,7 @@ class MasterClientElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)})
self.election.connectionCompleted(conn)
self.checkAskPrimary(conn)
def test_03_connectionFailed(self):
uuid = self.identifyToMasterNode(port=self.master_port)
......@@ -122,7 +122,7 @@ class MasterClientElectionTests(NeoTestBase):
"getConnector": Mock(),
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterList()), 2)
election.askPrimary(conn, packet)
election.askPrimary(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkAnswerPrimary(conn)
......@@ -234,10 +234,10 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertNotEqual(self.app.primary_master_node, None)
self.assertEqual(self.app.primary, False)
# Now tell it's another node which is primary, it must raise
# Now tell it's another node which is primary, it must raise
self.assertRaises(ElectionFailure, self.election.answerPrimary, conn, p, uuid, [])
class MasterServerElectionTests(NeoTestBase):
......@@ -265,7 +265,7 @@ class MasterServerElectionTests(NeoTestBase):
self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
def tearDown(self):
NeoTestBase.tearDown(self)
# restore environnement
......@@ -279,7 +279,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.getNewUUID()
return uuid
def checkCalledAskPrimary(self, conn, packet_number=0):
""" Check ask primary master has been send"""
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
......@@ -384,14 +384,14 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE,
uuid, "127.0.0.1", self.master_port,
self.app.pt.getPartitions(),
self.app.pt.getPartitions(),
self.app.pt.getReplicas(),
self.app.uuid
)
self.assertEqual(conn.getConnector(), None)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0)
def test_08_AcceptIdentification2(self):
# test with bad address, must be rejected
uuid = self.getNewUUID()
......@@ -407,7 +407,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE,
uuid, ("127.0.0.2", self.master_port),
self.app.pt.getPartitions(),
self.app.pt.getPartitions(),
self.app.pt.getReplicas(),
self.app.uuid)
self.assertEqual(conn.getConnector(), None)
......@@ -428,19 +428,19 @@ class MasterServerElectionTests(NeoTestBase):
self.election.AcceptIdentification(conn, p, NodeTypes.MASTER,
uuid, ("127.0.0.1", self.master_port),
self.app.pt.getPartitions(),
self.app.pt.getPartitions(),
self.app.pt.getReplicas(),
self.app.uuid)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), uuid)
self.assertEqual(conn.getUUID(), uuid)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),2)
self.checkCalledAskPrimary(conn.getConnector(), 1)
def test_10_RequestIdentification(self):
election = self.election
uuid = self.getNewUUID()
args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port),
args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port),
'INVALID_NAME')
packet = Packets.RequestIdentification(*args)
# test alien cluster
......@@ -517,7 +517,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid=new_uuid,
ip_address='127.0.0.1',
port=self.master_port+1,
name=self.app.name,)
name=self.app.name,)
def test_12_announcePrimary(self):
......@@ -538,7 +538,7 @@ class MasterServerElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None)
election.announcePrimary(conn, packet)
election.announcePrimary(conn, packet)
self.assertEqual(self.app.primary, False)
self.assertNotEqual(self.app.primary_master_node, None)
# set current as primary, and announce another, must raise
......@@ -548,8 +548,8 @@ class MasterServerElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)})
self.app.primary = True
self.assertEqual(self.app.primary, True)
self.assertRaises(ElectionFailure, election.announcePrimary, conn, packet)
self.assertRaises(ElectionFailure, election.announcePrimary, conn, packet)
def test_13_reelectPrimary(self):
election = self.election
......@@ -573,7 +573,7 @@ class MasterServerElectionTests(NeoTestBase):
self.checkIdenficationRequired(election.notifyNodeInformation, conn, packet, node_list)
# tell the master node about itself, must do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
"getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port - 1),
self.app.uuid, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
......@@ -583,7 +583,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(node, None)
# tell about a storage node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
"getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getStorageList()), 0)
......@@ -591,7 +591,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a client node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
"getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getList()), 0)
......@@ -599,7 +599,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getNodeList()), 0)
# tell about another master node
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
"getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port + 1),
self.getNewUUID(), NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
......@@ -618,7 +618,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1))
self.assertEqual(node.getState(), NodeStates.DOWN)
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
......@@ -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()
#
# 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
......@@ -56,7 +56,7 @@ class ConnectionTests(NeoTestBase):
# init with connector but no handler
registerConnectorHandler(DoNothingConnector)
connector = getConnectorHandler("DoNothingConnector")()
connector = getConnectorHandler("DoNothingConnector")()
self.assertNotEqual(connector, None)
em = Mock()
bc = BaseConnection(em, handler, connector=connector)
......@@ -99,7 +99,7 @@ class ConnectionTests(NeoTestBase):
call = em.mockGetNamedCalls("register")[0]
conn = call.getParam(0)
self.assertEquals(conn, bc)
def test_02_ListeningConnection(self):
# test init part
em = Mock()
......@@ -117,8 +117,8 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1)
# test readable
bc.readable()
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1)
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1)
# test with exception raise when getting new connection
em = Mock()
......@@ -136,8 +136,8 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1)
# test readable
bc.readable()
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0)
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0)
def test_03_Connection(self):
......@@ -194,7 +194,7 @@ class ConnectionTests(NeoTestBase):
connector=conn, addr=("127.0.0.7", 93413))
self.assertEqual(bc.write_buf, '')
self.assertNotEqual(bc.connector, None)
self.assertFalse(bc.pending())
self.assertFalse(bc.pending())
# connector and buffer
bc.write_buf += '1'
self.assertTrue(bc.pending())
......@@ -257,7 +257,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2)
def test_06_Connection_send(self):
# no data, nothing done
......@@ -273,7 +273,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("send")), 0)
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
# send all data
def send(self, data):
return len(data)
......@@ -330,7 +330,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.write_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
# send part of multiple packet
def send(self, data):
return len(data)/2
......@@ -458,10 +458,10 @@ class ConnectionTests(NeoTestBase):
# give some data to analyse
master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()),
......@@ -479,7 +479,7 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0)
self.assertEqual(data.getType(), p.getType())
self.assertEqual(data.getId(), p.getId())
self.assertEqual(data.decode(), p.decode())
self.assertEqual(data.decode(), p.decode())
self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '')
......@@ -491,9 +491,9 @@ class ConnectionTests(NeoTestBase):
bc._queue = Mock()
# packet 1
master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()),
......@@ -505,9 +505,9 @@ class ConnectionTests(NeoTestBase):
bc.read_buf += data
# packet 2
master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()),
......@@ -528,13 +528,13 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0)
self.assertEqual(data.getType(), p1.getType())
self.assertEqual(data.getId(), p1.getId())
self.assertEqual(data.decode(), p1.decode())
self.assertEqual(data.decode(), p1.decode())
# packet 2
call = bc._queue.mockGetNamedCalls("append")[1]
data = call.getParam(0)
self.assertEqual(data.getType(), p2.getType())
self.assertEqual(data.getId(), p2.getId())
self.assertEqual(data.decode(), p2.decode())
self.assertEqual(data.decode(), p2.decode())
self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(len(bc.read_buf), 0)
......@@ -558,11 +558,11 @@ class ConnectionTests(NeoTestBase):
bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413))
bc._queue = Mock()
master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()),
......@@ -583,7 +583,7 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0)
self.assertEqual(data.getType(), p.getType())
self.assertEqual(data.getId(), p.getId())
self.assertEqual(data.decode(), p.decode())
self.assertEqual(data.decode(), p.decode())
self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '')
......@@ -690,9 +690,9 @@ class ConnectionTests(NeoTestBase):
handler = Mock()
# patch receive method to return data
def receive(self):
master_list = ((("127.0.0.1", 2135), self.getNewUUID()),
master_list = ((("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2136), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()),
......@@ -796,7 +796,7 @@ class ConnectionTests(NeoTestBase):
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
self.assertRaises(ConnectorException, ClientConnection, em, handler,
self.assertRaises(ConnectorException, ClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
......@@ -970,7 +970,7 @@ class ConnectionTests(NeoTestBase):
bc.abort()
self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isServer())
def test_15_MTClientConnection(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection
......@@ -1039,8 +1039,8 @@ class ConnectionTests(NeoTestBase):
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
self.assertRaises(ConnectorException, MTClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413),
self.assertRaises(ConnectorException, MTClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413),
dispatcher=dispatcher)
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
......@@ -1098,6 +1098,6 @@ class ConnectionTests(NeoTestBase):
# XXX check locking ???
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
......
#
# 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):
......
#
# 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
......@@ -49,7 +49,7 @@ def bin(s):
ret.append(chr(int(s[:2], 16)))
s = s[2:]
return ''.join(ret)
def makeChecksum(s):
"""Return a 4-byte integer checksum against a string."""
......@@ -68,7 +68,7 @@ def getNextTID(ltid):
if lower == 0xffffffff:
# This should not happen usually.
from datetime import timedelta, datetime
d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
gmt.tm_hour, gmt.tm_min) \
+ timedelta(0, 60)
upper = ((((d.year - 1900) * 12 + d.month - 1) * 31 \
......@@ -98,7 +98,7 @@ class Enum(dict):
class MyEnum(Enum):
ITEM1 = Enum.Item(0)
ITEM2 = Enum.Item(1)
Enum items must be written in full upper case
Enum items must be written in full upper case
"""
class Item(int):
......@@ -134,7 +134,7 @@ class Enum(dict):
item._name = name
item._enum = self
self[int(item)] = item
def getByName(self, name):
return getattr(self, name)
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