Ejemplo n.º 1
0
        public void TestTwoBlocks()
        {
            using (var xMemStream = new MemoryStream())
            {
                xMemStream.SetLength(2048);
                // 4 blocks of 512 bytes
                using (var xRawBlockStore = new SimpleStreamBlockStore(xMemStream, 512))
                {
                    ODBFSImpl.Format(xRawBlockStore, 512);
                    using (var xOdbfs = new ODBFSImpl(xRawBlockStore))
                    {
                        Assert.AreEqual(0, xOdbfs.GetVirtualBlocks().Count());
                        var xBlock1Id = Guid.NewGuid();
                        var xBlock2Id = Guid.NewGuid();
                        xOdbfs.CreateNewBlock(xBlock1Id, 1);
                        xOdbfs.CreateNewBlock(xBlock2Id, 1);
                        var xBuff1 = new byte[512];
                        var xBuff1Seg = new ArraySegment<byte>(xBuff1);
                        var xBuff2 = new byte[512];
                        var xBuff2Seg = new ArraySegment<byte>(xBuff2);
                        using (var xBlock1 = xOdbfs.OpenBlock(xBlock1Id))
                        {
                            for (int i = 0; i < xBuff1.Length; i++)
                            {
                                xBuff1[i] = 0xAA;
                            }
                            xBlock1.Store(0, xBuff1Seg);
                        }
                        using (var xBlock2 = xOdbfs.OpenBlock(xBlock2Id))
                        {
                            for (int i = 0; i < xBuff1.Length; i++)
                            {
                                xBuff1[i] = 0xBB;
                            }
                            xBlock2.Store(0, xBuff1Seg);
                        }

                        for (int i = 0; i < xBuff1.Length; i++)
                        {
                            xBuff1[i] = 0xAA;
                        }
                        xRawBlockStore.Retrieve(1, xBuff2Seg);
                        Assert.IsTrue(DeduplicatingBlockStore.CompareBlocks(xBuff1, xBuff2, 0, 0, 512));
                        for (int i = 0; i < xBuff1.Length; i++)
                        {
                            xBuff1[i] = 0xBB;
                        }
                        xRawBlockStore.Retrieve(2, xBuff2Seg);
                        Assert.IsTrue(DeduplicatingBlockStore.CompareBlocks(xBuff1, xBuff2, 0, 0, 512));
                        xBuff1 = new byte[512];
                        xRawBlockStore.Retrieve(3, xBuff2Seg);
                        Assert.IsTrue(DeduplicatingBlockStore.CompareBlocks(xBuff1, xBuff2, 0, 0, 512));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public VBlockContentStore(ODBFSImpl odbfs, Guid identifier)
 {
     if (odbfs == null)
     {
         throw new ArgumentNullException("odbfs");
     }
     _odbfs = odbfs;
     _identifier = identifier;
     using(_odbfs._openBlocksLock.EnterWriteLock())
     {
         List<VBlockContentStore> xOpenBlocks;
         if(!_odbfs._openBlocks.TryGetValue(identifier, out xOpenBlocks))
         {
             throw new Exception("Block not found!");
         }
         xOpenBlocks.Add(this);
     }
 }