Esempio n. 1
0
        public void GetChainReturnsConcurrentChainFromDisk()
        {
            string dir   = AssureEmptyDir("TestData/ChainRepository/GetChainReturnsConcurrentChainFromDisk");
            var    chain = new ConcurrentChain(Network.RegTest);
            var    tip   = this.AppendBlock(chain);

            using (var session = new DBreezeSingleThreadSession("session", dir))
            {
                session.Execute(() =>
                {
                    var toSave = tip;
                    List <ChainedBlock> blocks = new List <ChainedBlock>();
                    while (toSave != null)
                    {
                        blocks.Insert(0, toSave);
                        toSave = toSave.Previous;
                    }
                    foreach (var block in blocks)
                    {
                        session.Transaction.Insert <int, BlockHeader>("Chain", block.Height, block.Header);
                    }

                    session.Transaction.Commit();
                }).Wait();
            }

            using (var repo = new ChainRepository(dir))
            {
                var testChain = new ConcurrentChain(Network.RegTest);
                repo.Load(testChain).GetAwaiter().GetResult();
                Assert.Equal(tip, testChain.Tip);
            }
        }
 public void DoStartsTransaction()
 {
     using (var session = new DBreezeSingleThreadSession("TestThread", AssureEmptyDir("TestData/DBreezeSingleThreadSession/DoStartsTransaction")))
     {
         session.Execute(() =>
         {
             Assert.NotNull(session.Transaction);
         });
     }
 }
 public void DoRunsSameThreadAsSessionCreated()
 {
     using (var session = new DBreezeSingleThreadSession("TestThread", AssureEmptyDir("TestData/DBreezeSingleThreadSession/DoRunsSameThreadAsSessionCreated")))
     {
         session.Execute(() =>
         {
             Assert.Equal("TestThread", Thread.CurrentThread.Name);
         });
     }
 }
        public void DoWithTypePerformsTask()
        {
            using (var session = new DBreezeSingleThreadSession("TestThread", AssureEmptyDir("TestData/DBreezeSingleThreadSession/DoWithTypePerformsTask")))
            {
                var task = session.Execute <string>(() =>
                {
                    return("TaskResult");
                });
                task.Wait();

                Assert.Equal("TaskResult", task.Result);
            }
        }
        public void DoWithTypeRunsSameThreadAsSessionCreated()
        {
            using (var session = new DBreezeSingleThreadSession("TestThread", AssureEmptyDir("TestData/DBreezeSingleThreadSession/DoWithTypeRunsSameThreadAsSessionCreated")))
            {
                var thread = session.Execute <string>(() =>
                {
                    return(Thread.CurrentThread.Name);
                });
                thread.Wait();

                Assert.Equal("TestThread", thread.Result);
            }
        }
        public void DoAbleToAccessExistingTransactionData()
        {
            var dir = AssureEmptyDir("TestData/DBreezeSingleThreadSession/DoAbleToAccessExistingTransactionData");

            uint256[] data = SetupTransactionData(dir);

            using (var session = new DBreezeSingleThreadSession("TestThread", dir))
            {
                session.Execute(() =>
                {
                    var data2       = new uint256[data.Length];
                    var transaction = session.Transaction;
                    int i           = 0;
                    foreach (var row in transaction.SelectForward <byte[], byte[]>("Table"))
                    {
                        data2[i++] = new uint256(row.Key, false);
                    }

                    Assert.True(data.SequenceEqual(data2));
                });
            }
        }