def fake_monitor(tconf): def getThroughput(self, instId): return self.throughputs[instId].throughput throughputs = dict() instances = Instances() for i in range(NUM_OF_REPLICAS): throughputs[i] = Monitor.create_throughput_measurement(tconf, start_ts=0) instances.add(i) monitor = FakeSomething( throughputs=throughputs, instances=instances, Delta=tconf.DELTA, throughput_avg_strategy_cls=MedianLowStrategy, ) monitor.numOrderedRequests = dict() for i in range(NUM_OF_REPLICAS): monitor.numOrderedRequests[i] = (100, 100) monitor.getThroughputs = functools.partial(Monitor.getThroughputs, monitor) monitor.getThroughput = functools.partial(getThroughput, monitor) monitor.getInstanceMetrics = functools.partial(Monitor.getInstanceMetrics, monitor) monitor.masterThroughputRatio = functools.partial( Monitor.masterThroughputRatio, monitor) return monitor
def fake_monitor(tconf): def getThroughput(self, instId): return self.throughputs[instId].throughput throughputs = dict() instances = Instances() num_of_replicas = 5 for i in range(num_of_replicas): throughputs[i] = Monitor.create_throughput_measurement(tconf) instances.add(i) monitor = FakeSomething( throughputs=throughputs, instances=instances, Delta=tconf.DELTA, throughput_avg_strategy_cls=MedianLowStrategy, ) monitor.numOrderedRequests = dict() for i in range(num_of_replicas): monitor.numOrderedRequests[i] = (100, 100) monitor.getThroughputs = functools.partial(Monitor.getThroughputs, monitor) monitor.getThroughput = functools.partial(getThroughput, monitor) monitor.getInstanceMetrics = functools.partial(Monitor.getInstanceMetrics, monitor) monitor.instance_throughput_ratio = functools.partial(Monitor.instance_throughput_ratio, monitor) monitor.is_instance_throughput_too_low = functools.partial(Monitor.is_instance_throughput_too_low, monitor) monitor.addInstance = functools.partial(Monitor.addInstance, monitor) return monitor
def __init__(self, *args, **kwargs): self.nodeMsgRouter.routes[TestMsg] = self.eatTestMsg self.nodeIbStasher = Stasher(self.nodeInBox, "nodeInBoxStasher~" + self.name) self.clientIbStasher = Stasher(self.clientInBox, "clientInBoxStasher~" + self.name) self.actionQueueStasher = Stasher(self.actionQueue, "actionQueueStasher~" + self.name) # alter whitelist to allow TestMsg type through without sig self.authnWhitelist = self.authnWhitelist + (TestMsg, ) # Nodes that wont be blacklisted by this node if the suspicion code # is among the set of suspicion codes mapped to its name. If the set of # suspicion codes is empty then the node would not be blacklisted for # any suspicion code self.whitelistedClients = {} # type: Dict[str, Set[int]] # Clients that wont be blacklisted by this node if the suspicion code # is among the set of suspicion codes mapped to its name. If the set of # suspicion codes is empty then the client would not be blacklisted for # suspicion code self.whitelistedClients = {} # type: Dict[str, Set[int]] # Reinitialize the monitor d, l, o = self.monitor.Delta, self.monitor.Lambda, self.monitor.Omega self.instances = Instances() self.monitor = TestMonitor(self.name, d, l, o, self.instances) for i in range(len(self.replicas)): self.monitor.addInstance()
def fake_monitor(tconf): latencies = [] instances = Instances() for i in range(NUM_OF_REPLICAS): latencies.append(LatencyMeasurement()) instances.add() monitor = FakeSomething( instances=instances, Omega=tconf.OMEGA, clientAvgReqLatencies=latencies, latency_avg_strategy_cls=MedianHighStrategy, ) monitor.getLatencies = functools.partial(Monitor.getLatencies, monitor) monitor.isMasterAvgReqLatencyTooHigh = functools.partial( Monitor.isMasterAvgReqLatencyTooHigh, monitor) return monitor
def test_not_send_if_master_Id_is_None(fake_node, testNodeClass): fake_node.isParticipating = True fake_node.view_change_in_progress = False fake_node._update_new_ordered_reqs_count = lambda: True fake_node.instances = Instances() fake_node.checkPerformance = functools.partial( testNodeClass.checkPerformance, fake_node) assert fake_node.checkPerformance() == True
def fake_node(fake_node): @contextmanager def measure_time(*args): yield fake_node.instances = Instances() fake_node.instances.add(0) fake_node.spylog = [] fake_node.metrics = FakeSomething(add_event=lambda *args: True, measure_time=measure_time) return fake_node
def __init__(self, *args, **kwargs): self.nodeMsgRouter.routes[TestMsg] = self.eatTestMsg self.nodeIbStasher = Stasher(self.nodeInBox, "nodeInBoxStasher~" + self.name) self.clientIbStasher = Stasher(self.clientInBox, "clientInBoxStasher~" + self.name) self.actionQueueStasher = Stasher(self.actionQueue, "actionQueueStasher~" + self.name) # alter whitelist to allow TestMsg type through without sig self.authnWhitelist = self.authnWhitelist + (TestMsg,) # Nodes that wont be blacklisted by this node if the suspicion code # is among the set of suspicion codes mapped to its name. If the set of # suspicion codes is empty then the node would not be blacklisted for # any suspicion code self.whitelistedNodes = {} # type: Dict[str, Set[int]] # Clients that wont be blacklisted by this node if the suspicion code # is among the set of suspicion codes mapped to its name. If the set of # suspicion codes is empty then the client would not be blacklisted for # suspicion code self.whitelistedClients = {} # type: Dict[str, Set[int]] # Reinitialize the monitor d, l, o = self.monitor.Delta, self.monitor.Lambda, self.monitor.Omega notifierEventTriggeringConfig = self.monitor.notifierEventTriggeringConfig self.instances = Instances() self.nodeInfo = { 'data': {} } pluginPaths = kwargs.get('pluginPaths', []) self.monitor = TestMonitor( self.name, d, l, o, self.instances, MockedNodeStack(), MockedBlacklister(), nodeInfo=self.nodeInfo, notifierEventTriggeringConfig=notifierEventTriggeringConfig, pluginPaths=pluginPaths) for i in range(len(self.replicas)): self.monitor.addInstance() self.replicas._monitor = self.monitor self.replicas.register_monitor_handler()
def fake_node(fake_node): fake_node.instances = Instances() fake_node.instances.add() fake_node.spylog = [] return fake_node