public void WritesComplexInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("X", mem);

            Parallel.For(0, 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);
            });
        }
        public void ShiftsScope()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("twilight-zone");

            Assert.Empty(shifted.Catalog().List());
        }
        public void WritesPropsInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

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

            Assert.Equal("louie", hive.Comb("2CV").Props().Value("looping"));
        }
        public void AddsInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

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

            Assert.Equal(1, hive.Catalog().List().Count);
        }
        public void DistinguishesScope()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("twilight-zone");

            shifted.Catalog().Add("789");

            Assert.Contains("twilight-zone/hq/catalog.cat", mem.Contents().Knowledge(""));
        }
        public void PrependsScopeToCombName()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("prepend-this", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("prepend-this");

            Assert.StartsWith("prepend-this",
                              hive.Comb("123", false).Name()
                              );
        }
        public void DeliversHQXocument()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.HQ().Cell("A").Update(new InputOf(new byte[1] {
                0xAB
            }));

            Assert.Equal(
                new byte[1] {
                0xAB
            },
                hive.HQ().Cell("A").Content()
                );
        }
        public void WritesPropsWhenShifted()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("X", mem);

            Parallel.For(0, 256, (i) =>
            {
                var id = $"mech-{i}";
                hive.Shifted("machine").Catalog().Add(id);
                hive.Shifted("machine").Comb(id).Props().Refined("checksum", id);
            });

            Parallel.ForEach(hive.Shifted("machine").Catalog().List(), comb =>
            {
                Assert.Equal(comb.Name(), $"machine/{comb.Props().Value("checksum")}");
            });
        }
        public void DeliversProps()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog()
            .Add("123");

            hive.Catalog().List()[0]
            .Props()
            .Refined("prop", "eller");

            Assert.Equal(
                "eller",
                hive.Catalog().List()[0]
                .Props()
                .Value("prop")
                );
        }
        public void DeliversHQInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

            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()", "")
                        );
                });
        }
        public void DeliversHQInParallelAfterShift()
        {
            var   mem  = new RamMnemonic();
            IHive hive = new MemorizedHive("cars", mem);

            hive = hive.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"));
        }
        public void RemembersCombs()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog().Add("123");
            hive.Catalog().Add("456");

            hive.Comb("123", false)
            .Cell("my-cell")
            .Update(new InputOf("larva"));

            Assert.Equal(
                "larva",
                new TextOf(
                    new InputOf(
                        hive.Comb("123", false)
                        .Cell("my-cell")
                        .Content()
                        )
                    ).AsString()
                );
        }
        public void RemembersXocument()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("animal", mem);

            hive.Catalog().Add("123");
            hive.Catalog().Add("456");

            hive.Comb("456").Xocument("meatloaf.xml")
            .Modify(
                new Directives()
                .Xpath("/meatloaf")
                .Add("lines")
                .Add("line").Set("And I would do anything for love").Up()
                .Add("line").Set("But I won't do that").Up()
                );

            Assert.Contains(
                "But I won't do that",
                hive.Comb("456")
                .Xocument("meatloaf.xml")
                .Values("//line/text()")
                );
        }
示例#14
0
        public void WorksAsyncWithCache()
        {
            using (var dir = new TempDirectory())
            {
                IHive hive =
                    new MemorizedHive(
                        "product",
                        new CachedMnemonic(
                            new FileMnemonic(dir.Value().FullName)
                            )
                        ).Shifted("machine");

                long elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    hive.Catalog().Add(id);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Creation: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    var prop = hive.Comb(id).Props().Value("checksum", string.Empty);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Read 1: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, i =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    hive.Comb(id)
                    .Props()
                    .Refined("checksum", id);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Update props: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    var prop = hive.Comb(id).Props().Value("checksum", string.Empty);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Read 2: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, i =>
                {
                    var id   = $"mech-{i}";
                    var xoc  = hive.Comb(id).Xocument("stuff.xml");
                    var name = xoc.Value($"/stuff/thing/text()", "");
                    xoc.Modify(new Directives().Xpath("//name").Set(Guid.NewGuid()));

                    var xoc2  = hive.Comb(id).Xocument("stuff.xml");
                    var name2 = xoc.Value($"/stuff/thing/text()", "");
                    xoc2.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));

                    var xoc3  = hive.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);
                });


                Debug.WriteLine("Read Stuff: " + elapsed);
                elapsed = 0;
            }
        }