public void Create(string id , ICommunicationBridge bridgeOut, ICommunicationBridge bridgeIn, ICommunicationBridge bridgeMaster , TestMasterJobCommand masterjob , out PersistenceClient <Guid, BridgeMe> init, out DebugMemoryDataCollector memcollector) { var pipeline = new MicroservicePipeline(id) .AdjustPolicyTaskManagerForDebug() .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true) .AddDebugMemoryDataCollector(out memcollector) .AddChannelIncoming("local", internalOnly: true) .AttachCommand(masterjob) .Revert() .AddChannelIncoming("cresponse") .AttachListener(bridgeIn.GetListener()) .Revert() .AddChannelOutgoing("crequest") .AttachSender(bridgeOut.GetSender()) .AttachPersistenceClient("cresponse", out init) .Revert() .AddChannelBroadcast("negotiate") .AttachListener(bridgeMaster.GetListener()) .AttachSender(bridgeMaster.GetSender()) .AssignMasterJob(masterjob) .Revert() ; Add(id, pipeline, masterjob); }
public void Add(string id, MicroservicePipeline pipeline, TestMasterJobCommand masterjob) { Services.Add(id, pipeline); masterjob.OnMasterJobStateChange += (o, e) => MasterJobStateChange(o, e); masterjob.OnMasterJobCommunication += (o, e) => Log.Add(e); }
public void MasterJobNegotiation() { var ctx = new EnqueueContext(); var fabric = new ManualFabricBridge(); var bridgeOut = fabric[FabricMode.Queue]; var bridgeIn = fabric[FabricMode.Broadcast]; var bridgeMaster = fabric[FabricMode.Broadcast]; try { PersistenceClient <Guid, BridgeMe> init1, init3; DebugMemoryDataCollector memp1, memp2, memp3; ManualChannelSender incoming = null; var mast1 = new TestMasterJobCommand(); var mast2 = new TestMasterJobCommand(); var mast3 = new TestMasterJobCommand(); ctx.Create("Sender1", bridgeOut, bridgeIn, bridgeMaster, mast1, out init1, out memp1); ctx.Create("Sender3", bridgeOut, bridgeIn, bridgeMaster, mast3, out init3, out memp3); ctx.Add("Receiver2" , new MicroservicePipeline("Receiver2") .AdjustPolicyTaskManagerForDebug() .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true) .AddDebugMemoryDataCollector(out memp2) .AddChannelIncoming("local", internalOnly: true) .AttachCommand(mast2) .Revert() .AddChannelIncoming("crequest") .AttachListener(bridgeOut.GetListener()) .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe>((e) => e.Id, (s) => new Guid(s))) .Revert() .AddChannelOutgoing("cresponse") .AttachSender(bridgeIn.GetSender(), (a) => incoming = a as ManualChannelSender) .Revert() .AddChannelBroadcast("negotiate") .AttachListener(bridgeMaster.GetListener()) .AttachSender(bridgeMaster.GetSender()) .AssignMasterJob(mast2) .Revert() //.AddChannelIncoming("Deadletter") // .AttachListener(incoming.GetDeadLetterListener()) // .Revert() , mast2); ctx.Services.Values.ForEach((v) => v.Start()); //Check that the standard comms are working. var entity = new BridgeMe() { Message = "Momma" }; var rs = init1.Create(entity, new RepositorySettings() { WaitTime = TimeSpan.FromSeconds(30) }).Result; var rs2 = init1.Read(entity.Id).Result; var rs3 = init3.Read(entity.Id).Result; Assert.IsTrue(rs2.IsSuccess); Assert.IsTrue(rs3.IsSuccess); Assert.IsTrue(rs2.Entity.Message == "Momma"); //Wait for one of the services to go master. ctx.MasterJobSignal.WaitOne(); //OK, next service take over Assert.IsNotNull(ctx.MasterName); ctx.MasterJobSignal.Reset(); var holdme1 = ctx.MasterName; ctx.Stop(holdme1); //OK, final service take over ctx.MasterJobSignal.WaitOne(); Assert.IsNotNull(ctx.MasterName); ctx.MasterJobSignal.Reset(); var holdme2 = ctx.MasterName; ctx.Stop(holdme2); ctx.MasterJobSignal.WaitOne(); var holdme3 = ctx.MasterName; ctx.Stop(ctx.MasterName); Assert.IsNotNull(holdme3); //Check that the payloads have been successfully signalled. Assert.IsTrue(bridgeOut.PayloadsAllSignalled); Assert.IsTrue(bridgeIn.PayloadsAllSignalled); //Assert.IsTrue(bridgeMaster.PayloadsAllSignalled); } catch (Exception ex) { throw; } }
public void MasterJobNegotiation() { ManualResetEvent mre = new ManualResetEvent(false); var services = new Dictionary <string, MicroservicePipeline>(); string masterName = null; Action <object, string> goingMaster = (o, s) => { if (masterName != null) { Assert.Fail(); } masterName = s; mre.Set(); }; Action <TestMasterJobCommand> release = (c) => { c.OnGoingMaster += (object o, string s) => goingMaster(o, s); }; try { var bridgeOut = new CommunicationBridge(CommunicationBridgeMode.RoundRobin); var bridgein = new CommunicationBridge(CommunicationBridgeMode.Broadcast); var bridgeMaster = new CommunicationBridge(CommunicationBridgeMode.Broadcast); PersistenceClient <Guid, BridgeMe> init, init3; DebugMemoryDataCollector memp1, memp2, memp3; TestMasterJobCommand mast1 = null, mast2 = null, mast3 = null; services.Add("Sender1", new MicroservicePipeline("Sender1") .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true) .AddDebugMemoryDataCollector(out memp1) .AddChannelIncoming("local", internalOnly: true) .AttachCommand(mast1 = new TestMasterJobCommand(), assign: release) .Revert() .AddChannelIncoming("cresponse") .AttachListener(bridgein.GetListener()) .Revert() .AddChannelOutgoing("crequest") .AttachSender(bridgeOut.GetSender()) .AttachPersistenceClient("cresponse", out init) .Revert() .AddChannelBroadcast("negotiate") .AttachListener(bridgeMaster.GetListener()) .AttachSender(bridgeMaster.GetSender()) .AssignMasterJob(mast1) .Revert() ); services.Add("Sender3", new MicroservicePipeline("Sender3") .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true) .AddDebugMemoryDataCollector(out memp3) .AddChannelIncoming("local", internalOnly: true) .AttachCommand(mast3 = new TestMasterJobCommand(), assign: release) .Revert() .AddChannelIncoming("cresponse") .AttachListener(bridgein.GetListener()) .Revert() .AddChannelOutgoing("crequest") .AttachSender(bridgeOut.GetSender()) .AttachPersistenceClient("cresponse", out init3) .Revert() .AddChannelBroadcast("negotiate") .AttachListener(bridgeMaster.GetListener()) .AttachSender(bridgeMaster.GetSender()) .AssignMasterJob(mast3) .Revert() ); services.Add("Receiver2", new MicroservicePipeline("Receiver2") .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true) .AddDebugMemoryDataCollector(out memp2) .AddChannelIncoming("local", internalOnly: true) .AttachCommand(mast2 = new TestMasterJobCommand(), assign: release) .Revert() .AddChannelIncoming("crequest") .AttachListener(bridgeOut.GetListener()) .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe>((e) => e.Id, (s) => new Guid(s))) .Revert() .AddChannelOutgoing("cresponse") .AttachSender(bridgein.GetSender()) .Revert() .AddChannelBroadcast("negotiate") .AttachListener(bridgeMaster.GetListener()) .AttachSender(bridgeMaster.GetSender()) .AssignMasterJob(mast2) .Revert() ); services.Values.ForEach((v) => v.Start()); int check1 = services["Sender1"].ToMicroservice().Commands.Count(); int check2 = services["Sender3"].ToMicroservice().Commands.Count(); var entity = new BridgeMe() { Message = "Momma" }; var rs = init.Create(entity, new RepositorySettings() { WaitTime = TimeSpan.FromMinutes(5) }).Result; var rs2 = init.Read(entity.Id).Result; var rs3 = init3.Read(entity.Id).Result; Assert.IsTrue(rs2.IsSuccess); Assert.IsTrue(rs3.IsSuccess); Assert.IsTrue(rs2.Entity.Message == "Momma"); //Wait for one of the services to go master. mre.WaitOne(); Assert.IsNotNull(masterName); //Ok, service 2 take over mre.Reset(); var holdme1 = masterName; masterName = null; services[holdme1].Stop(); mre.WaitOne(); //Ok, service 3 take over mre.Reset(); var holdme2 = masterName; masterName = null; services[holdme2].Stop(); mre.WaitOne(); Assert.IsNotNull(masterName); } catch (Exception ex) { throw; } }