示例#1
0
        public void DeltaLogTest1([Values] TestUtils.DeviceType deviceType)
        {
            const int TotalCount = 200;
            string    filename   = $"{path}delta_{deviceType}.log";

            TestUtils.RecreateDirectory(path);

            device = TestUtils.CreateTestDevice(deviceType, filename);
            device.Initialize(-1);
            using DeltaLog deltaLog = new DeltaLog(device, 12, 0);
            Random r = new (20);
            int    i;

            SectorAlignedBufferPool bufferPool = new(1, (int)device.SectorSize);

            deltaLog.InitializeForWrites(bufferPool);
            for (i = 0; i < TotalCount; i++)
            {
                int  _len = 1 + r.Next(254);
                long address;
                while (true)
                {
                    deltaLog.Allocate(out int maxLen, out address);
                    if (_len <= maxLen)
                    {
                        break;
                    }
                    deltaLog.Seal(0);
                }
                for (int j = 0; j < _len; j++)
                {
                    unsafe { *(byte *)(address + j) = (byte)_len; }
                }
                deltaLog.Seal(_len, i % 2 == 0 ? DeltaLogEntryType.DELTA : DeltaLogEntryType.CHECKPOINT_METADATA);
            }
            deltaLog.FlushAsync().Wait();

            deltaLog.InitializeForReads();
            r = new (20);
            for (i = 0; deltaLog.GetNext(out long address, out int len, out var type); i++)
            {
                int _len = 1 + r.Next(254);
                Assert.AreEqual(i % 2 == 0 ? DeltaLogEntryType.DELTA : DeltaLogEntryType.CHECKPOINT_METADATA, type);
                Assert.AreEqual(len, _len);
                for (int j = 0; j < len; j++)
                {
                    unsafe { Assert.AreEqual((byte)_len, *(byte *)(address + j)); };
                }
            }
            Assert.AreEqual(TotalCount, i, $"i={i} and TotalCount={TotalCount}");
            bufferPool.Free();
        }
示例#2
0
        public void DeltaLogTest1()
        {
            int           TotalCount = 1000;
            string        path       = TestContext.CurrentContext.TestDirectory + "/" + TestContext.CurrentContext.Test.Name + "/";
            DirectoryInfo di         = Directory.CreateDirectory(path);

            using (IDevice device = Devices.CreateLogDevice(path + TestContext.CurrentContext.Test.Name + "/delta.log", deleteOnClose: false))
            {
                device.Initialize(-1);
                using DeltaLog deltaLog = new DeltaLog(device, 12, 0);
                Random r = new Random(20);
                int    i;

                var bufferPool = new SectorAlignedBufferPool(1, (int)device.SectorSize);
                deltaLog.InitializeForWrites(bufferPool);
                for (i = 0; i < TotalCount; i++)
                {
                    int  len = 1 + r.Next(254);
                    long address;
                    while (true)
                    {
                        deltaLog.Allocate(out int maxLen, out address);
                        if (len <= maxLen)
                        {
                            break;
                        }
                        deltaLog.Seal(0);
                    }
                    for (int j = 0; j < len; j++)
                    {
                        unsafe { *(byte *)(address + j) = (byte)len; }
                    }
                    deltaLog.Seal(len, i);
                }
                deltaLog.FlushAsync().Wait();

                deltaLog.InitializeForReads();
                i = 0;
                r = new Random(20);
                while (deltaLog.GetNext(out long address, out int len, out int type))
                {
                    int _len = 1 + r.Next(254);
                    Assert.IsTrue(type == i);
                    Assert.IsTrue(_len == len);
                    for (int j = 0; j < len; j++)
                    {
                        unsafe { Assert.IsTrue(*(byte *)(address + j) == (byte)_len); };
                    }
                    i++;
                }
                Assert.IsTrue(i == TotalCount);
                bufferPool.Free();
            }
            while (true)
            {
                try
                {
                    di.Delete(recursive: true);
                    break;
                }
                catch { }
            }
        }