示例#1
0
        public void UpdatesCellsInParallel()
        {
            var hive     = new RamHive("product");
            var comb     = "Dr.Robotic";
            var index    = -1;
            var contents = new ConcurrentDictionary <string, string>();

            new ParallelFunc(() =>
            {
                var id      = "Item_" + ++index;
                var content = Guid.NewGuid().ToString();
                hive.Catalog().Add(comb);
                hive.Comb(comb).Cell(id).Update(new InputOf(content));

                contents.AddOrUpdate(id, content, (a, b) => content);
                return(true);
            },
                             Environment.ProcessorCount << 4,
                             10000
                             ).Invoke();

            Parallel.ForEach(contents.Keys, (record) =>
            {
                Assert.Equal(
                    contents[record],
                    new TextOf(hive.Comb(comb).Cell(record).Content()).AsString()
                    );
            });
        }
示例#2
0
        public void WritesComplexInParallel()
        {
            var hive = new RamHive("product");

            for (int i = 0; i < 256; i++)
            {
                var id = $"mech-{i}";
                hive.Shifted("machine").Catalog().Add(id);
                hive.Shifted("machine").Comb(id).Props().Refined("checksum", id);
            }

            Parallel.For(0, 256, i =>
            {
                var id = $"mech-{i}";
                using (var xoc = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                {
                    var name = xoc.Value($"/stuff/thing/text()", "");
                    xoc.Modify(new Directives().Xpath("//name").Set(Guid.NewGuid()));
                    using (var xoc2 = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                    {
                        var name2 = xoc.Value($"/stuff/thing/text()", "");
                        xoc2.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));
                        using (var xoc3 = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                        {
                            var name3 = xoc.Value($"/stuff/thing/text()", "");
                            xoc3.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));
                        }
                    }
                }
                Assert.Equal(1, hive.Shifted("machine").Comb(id).Xocument("stuff.xml").Nodes("//thing").Count);
            });
        }
示例#3
0
        public void WorksParallelWithRamHive()
        {
            var hive    = new RamHive("product");
            var machine = "Dr.Robotic";

            new ParallelFunc(() =>
            {
                var id = Guid.NewGuid().ToString();
                hive.Shifted("to-the-left").Catalog().Add(machine);

                var content = Guid.NewGuid().ToString();
                hive.Shifted("to-the-left")
                .Comb(machine)
                .Cell(id)
                .Update(new InputOf(content));

                Assert.Equal(
                    content,
                    new TextOf(
                        hive.Shifted("to-the-left")
                        .Comb(machine)
                        .Cell(id)
                        .Content()
                        ).AsString()
                    );
                return(true);
            },
                             256,
                             10000
                             ).Invoke();
        }
示例#4
0
 public void FindsComb()
 {
     using (var dir = new TempDirectory())
     {
         var hive = new RamHive("product");
         hive.Catalog().Add("2CV");
         Assert.NotEmpty(
             hive.Catalog().List()
             );
     }
 }
示例#5
0
        public void AddsInParallel()
        {
            var valve = new LocalSyncPipe();
            var hive  = new RamHive("testRamHive");

            Parallel.For(0, Environment.ProcessorCount << 4, (i) =>
                    {
                    hive.Catalog().Add("123");
                });

            Assert.Equal(1, hive.Catalog().List().Count);
        }
示例#6
0
        public void PrependsScopeToCombName()
        {
            using (var dir = new TempDirectory())
            {
                var hive    = new RamHive("product");
                var shifted = hive.Shifted("prepend-this");
                shifted.Catalog().Add("an-entry");

                Assert.StartsWith("prepend-this",
                                  shifted.Comb("an-entry").Name()
                                  );
            }
        }
示例#7
0
        public void WritesPropsInParallel()
        {
            var hive = new RamHive("product");

            hive.Catalog().Add("2CV");

            Parallel.For(0, Environment.ProcessorCount << 4, i =>
                    {
                    hive.Comb("2CV").Props().Refined("looping", "louie");
                });

            Assert.Equal("louie", hive.Comb("2CV").Props().Value("looping"));
        }
示例#8
0
 public void ShiftsScope()
 {
     using (var dir = new TempDirectory())
     {
         IHive hive = new RamHive("product");
         hive.Catalog().Add("2CV");
         hive = hive.Shifted("machine");
         hive.Catalog().Add("DrRobotic");
         Assert.Equal(
             1,
             hive.Catalog().List().Count
             );
     }
 }
示例#9
0
        public void ShiftsHQ()
        {
            using (var dir = new TempDirectory())
            {
                var hive = new RamHive("cockpit");
                hive.Catalog().Add("log");

                var shifted = hive.Shifted("factory");
                shifted.Catalog().Add("booyaa");

                var shiftedAgain = shifted.Shifted("cockpit");

                Assert.Contains("log", shiftedAgain.Catalog().List()[0].Name());
            }
        }
示例#10
0
        public void WritesPropsWhenShifted()
        {
            var hive = new RamHive("product");

            for (int i = 0; i < 256; i++)
            {
                var id = $"mech-{i}";
                hive.Shifted("machine").Catalog().Add(id);
                hive.Shifted("machine").Comb(id).Props().Refined("checksum", id);
            }

            foreach (var comb in hive.Shifted("machine").Catalog().List())
            {
                Assert.Equal(comb.Name(), $"machine/{comb.Props().Value("checksum")}");
            }
        }
示例#11
0
        public void DeliversHQInParallelAfterShift()
        {
            var hive  = new RamHive("person").Shifted("still-parallel");
            var first = true;

            Parallel.For(0, Environment.ProcessorCount << 4, i =>
                    {
                    if (!first)
                    {
                        hive.Catalog().Remove("X");
                        first = false;
                    }
                    hive.Catalog().Add("X");
                });

            Assert.True(hive.Catalog().Has("X"));
        }
示例#12
0
        public void DeliversHQInParallel()
        {
            var hive = new RamHive("person");

            Parallel.For(0, Environment.ProcessorCount << 4, i =>
                    {
                    var xoc = hive.HQ().Xocument("test");
                    xoc.Modify(
                        new Directives()
                        .Xpath("/test")
                        .AddIf("result")
                        .Set("passed")
                        );
                    Assert.Equal(
                        "passed",
                        hive.HQ().Xocument("test").Value("/test/result/text()", "")
                        );
                });
        }
示例#13
0
        public void RemembersCombCell()
        {
            IHive hive = new RamHive("product");

            using (var cell = hive.Comb("2CV").Cell("Some-testing-item"))
            {
                cell.Update(new InputOf("I am a very cool testdata string"));
            }

            using (var cell = hive.Comb("2CV").Cell("Some-testing-item")
                   )
            {
                Assert.Equal(
                    "I am a very cool testdata string",
                    new TextOf(
                        cell.Content()
                        ).AsString()
                    );
            }
        }