Exemplo n.º 1
0
    public static IFluentSequenceMutatorBuilder ProcessOnMultipleThreads(this IFluentSequenceMutatorBuilder builder, int threadCount, Action <int, IFluentSequenceMutatorBuilder> mutatorBuilder)
    {
        var splitter = new Splitter <DefaultRowQueue>(builder.ProcessBuilder.Result.Context)
        {
            Name         = "ParallelSplitter",
            InputProcess = builder.ProcessBuilder.Result,
        };

        var merger = new ParallelMerger(builder.ProcessBuilder.Result.Context)
        {
            Name         = "ParallelMerger",
            SequenceList = new List <ISequence>(),
        };

        for (var i = 0; i < threadCount; i++)
        {
            var subBuilder        = SequenceBuilder.Fluent;
            var subMutatorBuilder = subBuilder.ReadFrom(splitter);
            mutatorBuilder.Invoke(i, subMutatorBuilder);

            var subProcess = subBuilder.Result;
            merger.SequenceList.Add(subProcess);
        }

        builder.ProcessBuilder.Result = merger;
        return(builder);
    }
Exemplo n.º 2
0
        public void MergerTest()
        {
            var context = TestExecuter.GetContext();

            var merger = new ParallelMerger(context)
            {
                ProcessList = new List <IProducer>(),
            };

            for (var i = 0; i < 3; i++)
            {
                merger.ProcessList.Add(new CustomMutator(context)
                {
                    InputProcess = TestData.Person(context),
                    Action       = row =>
                    {
                        Thread.Sleep(new Random().Next(100));
                        row["ThreadIndex"] = i;
                        return(true);
                    },
                });
            }

            var result = merger.Evaluate().TakeRowsAndReleaseOwnership().ToList();

            Assert.AreEqual(21, result.Count);
            foreach (var p in TestData.Person(context).Evaluate().TakeRowsAndReleaseOwnership())
            {
                Assert.AreEqual(3, result.Count(m => m.GetAs <int>("id") == p.GetAs <int>("id")));
            }

            var exceptions = context.GetExceptions();

            Assert.AreEqual(0, exceptions.Count);
        }
Exemplo n.º 3
0
        public void MergerTest()
        {
            var topic = TestExecuter.GetTopic();

            var merger = new ParallelMerger(topic, null)
            {
                ProcessList = new List <IEvaluable>(),
            };

            for (var i = 0; i < 3; i++)
            {
                merger.ProcessList.Add(new CustomMutator(topic, null)
                {
                    InputProcess = TestData.Person(topic),
                    Then         = (proc, row) =>
                    {
                        Thread.Sleep(new Random().Next(100));
                        row.SetValue("ThreadIndex", i);
                        return(true);
                    },
                });
            }

            var result = merger.Evaluate().TakeRowsAndReleaseOwnership().ToList();

            Assert.AreEqual(21, result.Count);
            foreach (var p in TestData.Person(topic).Evaluate().TakeRowsAndReleaseOwnership())
            {
                Assert.AreEqual(3, result.Count(m => m.GetAs <int>("id") == p.GetAs <int>("id")));
            }

            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(0, exceptions.Count);
        }
Exemplo n.º 4
0
        public void SplitterTestWithMerger()
        {
            var context = TestExecuter.GetContext();

            var splitter = new Splitter <DefaultRowQueue>(context)
            {
                InputProcess = new EnumerableImporter(context)
                {
                    InputGenerator = caller => TestData.Person(context).Evaluate(caller).TakeRowsAndReleaseOwnership(),
                },
            };

            var merger = new ParallelMerger(context)
            {
                ProcessList = new List <IProducer>(),
            };

            for (var i = 0; i < 3; i++)
            {
                merger.ProcessList.Add(new CustomMutator(context)
                {
                    InputProcess = splitter,
                    Action       = row =>
                    {
                        Thread.Sleep(new Random().Next(10));
                        row["ThreadIndex"] = i;
                        return(true);
                    },
                });
            }

            var result = merger.Evaluate().TakeRowsAndReleaseOwnership().ToList();

            Assert.AreEqual(7, result.Count);
            foreach (var p in TestData.Person(context).Evaluate().TakeRowsAndReleaseOwnership())
            {
                Assert.IsTrue(result.Any(m => m.GetAs <int>("id") == p.GetAs <int>("id")));
            }

            var exceptions = context.GetExceptions();

            Assert.AreEqual(0, exceptions.Count);
        }