public async Task ReceivePackets_WithCancellation() { //Arrange var packets = TestNetwork.GeneratePackets(1); var results = new BlockingCollection <byte[]>(1); using var socket = DatagramSocketFactory.Create(); var port = TestNetwork.GetNextPort(); var cancellationSource = new CancellationTokenSource(); var random = new Random(); //Act socket.Bind(new IPEndPoint(IPAddress.Any, port)); var receivingTask = Task.Run(async() => { await foreach (var context in socket.ToOutputEnumerable().WithCancellation(cancellationSource.Token)) { results.Add(context.Buffer.AsMemory(context.Offset, context.Length).ToArray()); if (results.Count == results.BoundedCapacity) { cancellationSource.CancelAfter(TimeSpan.FromSeconds(random.NextDouble())); } } }); await TestNetwork.SendPacketsTo(port, packets); //Assert await Assert.ThrowsAsync <OperationCanceledException>(() => receivingTask); }
public async Task ReceivePackets() { //Arrange var packets = TestNetwork.GeneratePackets(10); var results = new BlockingCollection <byte[]>(10); using var socket = DatagramSocketFactory.Create(); var port = TestNetwork.GetNextPort(); //Act socket.Bind(new IPEndPoint(IPAddress.Any, port)); var receivingTask = Task.Run(async() => { await foreach (var context in socket.ToOutputEnumerable()) { results.Add(context.Buffer.AsMemory(context.Offset, context.Length).ToArray()); if (results.Count == results.BoundedCapacity) { break; } } }); var sendingTask = TestNetwork.SendPacketsTo(port, packets); await Task.WhenAll(receivingTask, sendingTask); //Assert results.Should().BeEquivalentTo(packets); }
// Use this for initialization void Start() { myParse = GameObject.Find("Preload").GetComponent <MyParse>(); testNetwork = GameObject.Find("Preload").GetComponent <TestNetwork>(); testNetwork.ReTestConnection(); isQuery = false; localPosition = 275.98f; top100Position = 275.98f; loadState = LoadState.Local; }
public void Call_Mainchain_Gateway_Get_Info() { var federation = new Federation(new[] { new PubKey("02fad5f3c4fdf4c22e8be4cfda47882fff89aaa0a48c1ccad7fa80dc5fee9ccec3"), new PubKey("02503f03243d41c141172465caca2f5cef7524f149e965483be7ce4e44107d7d35"), new PubKey("03be943c3a31359cd8e67bedb7122a0898d2c204cf2d0119e923ded58c429ef97c") }); Network sideChainNetwork = new TestNetwork(federation); string redeemScript = PayToFederationTemplate.Instance.GenerateScriptPubKey(federation.Id).ToString(); string federationIps = "127.0.0.1:36201,127.0.0.1:36202,127.0.0.1:36203"; string multisigPubKey = federation.GetFederationDetails().transactionSigningKeys.TakeLast(1).First().ToHex(); string[] args = new[] { "-mainchain", "-testnet", $"-federationips={federationIps}", $"-redeemscript={redeemScript}", $"-publickey={multisigPubKey}", "-mincoinmaturity=1", "-mindepositconfirmations=1" }; var nodeSettings = new NodeSettings(sideChainNetwork, ProtocolVersion.ALT_PROTOCOL_VERSION, args: args); this.federationWalletManager.IsFederationWalletActive().Returns(true); var settings = new FederatedPegSettings(nodeSettings, new CounterChainNetworkWrapper(KnownNetworks.StraxRegTest)); var controller = new FederationGatewayController( Substitute.For <IAsyncProvider>(), new ChainIndexer(), Substitute.For <IConnectionManager>(), this.crossChainTransferStore, this.GetMaturedBlocksProvider(settings), this.network, settings, this.federationWalletManager, Substitute.For <IFullNode>(), Substitute.For <IPeerBanning>(), this.federationManager); IActionResult result = controller.GetInfo(); result.Should().BeOfType <JsonResult>(); ((JsonResult)result).Value.Should().BeOfType <FederationGatewayInfoModel>(); var model = ((JsonResult)result).Value as FederationGatewayInfoModel; model.IsMainChain.Should().BeTrue(); model.FederationMiningPubKeys.Should().BeNull(); model.MiningPublicKey.Should().BeNull(); model.MultiSigRedeemScript.Should().Be(redeemScript); string.Join(",", model.FederationNodeIpEndPoints).Should().Be(federationIps); model.IsActive.Should().BeTrue(); model.MinimumDepositConfirmationsSmallDeposits.Should().Be(25); model.MinimumDepositConfirmationsNormalDeposits.Should().Be(80); model.MultisigPublicKey.Should().Be(multisigPubKey); }
private void OnDestroy() { TestNetwork.Instance = null; #if DB_SERVER _server.Stop(); #endif #if DB_CLIENT _playClient = false; #endif }
/// <summary> /// Trying to set up a network that look likes /// <code> /// _test1 /// |-----------, /// _test2 _test2.1 /// | /// _test3 /// </code> /// </summary> //[TestFixtureSetUp] public void Setup() { this.TestNetwork = new WCFNetwork(); this.TestNetwork.Start(); Address = TestNetwork.Local.Address.AsString; TestNetwork.GetChannel <RegisteredMessage>().Received += RegisteredAddressRecieved; this.TestOutgoing = TestNetwork.GetChannel <OutgoingMessage>(); this.TestReturn = TestNetwork.GetChannel <ReturnMessage>(); Debug.WriteLine(Environment.CurrentDirectory); Test2Process = Process.Start("nDistribute.WCF.TestExe.exe", Address); }
private float stopTime; //stop when animation finished //======================== void Start() { TextAsset binAsset = Resources.Load("Rule", typeof(TextAsset)) as TextAsset; string [] lineArray = binAsset.text.Split("\n"[0]); dataCount = lineArray.Length - 1; data = new string [dataCount][]; for (int i = 1; i < lineArray.Length; i++) { data[i - 1] = lineArray[i].Split(','); } /*string tmp = ""; * for (int i = 0; i < dataCount; i++) { * tmp = ""; * for (int j = 0; j < 4; j++) { * tmp += data[i][j] + " "; * } * Debug.Log(tmp); * }*/ binAsset = Resources.Load("Time", typeof(TextAsset)) as TextAsset; lineArray = binAsset.text.Split("\n"[0]); timeData = new float[lineArray.Length - 1][]; string[] tmp; for (int i = 1; i < lineArray.Length; i++) { tmp = lineArray[i].Split(','); timeData[i - 1] = new float[tmp.Length]; for (int j = 0; j < tmp.Length; j++) { timeData[i - 1][j] = float.Parse(tmp[j]); } } /*string tmp1 = ""; * for (int i = 0; i < timeData.Length; i++) { * tmp1 = ""; * for (int j = 0; j < 2; j++) { * tmp1 += timeData[i][j] + " "; * } * Debug.Log(tmp1); * }*/ myParse = GameObject.Find("Preload").GetComponent <MyParse>(); testNetwork = GameObject.Find("Preload").GetComponent <TestNetwork>(); countDownTimeLeft = 3f; countDownTimeLeftTmp = 3; combo = 0; gameState = GameState.Starting; }
/// <summary> /// This method refreshes the network location label. /// </summary> private async Task RefreshNetworkLocation() { bool result = await TestNetwork.IsProbeAvailable(); Invoke(new Action(() => { lblNetLocation.ForeColor = Color.Black; if (result) { lblNetLocation.Text = "Internal"; } else { lblNetLocation.Text = "External"; } })); }
/// <summary> /// This method refreshes the network status label. /// </summary> private async Task RefreshNetworkStatus() { bool result = await TestNetwork.IsProbeAvailable(true); Invoke(new Action(() => { if (result) { lblNetStatus.ForeColor = Color.DarkGreen; lblNetStatus.Text = "Connected"; } else { lblNetStatus.ForeColor = Color.DarkRed; lblNetStatus.Text = "Not Connected"; } })); }
internal Fixture(ISet <MemberId> memberIds, TestNetwork net, long electionTimeout, long heartbeatInterval) { this.Net = net; foreach (MemberId member in memberIds) { TestNetwork.Inbound inbound = new TestNetwork.Inbound(net, member); TestNetwork.Outbound outbound = new TestNetwork.Outbound(net, member); _members.Add(member); TimerService timerService = CreateTimerService(); BootstrapWaiter waiter = new BootstrapWaiter(); _bootstrapWaiters.Add(waiter); InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftMachine raftMachine = (new RaftMachineBuilder(member, memberIds.Count, RaftTestMemberSetBuilder.INSTANCE)).electionTimeout(electionTimeout).heartbeatInterval(heartbeatInterval).inbound(inbound).outbound(outbound).timerService(timerService).raftLog(raftLog).commitListener(waiter).build(); Rafts.Add(new RaftFixture(this, raftMachine, raftLog)); } }
public void IniReaderTest() { var ini = new IniReader(@"cal.model.ini", 4096, 102); var v = Vector <double> .Build.Dense(4096); var bias = TestNetwork.Score(v); int N = 10; for (int b = 0; b < N; b++) { Assert.AreEqual(bias[b], ini.Bias[b], 1e-5); } for (int f = 0; f < 1000; f++) { v[f] = 1; var pred = TestNetwork.Score(v); v[f] = 0; for (int b = 0; b < N; b++) { Assert.AreEqual(pred[b], ini.Bias[b] + ini.Weights[b * 4096 + f], 1e-5); } } }
// Use this for initialization void Awake() { I = this; }
private void Awake() { TestNetwork.Instance = this; }
public override IMatrix Apply(IMatrix m) { scores = TestNetwork.Score(m.GetColumn(0).Decrypt(null)); return(m); }