public void OutgoingTests() { var policy = new CommandPolicy() { ChannelId = "default" , JobSchedulesEnabled = true , OutgoingRequestMaxProcessingTimeDefault = TimeSpan.FromSeconds(1) , OutgoingRequestDefaultTimespan = TimeSpan.FromSeconds(1) , OutgoingRequestsEnabled = true , ResponseChannelId = "incoming" }; var harness = new CommandHarness <OutgoingCommandRoot>(policy); bool timed_out = false; var mre = new ManualResetEventSlim(); harness.Service.OnOutgoingRequest += (object sender, OutgoingRequestEventArgs e) => { }; harness.Service.OnOutgoingRequestTimeout += (object sender, OutgoingRequestEventArgs e) => { timed_out = true; mre.Set(); }; harness.Start(); //Create the timeout poll Task.Run(async() => { while (!timed_out) { harness.OutgoingTimeoutScheduleExecute(); await Task.Delay(100); } }); harness.ScheduleExecute("1base"); mre.Wait(); Assert.IsTrue(timed_out); }
public void PartialCommandContractWithChannelIdSet() { int countTotal = 0; int countOutgoing = 0; int countResponse = 0; var policy = new CommandPolicy() { ChannelId = "fredo", OutgoingRequestsEnabled = true, ResponseChannelId = "getback" }; var harness = new CommandHarness <CommandHarness1>(policy); harness.Start(); Assert.IsTrue(harness.RegisteredCommandMethods.Count == 2); bool ok = false; harness .Intercept((ctx) => ok = true, CommandHarnessTrafficDirection.Outgoing, ("one", null, null)) .Intercept((ctx) => Interlocked.Increment(ref countTotal)) .Intercept((ctx) => Interlocked.Increment(ref countOutgoing), header: ("one", null, null)) .Intercept((ctx) => Interlocked.Increment(ref countResponse), header: ("getback", null, null)) .InterceptOutgoing((c) => { string rString = null; c.RequestPayloadTryGet <string>(out rString); c.ResponseSet <string>(200, "over and out", "Hello mum"); }) ; harness.ScheduleExecute("1"); harness.Dispatcher.Process(("fredo", "two", "three"), "Helloe"); harness.Dispatcher.Process(("one", "two"), "Helloe", responseHeader: ("2", "3")); Assert.IsTrue(harness.TrafficPayloadOutgoing.Count == 2); Assert.IsTrue(ok); Assert.IsTrue(countTotal == 7); Assert.IsTrue(countOutgoing == 2); }