Exemplo n.º 1
0
        protected virtual IPipeline Pipeline()
        {
            var pipeline = new MicroservicePipeline(GetType().Name);

            pipeline
            .AddDebugMemoryDataCollector(out mCollector)
            .AddPayloadSerializerDefaultJson()
            .AddChannelIncoming("internalIn", internalOnly: true)
            .AttachCommand(mCommand)
            .CallOut((c) => cpipeIn = c)
            .Revert()
            .AddChannelOutgoing("internalOut", internalOnly: true, autosetPartition01: false)
            .AttachPriorityPartition(0, 1)
            .CallOut((c) => cpipeOut = c)
            .Revert()
            .AddChannelIncoming("internalInit", internalOnly: true)
            .AttachCommandInitiator(out mCommandInit);

            return(pipeline);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }