Exemplo n.º 1
0
        public void CommandLocal1()
        {
            try
            {
                DebugMemoryDataCollector memp1;
                ICommandInitiator        init;

                var p1 = new MicroservicePipeline(nameof(CommandLocal1), serviceReference: typeof(CommandLocal))
                         .AddDebugMemoryDataCollector(out memp1)
                         //.AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddICommandInitiator(out init)
                         .AddChannelIncoming("fredo")
                         .AttachCommand(typeof(ITestCommandLocal1), (ctx) =>
                {
                    var message = ctx.RequestPayloadGet <string>();
                    ctx.ResponseSet(200, "howdy");

                    return(Task.FromResult(0));
                }
                                        )
                         .Revert();

                p1.Start();

                var ok = init.Process <ITestCommandLocal1, string, string>("Hello").Result;

                p1.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public void Pipeline()
        {
            var pipe = new MicroservicePipeline();

            pipe.Start();

            pipe.Stop();
        }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            var pipeline = new MicroservicePipeline("AzureTest");

            pipeline.Start();

            pipeline.Stop();
        }
Exemplo n.º 4
0
        public void PersistenceSingle()
        {
            try
            {
                PersistenceClient <Guid, Sample1> repo;

                var p1 = new MicroservicePipeline("Local")
                         .AddChannelIncoming("request")
                         .AttachPersistenceManagerHandlerMemory(
                    keyMaker: (Sample1 e) => e.Id
                    , keyDeserializer: (s) => new Guid(s)
                    , versionPolicy: ((e) => e.VersionId.ToString("N").ToUpperInvariant(), (e) => e.VersionId = Guid.NewGuid(), true)
                    )
                         .AttachPersistenceClient(out repo)
                         .Revert()
                ;

                p1.Start();

                var sample = new Sample1()
                {
                    Message = "Hello mom"
                };
                var id = sample.Id;
                //Run a set of simple version entity tests.
                //Create
                Assert.IsTrue(repo.Create(sample).Result.IsSuccess);
                //Read
                var result = repo.Read(id).Result;
                Assert.IsTrue(result.IsSuccess);
                Assert.IsTrue(result.Entity.Message == "Hello mom");
                //Update success
                var rs = repo.Update(sample).Result;
                Assert.IsTrue(rs.IsSuccess);
                //We have enabled version policy and optimistic locking so the next command should fail.
                //Update fail as old version
                Assert.IsFalse(repo.Update(sample).Result.IsSuccess);
                //But this one should pass.
                //Update pass as new entity.
                Assert.IsTrue(repo.Update(rs.Entity).Result.IsSuccess);
                //Read
                Assert.IsTrue(repo.Read(sample.Id).Result.IsSuccess);
                //Delete
                Assert.IsTrue(repo.Delete(sample.Id).Result.IsSuccess);
                //Read fail.
                Assert.IsFalse(repo.Read(sample.Id).Result.IsSuccess);

                p1.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var pipeline = new MicroservicePipeline("Server");

            pipeline.Start();
            Console.WriteLine("Press a key to stop.");
            Console.ReadKey();
            pipeline.Stop();
            Console.WriteLine("Service stopped.");
            Console.ReadKey();
        }
        public void PersistenceLocal1()
        {
            try
            {
                DebugMemoryDataCollector          memp1;
                PersistenceClient <Guid, Sample1> init;

                var p1 = new MicroservicePipeline(nameof(PersistenceLocal1))
                         .AddDebugMemoryDataCollector(out memp1)
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddChannelIncoming("fredo")
                         .AttachPersistenceManagerHandlerMemory(
                    (Sample1 e) => e.Id, (s) => new Guid(s)
                    , versionPolicy: ((e) => e.VersionId.ToString("N").ToUpperInvariant(), (e) => e.VersionId = Guid.NewGuid(), true)
                    , resourceProfile: ("paul1", true)
                    )
                         .AttachPersistenceClient(out init)
                         .Revert()
                ;

                p1.Start();

                var sample = new Sample1();

                //Run a set of simple version entity tests.
                //Create
                Assert.IsTrue(init.Create(sample).Result.IsSuccess);
                //Read
                Assert.IsTrue(init.Read(sample.Id).Result.IsSuccess);
                //Update success
                var rs = init.Update(sample).Result;
                Assert.IsTrue(rs.IsSuccess);
                //We have enabled version policy and optimitic locking so the next command should fail.
                //Update fail as old version
                Assert.IsFalse(init.Update(sample).Result.IsSuccess);
                //But this one should pass.
                //Update pass as new entity.
                Assert.IsTrue(init.Update(rs.Entity).Result.IsSuccess);
                //Read
                Assert.IsTrue(init.Read(sample.Id).Result.IsSuccess);
                //Delete
                Assert.IsTrue(init.Delete(sample.Id).Result.IsSuccess);
                //Read fail.
                Assert.IsFalse(init.Read(sample.Id).Result.IsSuccess);

                p1.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void TestReroute()
        {
            var                      bridgeOut = new ManualCommunicationBridgeAgent(new ManualFabricBridge(), CommunicationBridgeMode.RoundRobin);
            bool                     success = false;
            ManualResetEvent         mre = new ManualResetEvent(false);
            DebugMemoryDataCollector memp1, memp2;

            var p1 = new MicroservicePipeline("Sender")
                     .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                     .AddDebugMemoryDataCollector(out memp1)
                     .AddChannelIncoming("fredo")
                     .AttachCommand(typeof(IContractInitial), (ctx) =>
            {
                ctx.Responses.Add(new TransmissionPayload(ctx.Request.Message.Clone().SetDestination <IContractFinal>()));
                return(Task.FromResult(0));
            })
                     .Revert()
                     .AddChannelOutgoing("crequest")
                     .AttachSender(bridgeOut.GetSender())
                     .Revert()
            ;

            var p2 = new MicroservicePipeline("Receiver")
                     .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                     .AddDebugMemoryDataCollector(out memp2)
                     .AddChannelIncoming("crequest")
                     .AttachListener(bridgeOut.GetListener())
                     .AttachCommand(typeof(IContractFinal), (ctx) =>
            {
                var value = ctx.PayloadSerializer.PayloadDeserialize <string>(ctx.Request);

                success = value == "Hello";
                mre.Set();
                return(Task.FromResult(0));
            })
                     .Revert()
            ;

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

            //Send the message to the command asynchronously.
            p1.ToMicroservice().Dispatch.Process <IContractInitial>("Hello");

            mre.WaitOne();

            Assert.IsTrue(success);

            p1.Stop();
            p2.Stop();
        }
Exemplo n.º 8
0
        public void Pipeline()
        {
            var pipe = new MicroservicePipeline();

            pipe
            .AddChannelIncoming("freddyin", autosetPartition01: false)
            .AttachPriorityPartition(0, 1, 2)
            .Revert()
            .AddChannelOutgoing("freddyout", autosetPartition01: false)
            .AttachPriorityPartition(1, 2)
            ;

            pipe.Start();

            pipe.Stop();
        }
Exemplo n.º 9
0
        public void TestMethod1()
        {
            CommandInitiator init;

            try
            {
                var sender = new MicroservicePipeline("initiator")
                             .ConfigurationOverrideSet(AzureServiceBusExtensionMethods.KeyServiceBusConnection, SbConn)
                             .AddChannelOutgoing("remote")
                             .AttachAzureServiceBusQueueSender()
                             .Revert()
                             .AddChannelIncoming("response")
                             .AttachAzureServiceBusTopicListener(listenOnOriginatorId: true)
                             .AttachCommandInitiator(out init)
                ;

                var listener = new MicroservicePipeline("responder")
                               .ConfigurationOverrideSet(AzureServiceBusExtensionMethods.KeyServiceBusConnection, SbConn)
                               .AddChannelIncoming("remote")
                               .AttachAzureServiceBusQueueListener()
                               .AttachCommand(new SimpleCommand())
                               .Revert()
                               .AddChannelIncoming("deadletter")
                               .AttachMessageRedirectRule((p) => true, new ServiceMessageHeader("remote", "process", "deadletter"))
                               .AttachAzureServiceBusQueueListener("remote", isDeadLetterListener: true)
                               .Revert()
                               .AddChannelOutgoing("response")
                               .AttachAzureServiceBusTopicSender()
                ;

                listener.Start();

                sender.Start();

                var rs = init.Process <ISimpleCommand, string, string>("hello")?.Result;

                Assert.IsTrue(rs?.Response == "mom");

                sender.Stop();
                listener.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 10
0
        public void Test1()
        {
            var msp = new MicroservicePipeline();

            msp.ConfigurationOverrideSet("override", "one");
            var value1 = msp.Configuration.PlatformOrConfigCache("override");

            Assert.IsTrue(value1 == "one");

            msp.ConfigurationOverrideSet("override", "two");
            var value2 = msp.Configuration.PlatformOrConfigCache("override");

            Assert.IsTrue(value2 == "two");

            msp.Start();

            msp.Stop();
        }
Exemplo n.º 11
0
        public void Bug180()
        {
            try
            {
                ServiceMessageHeader destination = ("internalIn/frankie/benny");

                ICommandInitiator        init;
                DebugMemoryDataCollector collector;

                var pipeline = new MicroservicePipeline("TestPipeline")
                               .AdjustPolicyTaskManagerForDebug()
                               .AddDebugMemoryDataCollector(out collector)
                               .AddICommandInitiator(out init)
                               .AddChannelIncoming("internalIn", internalOnly: true)
                               .AttachCommand((c) =>
                {
                    c.ResponseSet(200);
                    return(Task.FromResult(0));
                }, ("frankie", "benny"))
                               .AttachCommand((ctx) =>
                {
                    ctx.ResponseSet(200);
                    return(Task.FromResult(0));
                }, ("internalIn", "frankie4fingers", "benny"))
                               .Revert()
                               .AddChannelOutgoing("internalOut", internalOnly: true)
                               .Revert();

                pipeline.Start();

                var rs = init.Process <string, string>(destination, "hello").Result;

                pipeline.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 12
0
        public void CommandLocal1()
        {
            try
            {
                DebugMemoryDataCollector memp1;
                ICommandInitiator        init;

                var p1 = new MicroservicePipeline(nameof(CommandLocal1))
                         .AddDebugMemoryDataCollector(out memp1)
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddChannelIncoming("fredo")
                         .AttachCommand(typeof(ITestCommandLocal1), (rq, rsc, pl) =>
                {
                    var payload = rq.PayloadUnpack <string>(pl);

                    var rs = rq.ToResponse();

                    rs.PayloadPack <string>(pl, "howdy");

                    rsc.Add(rs);
                    return(Task.FromResult(0));
                }
                                        )
                         .AttachICommandInitiator(out init)
                         .Revert()
                ;

                p1.Start();

                //var ok = init.Process<ITestCommandLocal1, string, string>("Hello", new RequestSettings).Result;

                p1.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 13
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;
            }
        }
Exemplo n.º 14
0
        public void Pipeline1()
        {
            try
            {
                var pipeline = new MicroservicePipeline("TestPipeline");

                IPipelineChannelIncoming <MicroservicePipeline> cpipeIn     = null;
                IPipelineChannelOutgoing <MicroservicePipeline> cpipeOut    = null;
                PersistenceInternalService <Guid, Blah>         persistence = null;
                PersistenceBlahMemory    persistBlah = null;
                DebugMemoryDataCollector collector;

                int signalChange = 0;

                pipeline
                .AddDebugMemoryDataCollector(out collector)
                .AdjustPolicyTaskManager((t, c) =>
                {
                    t.ConcurrentRequestsMin = 1;
                    t.ConcurrentRequestsMax = 4;
                })
                .CallOut(ConfigureServiceRoot)
                .CallOut(CallOutDefault)
                .AddChannelIncoming("internalIn", internalOnly: true)
                .CallOut(ChannelInConfigure, (c) => true)
                .AttachCommand(new PersistenceBlahMemory(profile: "Blah"), assign: (p) => persistBlah    = p)
                .AttachCommand(new PersistenceInternalService <Guid, Blah>(), assign: (c) => persistence = c, channelResponse: cpipeOut)
                .CallOut((c) => cpipeIn = c)
                .Revert()
                .AddChannelOutgoing("internalOut", internalOnly: true)
                .CallOut(ChannelOutConfigure, (c) => false)
                .CallOut((c) => cpipeOut = c)
                .Revert();

                persistBlah.OnEntityChangeAction += ((o, e) => { signalChange++; });

                pipeline.Start();


                Guid cId  = Guid.NewGuid();
                var  blah = new Blah {
                    ContentId = cId, Message = "Hello", VersionId = Guid.NewGuid()
                };
                var result = persistence.Create(blah).Result;
                Assert.IsTrue(result.IsSuccess);

                var result2 = persistence.Read(cId).Result;
                Assert.IsTrue(result2.IsSuccess);

                blah.VersionId = Guid.NewGuid();
                var result3 = persistence.Update(blah).Result;
                Assert.IsTrue(result3.IsSuccess);

                var result4 = persistence.Delete(blah.ContentId).Result;
                Assert.IsTrue(result4.IsSuccess);


                Assert.IsTrue(signalChange == 3);

                Assert.IsTrue(calloutDefault.HasValue);
                Assert.IsTrue(calloutIn.HasValue);
                Assert.IsFalse(calloutOut.HasValue);

                pipeline.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void PipelineCaseInsensitive()
        {
            try
            {
                DebugMemoryDataCollector collector1, collector2;
                CommandInitiator         init = null;

                var fabric       = new ManualFabricBridge();
                var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                var pClient = new MicroservicePipeline("Client");
                var pServer = new MicroservicePipeline("Server");

                pServer
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector2)
                .AddPayloadSerializerDefaultJson()
                .AddChannelIncoming("INTERNALIN", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition((0, 1.0M), (1, 0.9M))
                .AttachListener(bridgeOut.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("FRANKY", "johnny5"))
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(201, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "JoHnny6"))
                .Revert()
                .AddChannelOutgoing("return")
                .AttachSender(bridgeReturn.GetSender())
                .Revert();
                ;

                pClient
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1)
                .AddChannelIncoming("Return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;

                pClient.Start();
                pServer.Start();

                var list = new List <Task <ResponseWrapper <string> > >();

                list.Add(init.Process <ICaseSensitiveTest1, Blah, string>(new Blah()
                {
                    Message = "hello1"
                }));
                list.Add(init.Process <Blah, string>("Internalin", "franky", "johnny5", new Blah()
                {
                    Message = "hello2"
                }));
                list.Add(init.Process <Blah, string>(("InternalIn", "Franky", "johnny5"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("internalIN", "FRANKY", "johnny6"), new Blah()
                {
                    Message = "hello3"
                }));

                var result = Task.WhenAll(list).Result;

                result.ForEach((r) => Assert.IsTrue(r.ResponseCode == 200 || r.ResponseCode == 201));

                pClient.Stop();
                pServer.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 16
0
        public void PersistenceAzureClientServer()
        {
            try
            {
                //Either use a .runsettings file to set this value 'CI_ServiceBusConnection' or just manually set the value here if you want to run the test.
                var sbConnection = TestContext.GetCISettingAsString(AzureServiceBusExtensionMethods.KeyServiceBusConnection);

                PersistenceClient <Guid, Sample1> repo;

                var p1 = new MicroservicePipeline("Server")
                         .ConfigurationOverrideSet(AzureServiceBusExtensionMethods.KeyServiceBusConnection, sbConnection)
                         .AddChannelIncoming("request")
                         .AttachPersistenceManagerHandlerMemory(
                    keyMaker: (Sample1 e) => e.Id
                    , keyDeserializer: (s) => new Guid(s)
                    , versionPolicy: ((e) => e.VersionId.ToString("N").ToUpperInvariant(), (e) => e.VersionId = Guid.NewGuid(), true)
                    )
                         .AttachAzureServiceBusQueueListener()
                         .Revert()
                         .AddChannelOutgoing("response")
                         .AttachAzureServiceBusTopicSender()
                ;

                var p2 = new MicroservicePipeline("Client")
                         .ConfigurationOverrideSet(AzureServiceBusExtensionMethods.KeyServiceBusConnection, sbConnection)
                         .AddChannelIncoming("response")
                         .AttachAzureServiceBusTopicListener()
                         .Revert()
                         .AddChannelOutgoing("request")
                         .AttachAzureServiceBusQueueSender()
                         .AttachPersistenceClient("response", out repo)
                         .Revert()
                ;

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

                var sample = new Sample1()
                {
                    Message = "Hello mom"
                };
                var id = sample.Id;
                //Run a set of simple version entity tests.
                //Create
                Assert.IsTrue(repo.Create(sample).Result.IsSuccess);
                //Read
                var result = repo.Read(id).Result;
                Assert.IsTrue(result.IsSuccess);
                Assert.IsTrue(result.Entity.Message == "Hello mom");
                //Update success
                var rs = repo.Update(sample).Result;
                Assert.IsTrue(rs.IsSuccess);
                //We have enabled version policy and optimistic locking so the next command should fail.
                //Update fail as old version
                Assert.IsFalse(repo.Update(sample).Result.IsSuccess);
                //But this one should pass.
                //Update pass as new entity.
                Assert.IsTrue(repo.Update(rs.Entity).Result.IsSuccess);
                //Read
                Assert.IsTrue(repo.Read(sample.Id).Result.IsSuccess);
                //Delete
                Assert.IsTrue(repo.Delete(sample.Id).Result.IsSuccess);
                //Read fail.
                Assert.IsFalse(repo.Read(sample.Id).Result.IsSuccess);

                p1.Stop();
                p2.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 17
0
        public void Pipeline3()
        {
            try
            {
                var pipeline    = new MicroservicePipeline("TestPipeline");
                var destination = ServiceMessageHeader.FromKey("internalIn/frankie/benny");
                var fragment    = ServiceMessageHeaderFragment.FromKey("frankie/benny");

                ICommandInitiator        init;
                DebugMemoryDataCollector collector;

                pipeline
                .AddDebugMemoryDataCollector(out collector)
                .AdjustPolicyTaskManagerForDebug()
                .AddChannelIncoming("internalIn", internalOnly: true)
                .AttachCommand((ctx) =>
                {
                    string entity;

                    if (ctx.DtoTryGet(out entity))
                    {
                        Assert.AreEqual(entity, "Hello");
                        ctx.ResponseSet(200, entity + "Good good", "It's all good");
                    }
                    else
                    {
                        ctx.ResponseSet(400, description: "It's all messed up.");
                    }

                    ctx.Collector.LogMessage("It's all good.");

                    return(Task.FromResult(0));
                }
                               , fragment)
                .Revert()
                .AddChannelIncoming("internalRs", internalOnly: true)
                .AttachICommandInitiator(out init)
                .Revert();

                pipeline.Start();

                var rs1 = init.Process <string, string>(destination, "Hello", new RequestSettings()
                {
                    CorrelationId = "freddy"
                }).Result;
                var rs2 = init.Process <string, string>(destination, null, new RequestSettings()
                {
                    CorrelationId = "johnny"
                }).Result;

                Assert.IsTrue(rs1.ResponseCode.Value == 200);
                Assert.IsTrue(rs1.Response == "HelloGood good");
                Assert.IsTrue(rs2.ResponseCode.Value == 400);

                pipeline.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 18
0
        public void Pipeline2()
        {
            try
            {
                DebugMemoryDataCollector collector1, collector1a, collector2;
                CommandInitiator         init  = null;
                CommandInitiator         init2 = null;

                IPipelineChannelIncoming <MicroservicePipeline> cpipeIn  = null;
                IPipelineChannelOutgoing <MicroservicePipeline> cpipeOut = null;

                var fabric       = new ManualFabricBridge();
                var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                //bridgeReturn.Agent.OnReceive += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };
                //bridgeReturn.Agent.OnException += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };

                var pClient  = new MicroservicePipeline("Client");
                var pClient2 = new MicroservicePipeline("Client2");
                var pServer  = new MicroservicePipeline("Server");

                pServer
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector2)
                .AddPayloadSerializerDefaultJson()
                .AddChannelIncoming("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeIn = p)
                .AttachPriorityPartition((0, 1.0M), (1, 0.9M))
                .AttachListener(bridgeOut.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(201, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny6"))
                .Revert()
                .AddChannelOutgoing("return")
                .AttachSender(bridgeReturn.GetSender())
                .Revert();
                ;

                pClient
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeOut = p)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;


                pClient2
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1a)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init2)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;

                pClient.Start();
                pClient2.Start();
                pServer.Start();

                init.OnRequestUnresolved  += Init_OnRequestUnresolved;
                init2.OnRequestUnresolved += Init_OnRequestUnresolved;

                var list = new List <Task <ResponseWrapper <string> > >();

                list.Add(init.Process <IPipelineTest2, Blah, string>(new Blah()
                {
                    Message = "hello1"
                }));
                list.Add(init.Process <Blah, string>("internalIn", "franky", "johnny5", new Blah()
                {
                    Message = "hello2"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny5"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny6"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("spooky", "franky", "johnny5"), new Blah()
                {
                    Message = "hellospooky"
                }));

                var result = Task.WhenAll(list).Result;

                result.ForEach((r) => Assert.IsTrue(r.ResponseCode == 200 || r.ResponseCode == 201));

                pClient.Stop();
                pClient2.Stop();
                pServer.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 19
0
        public void PersistenceClientServer()
        {
            try
            {
                var fabric         = new ManualFabricBridge();
                var bridgeRequest  = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeResponse = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                PersistenceClient <Guid, Sample1> repo;

                var p1 = new MicroservicePipeline("Server")
                         .AddChannelIncoming("request")
                         .AttachPersistenceManagerHandlerMemory(
                    keyMaker: (Sample1 e) => e.Id
                    , keyDeserializer: (s) => new Guid(s)
                    , versionPolicy: ((e) => e.VersionId.ToString("N").ToUpperInvariant(), (e) => e.VersionId = Guid.NewGuid(), true)
                    )
                         .AttachListener(bridgeRequest.GetListener())
                         .Revert()
                         .AddChannelOutgoing("response")
                         .AttachSender(bridgeResponse.GetSender())
                ;

                var p2 = new MicroservicePipeline("Client")
                         .AddChannelIncoming("response")
                         .AttachListener(bridgeResponse.GetListener())
                         .Revert()
                         .AddChannelOutgoing("request")
                         .AttachSender(bridgeRequest.GetSender())
                         .AttachPersistenceClient("response", out repo)
                         .Revert()
                ;

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

                var sample = new Sample1()
                {
                    Message = "Hello mom"
                };
                var id = sample.Id;
                //Run a set of simple version entity tests.
                //Create
                Assert.IsTrue(repo.Create(sample).Result.IsSuccess);
                //Read
                var result = repo.Read(id).Result;
                Assert.IsTrue(result.IsSuccess);
                Assert.IsTrue(result.Entity.Message == "Hello mom");
                //Update success
                var rs = repo.Update(sample).Result;
                Assert.IsTrue(rs.IsSuccess);
                //We have enabled version policy and optimistic locking so the next command should fail.
                //Update fail as old version
                Assert.IsFalse(repo.Update(sample).Result.IsSuccess);
                //But this one should pass.
                //Update pass as new entity.
                Assert.IsTrue(repo.Update(rs.Entity).Result.IsSuccess);
                //Read
                Assert.IsTrue(repo.Read(sample.Id).Result.IsSuccess);
                //Delete
                Assert.IsTrue(repo.Delete(sample.Id).Result.IsSuccess);
                //Read fail.
                Assert.IsFalse(repo.Read(sample.Id).Result.IsSuccess);

                p1.Stop();
                p2.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }