def __init__(self, tmpdir, config=None):
     self.basedirpath = tmpdir
     self.name = 'Node1'
     self.f = 1
     self.replicas = dict()
     self.requests = []
     self.rank = None
     self.allNodeNames = [self.name, 'Node2', 'Node3', 'Node4']
     self.nodeReg = {
         name: HA("127.0.0.1", 0) for name in self.allNodeNames
     }
     self.totalNodes = len(self.allNodeNames)
     self.mode = Mode.starting
     self.config = config or getConfigOnce()
     self.replicas = {
         0: Replica(node=self, instId=0, isMaster=True, config=self.config),
         1: Replica(node=self, instId=1, isMaster=False, config=self.config),
         2: Replica(node=self, instId=2, isMaster=False, config=self.config),
     }
     self._found = False
     self.ledgerManager = LedgerManager(self, ownedByNode=True)
     ledger0 = FakeLedger(0, 10)
     ledger1 = FakeLedger(1, 5)
     self.ledgerManager.addLedger(0, ledger0)
     self.ledgerManager.addLedger(1, ledger1)
     self.quorums = Quorums(self.totalNodes)
     self.view_changer = ViewChanger(self)
     self.elector = PrimarySelector(self)
     self.metrics = NullMetricsCollector()
예제 #2
0
def fake_view_changer(request, tconf):
    node_count = 4
    node_stack = FakeSomething(name="fake stack",
                               connecteds={"Alpha", "Beta", "Gamma", "Delta"},
                               conns={"Alpha", "Beta", "Gamma", "Delta"})
    monitor = FakeSomething(isMasterDegraded=lambda: False,
                            areBackupsDegraded=lambda: [],
                            prettymetrics='')
    node = FakeSomething(name="SomeNode",
                         viewNo=request.param,
                         quorums=Quorums(
                             getValueFromModule(request,
                                                'nodeCount',
                                                default=node_count)),
                         nodestack=node_stack,
                         utc_epoch=lambda *args: get_utc_epoch(),
                         config=tconf,
                         monitor=monitor,
                         discard=lambda a, b, c: print(b),
                         primaries_disconnection_times=[None] *
                         getRequiredInstances(node_count),
                         master_primary_name='Alpha',
                         master_replica=FakeSomething(instId=0))
    view_changer = ViewChanger(node)
    return view_changer
예제 #3
0
def test_get_msgs_from_rxMsgs_queue(create_node_and_not_start, looper):
    node = create_node_and_not_start
    node.view_changer = ViewChanger(node)
    node.view_changer.view_no = 0
    """pre_view_change stage"""
    node.view_changer.startViewChange(1)
    assert node.view_changer.view_no == 0
    prepare = Prepare(
        0, 0, 1, get_utc_epoch(),
        'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be',
        'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG',
        '7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ')
    inst_change = InstanceChange(1, 25)
    m = node.nodeInBox.popleft()
    assert isinstance(m[0], ViewChangeStartMessage)
    node.nodestack.addRemote('someNode', genHa(),
                             b'1DYuELN<SHbv1?NJ=][4De%^Hge887B0I!s<YGdD',
                             'pubkey')
    node.nodestack.rxMsgs.append((json.dumps(prepare._asdict()), 'pubkey'))
    node.nodestack.rxMsgs.append((json.dumps(inst_change._asdict()), 'pubkey'))
    node.msgHasAcceptableViewNo = lambda *args, **kwargs: True
    """While processing ViewChangeStartMessage from nodeInBox queue, should be:
    - move msgs from rxMsgs queue to nodeInBox queue
    - process all 3PC msgs (for Prepare msg it should be moved to inBox queue of master_replica)
    - add ViewChangeContinue msg into master_replica's inBox queue
    - all not 3PC msgs will be stashed in strategy queue"""
    looper.run(node.process_one_node_message(m))
    m = node.master_replica.inBox.popleft()
    assert isinstance(m[0], Prepare)
    m = node.master_replica.inBox.popleft()
    assert isinstance(m, ViewChangeContinueMessage)
    m = node.view_changer.pre_vc_strategy.stashedNodeInBox.popleft()
    assert isinstance(m[0], InstanceChange)
