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 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 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 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 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 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 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 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()") ); }
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; } }