Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logging.basicConfig(format = u'[%(asctime)s %(filename)s:%(lineno)d %(levelname)s] %(message)s', level = logging.DEBUG)
_bchr = functools.partial(struct.pack, 'B')
class TEST_TYPE:
DEFAULT = 0
COMPACTION_1 = 1
COMPACTION_2 = 2
RAND_1 = 3
JOURNAL_1 = 4
AUTO_TICK_1 = 5
WAIT_BIND = 6
LARGE_COMMAND = 7
class TestObj(SyncObj):
def __init__(self, selfNodeAddr, otherNodeAddrs,
testType = TEST_TYPE.DEFAULT,
compactionMinEntries = 0,
dumpFile = None,
journalFile = None,
password = None,
dynamicMembershipChange = False,
useFork = True,
testBindAddr = False,
consumers = None,
onStateChanged = None,
leaderFallbackTimeout = None):
cfg = SyncObjConf(autoTick=False, appendEntriesUseBatch=False)
cfg.appendEntriesPeriod = 0.1
from __future__ import print_function
import sys
import time
import random
from collections import defaultdict
sys.path.append("../")
from pysyncobj import SyncObj, replicated, SyncObjConf, FAIL_REASON
class TestObj(SyncObj):
def __init__(self, selfNodeAddr, otherNodeAddrs):
super(TestObj, self).__init__(selfNodeAddr, otherNodeAddrs)
self.__appliedCommands = 0
@replicated
def testMethod(self, value):
self.__appliedCommands += 1
def getNumCommandsApplied(self):
return self.__appliedCommands
_g_sent = 0
_g_success = 0
_g_error = 0
_g_errors = defaultdict(int)
@replicated(ver=1)
def someMethod(self):
pass
@replicated
def methodTwo(self):
pass
class ZeroDeployConsumerBravo(SyncObjConsumer):
@replicated
def alphaMethod(self):
pass
@replicated(ver=3)
def methodTwo(self):
pass
class ZeroDeployTestObj(SyncObj):
def __init__(self, selfAddr, otherAddrs, consumers):
cfg = SyncObjConf(autoTick=False)
super(ZeroDeployTestObj, self).__init__(selfAddr, otherAddrs, cfg, consumers=consumers)
@replicated
def someMethod(self):
pass
@replicated
def otherMethod(self):
pass
@replicated(ver=1)
def thirdMethod(self):
pass
@patch.object(SyncObj, 'doTick', Mock(side_effect=Exception))
def test_run(self):
self.assertRaises(SleepException, self.rc.run)
self.rc.shutdown()
createJournal, HAS_CRYPTO, replicated_sync, Utility, SyncObjException
logging.basicConfig(format = '[%(asctime)s %(filename)s:%(lineno)d %(levelname)s] %(message)s', level = logging.DEBUG)
_bchr = functools.partial(struct.pack, 'B')
class TEST_TYPE:
DEFAULT = 0
COMPACTION_1 = 1
COMPACTION_2 = 2
RAND_1 = 3
JOURNAL_1 = 4
AUTO_TICK_1 = 5
WAIT_BIND = 6
class TestObj(SyncObj):
def __init__(self, selfNodeAddr, otherNodeAddrs,
testType = TEST_TYPE.DEFAULT,
compactionMinEntries = 0,
dumpFile = None,
journalFile = None,
password = None,
dynamicMembershipChange = False,
useFork = True,
testBindAddr = False):
cfg = SyncObjConf(autoTick=False, appendEntriesUseBatch=False)
cfg.appendEntriesPeriod = 0.1
cfg.raftMinTimeout = 0.5
cfg.raftMaxTimeout = 1.0
cfg.dynamicMembershipChange = dynamicMembershipChange
#!/usr/bin/env python
from __future__ import print_function
import sys
try:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
except ImportError:
from http.server import BaseHTTPRequestHandler, HTTPServer
sys.path.append("../")
from pysyncobj import SyncObj, SyncObjConf, replicated
class KVStorage(SyncObj):
def __init__(self, selfAddress, partnerAddrs, dumpFile):
conf = SyncObjConf(
fullDumpFile=dumpFile,
)
super(KVStorage, self).__init__(selfAddress, partnerAddrs, conf)
self.__data = {}
@replicated
def set(self, key, value):
self.__data[key] = value
@replicated
def pop(self, key):
self.__data.pop(key, None)
def get(self, key):
class FrozenDict(collections.Mapping):
def __init__(self, data):
self._data = data
def __getitem__(self, key):
return self._data[key]
def __len__(self):
return len(self._data)
def __iter__(self):
return iter(self._data)
class KVStorage(SyncObj):
__owners = {}
__resources = {}
def __init__(self, self_address, partner_addrs):
super(KVStorage, self).__init__(self_address, partner_addrs)
@replicated
def set_block_owner(self, block_id, owner):
self.__owners[block_id] = owner
def find_block_owner(self, block_id):
return self.__owners.get(block_id, None)
@property
def block_owners(self):
return FrozenDict(self.__owners)
#!/usr/bin/env python
from __future__ import print_function
import sys
import time
from functools import partial
sys.path.append("../")
from pysyncobj import SyncObj, replicated
class TestObj(SyncObj):
def __init__(self, selfNodeAddr, otherNodeAddrs):
super(TestObj, self).__init__(selfNodeAddr, otherNodeAddrs)
self.__counter = 0
@replicated
def incCounter(self):
self.__counter += 1
return self.__counter
@replicated
def addValue(self, value, cn):
self.__counter += value
return self.__counter, cn
def getCounter(self):
#!/usr/bin/env python
from __future__ import print_function
import sys
sys.path.append("../")
from pysyncobj import SyncObj, SyncObjConf, replicated
class KVStorage(SyncObj):
def __init__(self, selfAddress, partnerAddrs):
cfg = SyncObjConf(dynamicMembershipChange = True)
super(KVStorage, self).__init__(selfAddress, partnerAddrs, cfg)
self.__data = {}
@replicated
def set(self, key, value):
self.__data[key] = value
@replicated
def pop(self, key):
self.__data.pop(key, None)
def get(self, key):
return self.__data.get(key, None)
return self.__result
# selfAddress is send as a first message, we will abuse that fact
def _getSelfNodeAddr(self):
return self.__message
def _onMessageReceived(self, _, message):
self.__result = message
self.__node._Node__conn.disconnect()
self.__node._Node__lastConnectAttemptTime = 0
def __getattr__(self, name):
return getattr(self.syncObj, name)
class DynMemberSyncObj(SyncObj):
def __init__(self, selfAddress, partnerAddrs, conf):
autoTick = conf.autoTick
conf.autoTick = False
super(DynMemberSyncObj, self).__init__(None, partnerAddrs, conf)
utility = SyncObjUtility(self)
add_self = False
nodes = partnerAddrs[:]
nodes.extend([n.getAddress() for n in self._SyncObj__nodes if n.getAddress() not in partnerAddrs])
for node in nodes:
utility.setPartnerAddress(node)
response = utility.sendMessage(['members'])
if response:
partnerAddrs = [member['addr'] for member in response if member['addr'] != selfAddress]