public void TestMethod1()
        {
            try
            {
                var fabric    = new ManualFabricBridge();
                var bridgeOut = fabric[FabricMode.Queue];
                var bridgein  = fabric[FabricMode.Broadcast];

                PersistenceClient <Guid, BridgeMe> init;
                DebugMemoryDataCollector           memp1, memp2;

                var p1 = new MicroservicePipeline("Sender")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddDebugMemoryDataCollector(out memp1)
                         .AddChannelIncoming("cresponse")
                         .AttachListener(bridgein.GetListener())
                         .Revert()
                         .AddChannelOutgoing("crequest")
                         .AttachSender(bridgeOut.GetSender())
                         .AttachPersistenceClient("cresponse", out init)
                         .Revert()
                ;

                var p2 = new MicroservicePipeline("Receiver")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddDebugMemoryDataCollector(out memp2)
                         .AddChannelIncoming("crequest")
                         .AttachListener(bridgeOut.GetListener())
                         .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe>((e) => e.Id, (s) => new Guid(s)))
                         .Revert()
                         .AddChannelOutgoing("cresponse")
                         .AttachSender(bridgein.GetSender())
                ;

                p2.ToMicroservice().Events.ExecuteBegin += CommunicationBridgeTests_OnExecuteBegin;
                p1.Start();
                p2.Start();

                int check1 = p1.ToMicroservice().Commands.Count();
                int check2 = p2.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;

                Assert.IsTrue(rs2.IsSuccess);
                Assert.IsTrue(rs2.Entity.Message == "Momma");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void Tcp1()
        {
            try
            {
                var bridgeOut = new CommunicationBridge(CommunicationBridgeMode.RoundRobin, new TcpCommunicationBridgeAgent(new IPEndPoint(IPAddress.Loopback, 8088)));
                var bridgein  = new CommunicationBridge(CommunicationBridgeMode.Broadcast, new TcpCommunicationBridgeAgent(new IPEndPoint(IPAddress.Loopback, 8088)));

                PersistenceClient <Guid, BridgeMe> init;
                DebugMemoryDataCollector           memp1, memp2;

                var p1 = new MicroservicePipeline("Sender")
                         .AdjustPolicyCommunicationBoundaryLoggingActive()
                         .AddDebugMemoryDataCollector(out memp1)
                         .AddChannelIncoming("cresponse")
                         .AttachListener(bridgein.GetListener())
                         .Revert()
                         .AddChannelOutgoing("crequest")
                         .AttachSender(bridgeOut.GetSender())
                         .AttachPersistenceClient("cresponse", out init)
                         .Revert()
                ;

                var p2 = new MicroservicePipeline("Receiver")
                         .AdjustPolicyCommunicationBoundaryLoggingActive()
                         .AddDebugMemoryDataCollector(out memp2)
                         .AddChannelIncoming("crequest")
                         .AttachListener(bridgeOut.GetListener())
                         .AttachPersistenceManagerHandlerMemory((BridgeMe e) => e.Id, (s) => new Guid(s))
                         .Revert()
                         .AddChannelOutgoing("cresponse")
                         .AttachSender(bridgein.GetSender())
                ;

                p2.ToMicroservice().Events.ExecuteBegin += CommunicationBridgeTests_OnExecuteBegin;
                p1.Start();
                p2.Start();

                int check1 = p1.ToMicroservice().Commands.Count();
                int check2 = p2.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;

                Assert.IsTrue(rs2.IsSuccess);
                Assert.IsTrue(rs2.Entity.Message == "Momma");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void TestMethod1()
        {
            try
            {
                var bridgeOut = new CommunicationBridge(CommunicationBridgeMode.RoundRobin);
                var bridgein  = new CommunicationBridge(CommunicationBridgeMode.Broadcast);

                PersistenceClient <Guid, BridgeMe> init;
                DebugMemoryDataCollector           memp1, memp2;

                var p1 = new MicroservicePipeline("Sender")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddDebugMemoryDataCollector(out memp1)
                         .AddChannelIncoming("cresponse")
                         .AttachListener(bridgein.GetListener())
                         .Revert()
                         .AddChannelOutgoing("crequest")
                         .AttachSender(bridgeOut.GetSender())
                         .AttachPersistenceClient("cresponse", out init)
                ;

                var p2 = new MicroservicePipeline("Receiver")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault   = true)
                         .AddDataCollector((c) => new DebugMemoryDataCollector(), (c) => memp2 = c)
                         .AddChannelIncoming("crequest")
                         .AttachMessageRedirectRule(
                    canRedirect: (p) => p.Message.MessageType.Equals("bridgeme", StringComparison.InvariantCultureIgnoreCase)
                    , redirect: (p) => p.Message.MessageType = "BridgeMe2"
                    )
                         .AttachListener(bridgeOut.GetListener())
                         .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe2>((e) => e.Id, (s) => new Guid(s)))
                         .Revert()
                         .AddChannelOutgoing("cresponse")
                         .AttachSender(bridgein.GetSender())
                ;

                p1.Start();
                p2.Start();

                int check1 = p1.ToMicroservice().Commands.Count();
                int check2 = p2.ToMicroservice().Commands.Count();

                var entity = new BridgeMe()
                {
                    Message = "Momma"
                };
                var rs = init.Create(entity, new RepositorySettings()
                {
                    WaitTime = TimeSpan.FromSeconds(20)
                }).Result;

                Assert.IsTrue(!rs.IsSuccess && rs.ResponseCode == 422);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 4
0
        public void Redirect1()
        {
            try
            {
                var fabric    = new ManualFabricBridge();
                var bridgeOut = fabric[FabricMode.Queue];
                var bridgein  = fabric[FabricMode.Broadcast];

                ICommandInitiator        init;
                DebugMemoryDataCollector memp1, memp2;

                var client = new MicroservicePipeline("Sender")
                             .AdjustPolicyCommunicationBoundaryLoggingActive()
                             .AddDebugMemoryDataCollector(out memp1)
                             .AddChannelIncoming("cresponse", autosetPartition01: false)
                             .AttachPriorityPartition((0, 0.9M), (1, 1.1M))
                             .AttachListener(bridgein.GetListener())
                             .AttachICommandInitiator(out init)
                             .Revert()
                             .AddChannelOutgoing("crequest")
                             .AttachSender(bridgeOut.GetSender())
                ;

                var server = new MicroservicePipeline("Receiver")
                             .AdjustPolicyCommunicationBoundaryLoggingActive()
                             .AddDebugMemoryDataCollector(out memp2)
                             .AddChannelIncoming("credirect")
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(201, "Hi");
                    return(Task.FromResult(0));
                }, ("one", "two"))
                             .Revert()
                             .AddChannelIncoming("crequest")
                             .AttachMessageRedirectRule(
                    canRedirect: (p) => p.Message.MessageType.Equals("bridgeme", StringComparison.InvariantCultureIgnoreCase)
                    , redirect: (p) =>
                {
                    p.Message.MessageType = "BridgeMe2";
                    p.Message.ActionType  = "Whatever";
                }
                    )
                             .AttachMessageRedirectRule(
                    canRedirect: (p) => p.Message.MessageType.Equals("redirectme", StringComparison.InvariantCultureIgnoreCase)
                    , redirect: (p) =>
                {
                    p.Message.ChannelId   = "credirect";
                    p.Message.MessageType = "one";
                    p.Message.ActionType  = "two";
                }
                    )
                             .AttachListener(bridgeOut.GetListener())
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(400, "Blah");
                    return(Task.FromResult(0));
                }, ("BridgeMe", "create"))
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(200, "Yah!");
                    return(Task.FromResult(0));
                }, ("bridgeMe2", "whatever"))
                             .Revert()
                             .AddChannelOutgoing("cresponse")
                             .AttachSender(bridgein.GetSender())
                ;

                client.Start();
                server.Start();

                int check1 = client.ToMicroservice().Commands.Count();
                int check2 = server.ToMicroservice().Commands.Count();

                var entity = new BridgeMe()
                {
                    Message = "Momma"
                };

                var rs = init.Process <BridgeMe, string>(("crequest", "BRIDGEME", "create"), entity).Result;
                Assert.IsTrue(rs.ResponseCode == 200);

                var rs2 = init.Process <BridgeMe, string>(("crequest", "redirectme", "hmm"), entity).Result;
                Assert.IsTrue(rs2.ResponseCode == 201);

                client.Stop();
                server.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        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;
            }
        }