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