示例#1
0
        public void ParallelAccessWorks()
        {
            var content  = new BytesOf("Works").AsBytes();
            var accesses = 0;
            var cell     =
                new FkCell(
                    (update) => { },
                    () =>
            {
                accesses++;
                Assert.Equal(1, accesses);
                accesses--;
                return(content);
            }
                    );

            var valve = new LocalSyncPipe();

            Parallel.For(0, Environment.ProcessorCount << 4, (i) =>
                    {
                    Assert.Equal(
                        "Works",
                        new TextOf(
                            new SyncCell(cell, valve).Content()
                            ).AsString()
                        );
                });
        }
示例#2
0
        public void WorksWithRamCell()
        {
            var cell   = new RamCell();
            var gate   = new LocalSyncPipe();
            var synced = new SyncCell(cell, gate);

            synced.Update(new InputOf("its so hot outside"));
            Assert.Equal(
                "its so hot outside",
                new TextOf(synced.Content()).AsString()
                );
        }
示例#3
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);
        }
示例#4
0
 public void WorksWithFileCell()
 {
     using (var file = new TempFile())
     {
         var path = file.Value();
         var gate = new LocalSyncPipe();
         Parallel.For(0, Environment.ProcessorCount << 4, (current) =>
                 {
                 var cell = new SyncCell(new FileCell(path), gate);
                 cell.Update(new InputOf("File cell Input"));
                 Assert.Equal("File cell Input", new TextOf(cell.Content()).AsString());
             });
     }
 }
示例#5
0
 public void WorksWithFileHive()
 {
     using (var dir = new TempDirectory())
     {
         var valve = new LocalSyncPipe();
         var hive  = new FileHive(dir.Value().FullName, "product");
         hive.Catalog().Add("2CV");
         Parallel.For(0, Environment.ProcessorCount << 4, i =>
                 {
                 hive.Comb("2CV");
                 hive.Scope();
                 hive.HQ();
             });
     }
 }
        public void ModifiesExclusive()
        {
            var syncGate = new LocalSyncPipe();
            var mem      = new RamMnemonic();

            Parallel.For(0, Environment.ProcessorCount << 4, (current) =>
                    {
                    var content = Guid.NewGuid().ToString();
                    var synced  =
                        new SyncXocument("xoc",
                                         new MemorizedXocument("xoc", mem),
                                         syncGate
                                         );

                    synced.Modify(new Directives().Xpath("/xoc").Set(content));
                    Assert.NotEmpty(synced.Value("/xoc/text()", ""));
                });
        }
示例#7
0
        public void DoesNotBlockItself()
        {
            var cell = new RamCell();
            var gate = new LocalSyncPipe();

            Parallel.For(0, Environment.ProcessorCount << 4, (current) =>
                    {
                    var content = "ABC";
                    var first   = new SyncCell(cell, gate);
                    first.Update(new InputOf(content));
                    var again = new SyncCell(cell, gate);
                    again.Update(new InputOf(content));
                    var andAgain = new SyncCell(cell, gate);
                    andAgain.Update(new InputOf(content));
                    System.Threading.Thread.Sleep(1);
                    Assert.Equal(
                        "ABC ABC ABC",
                        $"{new TextOf(first.Content()).AsString()} {new TextOf(again.Content()).AsString()} {new TextOf(andAgain.Content()).AsString()}"
                        );
                });
        }
        public void ReadsExclusive()
        {
            var accesses = 0;
            var syncGate = new LocalSyncPipe();

            Parallel.For(0, Environment.ProcessorCount << 4, (i) =>
                    {
                    var xoc =
                        new SyncXocument("synced",
                                         new FkXocument(() =>
                {
                    accesses++;
                    Assert.Equal(1, accesses);
                    accesses--;
                    return
                    (new XDocument(
                         new XElement("synced", new XText("here"))
                         ));
                }),
                                         syncGate
                                         );
                    xoc.Value("/synced/text()", "");
                });
        }