예제 #4
0
def view_changer(tconf):
    node = FakeSomething(
        config=tconf,
        master_replica=FakeSomething(
            inBox=deque(),
            inBoxRouter=Router(),
            logger=FakeSomething(info=lambda *args, **kwargs: True)),
        name="Alpha",
        master_primary_name="Alpha",
        on_view_change_start=lambda *args, **kwargs: True,
        start_catchup=lambda *args, **kwargs: True,
        nodeInBox=deque(),
        nodeMsgRouter=Router(),
        metrics=None,
        process_one_node_message=None,
        quota_control=FakeSomething(node_quota=Quota(count=100, size=100)),
        nodestack=FakeSomething(
            service=lambda *args, **kwargs: eventually(lambda: True)))
    node.metrics = functools.partial(Node._createMetricsCollector, node)()
    node.process_one_node_message = functools.partial(
        Node.process_one_node_message, node)
    view_changer = ViewChanger(node)
    node.view_changer = view_changer
    node.viewNo = view_changer.view_no
    node.master_replica.node = node
    return view_changer
예제 #5
0
 def __init__(self, tmpdir):
     self.basedirpath = tmpdir
     self.name = 'Node1'
     self.f = 1
     self.replicas = []
     self.rank = None
     self.allNodeNames = [self.name, 'Node2', 'Node3', 'Node4']
     self.nodeReg = {name: HA("127.0.0.1", 0) for name in self.allNodeNames}
     self.totalNodes = len(self.allNodeNames)
     self.mode = Mode.starting
     self.replicas = [
         Replica(node=self, instId=0, isMaster=True),
         Replica(node=self, instId=1, isMaster=False),
         Replica(node=self, instId=2, isMaster=False),
     ]
     self._found = False
     self.ledgerManager = LedgerManager(self, ownedByNode=True)
     ledger0 = FakeLedger(0, 10)
     ledger1 = FakeLedger(1, 5)
     self.ledgerManager.addLedger(0, ledger0)
     self.ledgerManager.addLedger(1, ledger1)
     self.quorums = Quorums(self.totalNodes)
     self.config = getConfig()  # TODO do we need fake object here?
     self.view_changer = ViewChanger(self)
     self.elector = PrimarySelector(self)
예제 #6
0
def view_changer():
    config = FakeSomething(ViewChangeWindowSize=1, ForceViewChangeFreq=0)
    node = FakeSomething(name="fake node",
                         ledger_ids=[0],
                         config=config,
                         quorums=Quorums(7))
    view_changer = ViewChanger(node)
    return view_changer
예제 #7
0
def fake_view_changer(request, tconf):
    node_stack = FakeSomething(name="fake stack",
                               connecteds={"Alpha", "Beta", "Gamma", "Delta"})
    monitor = FakeSomething(isMasterDegraded=lambda: False, )
    node = FakeSomething(
        name="SomeNode",
        viewNo=request.param,
        quorums=Quorums(getValueFromModule(request, 'nodeCount', default=4)),
        nodestack=node_stack,
        utc_epoch=lambda *args: get_utc_epoch(),
        config=tconf,
        monitor=monitor,
        discard=lambda a, b, c: print(b),
    )
    view_changer = ViewChanger(node)
    return view_changer
예제 #8
0
 def patched_start_view_change(self, *args, **kwargs):
     self.node.processNodeInBox = functools.partial(TestNode.processNodeInBox, self.node)
     ViewChanger.start_view_change(self, *args, **kwargs)
     while stashed_msgs:
         self.node.nodestack.rxMsgs.append(stashed_msgs.popleft())
예제 #9
0
def create_view_changer(node):
    return ViewChanger(ViewChangerNodeModelDataProvider(node), node._timer)