コード例 #1
0
        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")}");
            });
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
0
        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(""));
        }
コード例 #5
0
        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()
                              );
        }
コード例 #6
0
        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"));
        }
コード例 #7
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;
            }
        }