Beispiel #1
0
        public void TransferSpeedCaptureTest(TransferSpeedType speedType)
        {
            _nodeStats = new NodeStatsLight(_node);

            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 30);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 51);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 140);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 110);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 133);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 51);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 140);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 110);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 133);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 51);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 140);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 110);
            _nodeStats.AddTransferSpeedCaptureEvent(speedType, 133);

            var av = _nodeStats.GetAverageTransferSpeed(speedType);

            Assert.AreEqual(102, av);

            var paddedAv = _nodeStats.GetPaddedAverageTransferSpeed(speedType);

            Assert.AreEqual("  102", paddedAv);
        }
    public void Should_allocate_by_speed_post_merge()
    {
        ulong[]           totalDifficulties = { 1, 3, 2 };
        int[]             averageSpeed      = { 5, 8, 10 };
        PublicKey[]       publicKeys        = { TestItem.PublicKeyA, TestItem.PublicKeyB, TestItem.PublicKeyC };
        PeerInfo[]        peers             = new PeerInfo[3];
        INodeStatsManager _nodeStatsManager = Substitute.For <INodeStatsManager>();

        for (int i = 0; i < 3; i++)
        {
            ISyncPeer syncPeer = Substitute.For <ISyncPeer>();
            syncPeer.IsInitialized.Returns(true);
            Node node = new Node(publicKeys[i], "192.168.1.18", i);
            syncPeer.Node.Returns(node);
            syncPeer.TotalDifficulty.Returns(new UInt256(totalDifficulties[i]));
            peers[i] = new PeerInfo(syncPeer);
            peers[i].HeadNumber.Returns(1);
            INodeStats nodeStats = Substitute.For <INodeStats>();
            nodeStats.GetAverageTransferSpeed(Arg.Any <TransferSpeedType>()).Returns(averageSpeed[i]);
            _nodeStatsManager.GetOrAdd(peers[i].SyncPeer.Node).Returns(nodeStats);
        }
        IPoSSwitcher poSSwitcher = Substitute.For <IPoSSwitcher>();

        poSSwitcher.TerminalTotalDifficulty.Returns(new UInt256(1));
        poSSwitcher.HasEverReachedTerminalBlock().Returns(true);

        IBeaconPivot beaconPivot = Substitute.For <IBeaconPivot>();

        IPeerAllocationStrategy mergePeerAllocationStrategy =
            (new MergeBlocksSyncPeerAllocationStrategyFactory(poSSwitcher, beaconPivot, Substitute.For <ILogManager>())).Create(new BlocksRequest());
        IBlockTree _blockTree = Substitute.For <IBlockTree>();
        PeerInfo?  info       = mergePeerAllocationStrategy.Allocate(null, peers, _nodeStatsManager, _blockTree);

        Assert.AreEqual(info, peers[2]);    // peer with highest highest speed
    }
Beispiel #3
0
        public void TransferSpeedCaptureTest()
        {
            _nodeStats = new NodeStatsLight(_node, _config);

            _nodeStats.AddTransferSpeedCaptureEvent(30);
            _nodeStats.AddTransferSpeedCaptureEvent(51);
            _nodeStats.AddTransferSpeedCaptureEvent(140);
            _nodeStats.AddTransferSpeedCaptureEvent(110);
            _nodeStats.AddTransferSpeedCaptureEvent(133);
            _nodeStats.AddTransferSpeedCaptureEvent(51);
            _nodeStats.AddTransferSpeedCaptureEvent(140);
            _nodeStats.AddTransferSpeedCaptureEvent(110);
            _nodeStats.AddTransferSpeedCaptureEvent(133);
            _nodeStats.AddTransferSpeedCaptureEvent(51);
            _nodeStats.AddTransferSpeedCaptureEvent(140);
            _nodeStats.AddTransferSpeedCaptureEvent(110);
            _nodeStats.AddTransferSpeedCaptureEvent(133);

            var av = _nodeStats.GetAverageTransferSpeed();

            Assert.AreEqual(102, av);
        }