public void PartialCommandContractWithChannelIdSet() { var policy = new CommandPolicy(); policy.ChannelId = "fredo"; CommandHarness <CommandHarnessTest1> harness; harness = new CommandHarness <CommandHarnessTest1>(() => new CommandHarnessTest1(policy)); harness.Start(); Assert.IsTrue(harness.RegisteredCommands.Count == 1); }
public void PartialCommandContractWithNoChannelIdSet() { var policy = new CommandPolicy(); policy.ChannelId = null; CommandHarness <CommandHarnessTest1> harness; try { harness = new CommandHarness <CommandHarnessTest1>(() => new CommandHarnessTest1(policy)); harness.Start(); } catch (Exception ex) { Assert.IsTrue(ex is CommandChannelIdNullException); } }
public void TestMasterJob() { var policy = new CommandPolicy() { ChannelId = "default", JobSchedulesEnabled = true, CommandContractAttributeInherit = true, JobScheduleAttributeInherit = true }; //Default state. var harness = new CommandHarness <MasterJobCommandTop>(policy); harness.MasterJobNegotiationEnable(); harness.Start(); Assert.IsTrue(harness.RegisteredSchedules.Count == 1); Assert.IsTrue(harness.Dependencies.Scheduler.Count == 2); Assert.IsTrue(harness.RegisteredCommandMethods.Count == 2); Assert.IsFalse(harness.HasCommand(("one", "base"))); Assert.IsFalse(harness.HasSchedule("1base")); //Wait for the master job to go live. harness.MasterJobStart(); //Check that the MasterJob commands and schedules have been registered. Assert.IsTrue(harness.RegisteredSchedules.Count == 2); Assert.IsTrue(harness.Dependencies.Scheduler.Count == 3); Assert.IsTrue(harness.RegisteredCommandMethods.Count == 3); Assert.IsTrue(harness.HasCommand(("one", "top"))); Assert.IsTrue(harness.HasSchedule("1top")); Assert.IsTrue(harness.HasCommand(("one", "base"))); Assert.IsTrue(harness.HasSchedule("1base")); //Stop the master job harness.MasterJobStop(); //Check that the master job commands have been removed. Assert.IsTrue(harness.RegisteredSchedules.Count == 1); Assert.IsTrue(harness.Dependencies.Scheduler.Count == 2); Assert.IsTrue(harness.RegisteredCommandMethods.Count == 2); Assert.IsFalse(harness.HasCommand(("one", "base"))); Assert.IsFalse(harness.HasSchedule("1base")); }
public void FailNoResponseChannel() { var policy = new CommandPolicy() { ChannelId = "default", OutgoingRequestsEnabled = true }; var harness = new CommandHarness <OutgoingCommandRoot>(policy); try { harness.Start(); } catch (Exception ex) { Assert.IsTrue(ex is CommandStartupException); } }
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); }
public void TestInheritance() { var policy = new CommandPolicy() { ChannelId = "default", JobSchedulesEnabled = true, CommandContractAttributeInherit = true, JobScheduleAttributeInherit = true }; //Default state. var harness = new CommandHarness <CommandTop>(policy); harness.Start(); Assert.IsTrue(harness.RegisteredSchedules.Count == 2); Assert.IsTrue(harness.RegisteredCommandMethods.Count == 2); Assert.IsTrue(harness.HasCommand(("one", "top"))); Assert.IsTrue(harness.HasSchedule("1top")); Assert.IsTrue(harness.HasCommand(("one", "base"))); Assert.IsTrue(harness.HasSchedule("1base")); }