示例#1
0
        public void DiscoveredNodeCache_Test()
        {
            var endpoint1 = "192.168.100.100:101";
            var endpoint2 = "192.168.100.100:102";

            var result = _discoveredNodeCacheProvider.TryTake(out var endpoint);

            result.ShouldBeFalse();
            endpoint.ShouldBeNull();

            _discoveredNodeCacheProvider.Add(endpoint1);
            _discoveredNodeCacheProvider.Add(endpoint2);

            result = _discoveredNodeCacheProvider.TryTake(out endpoint);
            result.ShouldBeTrue();
            endpoint.ShouldBe(endpoint1);

            _discoveredNodeCacheProvider.Add(endpoint1);

            result = _discoveredNodeCacheProvider.TryTake(out endpoint);
            result.ShouldBeTrue();
            endpoint.ShouldBe(endpoint2);
        }
示例#2
0
        public async Task RefreshNode_Test()
        {
            var node1 = new NodeInfo
            {
                Endpoint = "192.168.100.1:8000",
                Pubkey   = ByteString.CopyFromUtf8("node1")
            };
            await _peerDiscoveryService.AddNodeAsync(node1);

            var node2 = new NodeInfo
            {
                Endpoint = "192.168.100.1:8001",
                Pubkey   = ByteString.CopyFromUtf8("node2")
            };
            await _peerDiscoveryService.AddNodeAsync(node2);

            await _peerDiscoveryService.RefreshNodeAsync();

            var nodeList = await _nodeManager.GetRandomNodesAsync(10);

            nodeList.Nodes.Count.ShouldBe(2);
            nodeList.Nodes.ShouldContain(node1);
            nodeList.Nodes.ShouldContain(node2);

            await _peerDiscoveryService.RefreshNodeAsync();

            nodeList = await _nodeManager.GetRandomNodesAsync(10);

            nodeList.Nodes.Count.ShouldBe(1);
            nodeList.Nodes[0].ShouldBe(node1);

            _discoveredNodeCacheProvider.TryTake(out var endpoint);
            endpoint.ShouldBe(node1.Endpoint);

            _discoveredNodeCacheProvider.TryTake(out endpoint);
            endpoint.ShouldBeNull();
        }