Esempio n. 1
0
        public void TryAllocate()
        {
            PermutationSetup permutation = new PermutationSetup();

            permutation.Add(count16queue0);
            permutation.Add(count16queue16);

            foreach (Scenario scenario in permutation.Scenarios)
            {
                using (Run run = scenario.Run().Initialize())
                {
                    IBlockPool pool = run.Parameters["Pool"] as BlockPool;
                    byte[]     data = null;
                    for (int i = 0; i < 16; i++)
                    {
                        Assert.IsTrue(pool.TryAllocate(out data));
                        Assert.AreEqual(4096, data.Length);
                    }
                    byte[] data2;
                    Assert.IsFalse(pool.TryAllocate(out data2));
                    pool.Return(data);
                    Assert.IsTrue(pool.TryAllocate(out data));
                }
            }
        }
Esempio n. 2
0
        public void Allocate()
        {
            PermutationSetup permutation = new PermutationSetup();

            permutation.Add(count16queue0);
            permutation.Add(count16queue16);

            foreach (Scenario scenario in permutation.Scenarios)
            {
                using (Run run = scenario.Run().Initialize())
                {
                    IBlockPool pool = run.Parameters["Pool"] as BlockPool;
                    byte[]     data = null;
                    for (int i = 0; i < 16; i++)
                    {
                        data = pool.Allocate();
                        Assert.IsTrue(data != null);
                        Assert.AreEqual(4096, data.Length);
                    }
                    Semaphore s = new Semaphore(0, 256);
                    Task.Run(() =>
                    {
                        pool.Allocate();
                        s.Release();
                    });

                    Assert.IsFalse(s.WaitOne(500));
                    pool.Return(data);
                    Assert.IsTrue(s.WaitOne(500));
                }
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="serverContext">Server context</param>
 /// <param name="blockchain">Blockchain</param>
 /// <param name="blockRepository">The Block Model.</param>
 /// <param name="transactionModel"></param>
 /// <param name="assetModel"></param>
 /// <param name="blockchainContext">The block chain context class.</param>
 /// <param name="blockPool">Block pool</param>
 /// <param name="blockSigner">Block signer</param>
 /// <param name="blockPersister">Block persister</param>
 /// <param name="transactionPool">Transaction Pool</param>
 /// <param name="consoleHandler">Console handler</param>
 public PromptBlockchainController(
     IServerContext serverContext,
     IBlockchain blockchain,
     IBlockRepository blockRepository,
     ITransactionRepository transactionModel,
     IAssetRepository assetModel,
     IBlockchainContext blockchainContext,
     IBlockPool blockPool,
     IBlockPersister blockPersister,
     ISigner <Block> blockSigner,
     ITransactionPool transactionPool,
     IConsoleHandler consoleHandler)
 {
     _serverContext     = serverContext;
     _blockchain        = blockchain;
     _blockRepository   = blockRepository;
     _blockSigner       = blockSigner;
     _blockPersister    = blockPersister;
     _transactionModel  = transactionModel;
     _assetModel        = assetModel;
     _blockchainContext = blockchainContext;
     _blockPool         = blockPool;
     _transactionPool   = transactionPool;
     _consoleHandler    = consoleHandler;
 }
 /// <summary>Create session</summary>
 public OperationSession(OperationPolicy policy = OperationPolicy.Default, IBlockPool blockPool = default, CancellationTokenSource cancelSrc = default, IOption option = default)
 {
     this.Policy    = policy;
     this.BlockPool = blockPool ?? new BlockPool();
     this.CancelSrc = cancelSrc ?? new CancellationTokenSource();
     this.Option    = option;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="blockchain">Blockchain</param>
 /// <param name="blockPool">Block pool</param>
 /// <param name="consoleWriter">Console writter</param>
 /// <param name="consoleReader">Console reader</param>
 public PromptBlockchainController(IBlockchain blockchain, IBlockPool blockPool, IConsoleWriter consoleWriter, IConsoleReader consoleReader)
 {
     _blockPool     = blockPool;
     _blockchain    = blockchain;
     _consoleReader = consoleReader;
     _consoleWriter = consoleWriter;
 }
Esempio n. 6
0
 /// <summary>
 /// Create memory based file.
 /// </summary>
 /// <param name="blockSize"></param>
 public MemoryFile(int blockSize)
 {
     if (blockSize < 16)
     {
         throw new ArgumentOutOfRangeException(nameof(blockSize));
     }
     this.BlockSize = blockSize;
     this.blockPool = new BlockPoolPseudo(blockSize);
 }
Esempio n. 7
0
 public BlockProcessor(
     IBlockPool blockPool,
     IRepository repository,
     IAsyncDelayer asyncDelayer,
     IProcessor <Transaction> transactionProcessor)
 {
     _blockPool            = blockPool ?? throw new ArgumentNullException(nameof(blockPool));
     _repository           = repository ?? throw new ArgumentNullException(nameof(repository));
     _asyncDelayer         = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
     _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
 }
Esempio n. 8
0
 /// <summary>
 /// Create memory based file.
 /// </summary>
 public MemoryFile()
 {
     this.BlockSize = 1024;
     this.blockPool = new BlockPoolPseudo((int)BlockSize);
 }
Esempio n. 9
0
 /// <summary>
 /// Create memory based file.
 /// </summary>
 /// <param name="blockPool"></param>
 /// <param name="pathHint">Path to use in ToString()</param>
 public MemoryFile(IBlockPool blockPool, string pathHint = null)
 {
     this.blockPool = blockPool ?? throw new ArgumentNullException(nameof(blockPool));
     this.BlockSize = blockPool.BlockSize;
     this.Path      = pathHint;
 }
Esempio n. 10
0
 /// <summary>
 /// Create memory based file.
 /// </summary>
 /// <param name="blockPool"></param>
 public MemoryFile(IBlockPool blockPool)
 {
     this.blockPool = blockPool ?? throw new ArgumentNullException(nameof(blockPool));
     this.BlockSize = blockPool.BlockSize;
 }
Esempio n. 11
0
        public void Quota()
        {
            // Arrange
            PermutationSetup permutation = new PermutationSetup();

            permutation.Add(blockpool_3KB);

            permutation.Add(case_ms);
            permutation.Add(case_decor_ms);
            permutation.Add(case_vfs_ms);
            permutation.Add(case_vfs_2ms);


            // Act & Assert
            foreach (Scenario scenario in permutation.Scenarios)
            {
                using (Run run = scenario.Run().Initialize())
                {
                    IFileSystemDisposable fs   = run.Parameters["Class"] as IFileSystemDisposable;
                    IBlockPool            pool = run.Parameters["BlockPool"] as IBlockPool;
                    fs.CreateDirectory("dir/");

                    using (var s = fs.Open("dir/file", FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        Assert.AreEqual(0L, pool.BytesAllocated);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(1024L, pool.BytesAllocated);
                        Assert.AreEqual(2048L, pool.BytesAvailable);
                        Assert.AreEqual(1024L, s.Length);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(2048L, pool.BytesAllocated);
                        Assert.AreEqual(1024L, pool.BytesAvailable);
                        Assert.AreEqual(2048L, s.Length);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(3072L, s.Length);
                        Assert.AreEqual(3072L, pool.BytesAllocated);
                        Assert.AreEqual(0L, pool.BytesAvailable);

                        try
                        {
                            s.Write(new byte[1024]);
                            Assert.Fail();
                        }
                        catch (FileSystemExceptionOutOfDiskSpace)
                        {
                        }
                        Assert.AreEqual(3072, s.Length);

                        try
                        {
                            s.WriteByte(3);
                            Assert.Fail();
                        }
                        catch (FileSystemExceptionOutOfDiskSpace)
                        {
                        }
                        Assert.AreEqual(3072, s.Length);

                        s.SetLength(3071);
                        Assert.AreEqual(3071, s.Length);

                        s.WriteByte(3);
                        Assert.AreEqual(3072, s.Length);

                        s.SetLength(0L);
                        Assert.AreEqual(0, s.Length);
                        Assert.AreEqual(0L, pool.BytesAllocated);
                        Assert.AreEqual(3072L, pool.BytesAvailable);

                        s.Write(new byte[1024]);
                        s.Write(new byte[1024]);
                        s.Write(new byte[1024]);
                        Assert.AreEqual(3072L, s.Length);
                        Assert.AreEqual(3072L, pool.BytesAllocated);
                        Assert.AreEqual(0L, pool.BytesAvailable);
                    }

                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    fs.Delete("dir/", true);
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);


                    fs.CreateFile("newfile", new byte[3072]);
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    Stream ss = fs.Open("newfile", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                    fs.Delete("newfile");
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    ss.Dispose();
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);

                    fs.CreateFile("newfile", new byte[3072]);
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    fs.Dispose();
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);
                }
            }
        }