public void TestReopenAfterReadWriteStoreModifiedException()
        {
            ulong pageId;
            var buffer1 = new byte[] {1, 1, 1, 1};
            var buffer2 = new byte[] {2, 2, 2, 2};
            var buffer3 = new byte[] {3, 3, 3, 3};

            using (
                var pageStore = TestUtils.CreateEmptyPageStore("TestStoreModifiedExceptionThrown.data",
                                                               PersistenceType.Rewrite))
            {
                var page = pageStore.Create(1);
                pageId = page.Id;
                page.SetData(buffer1, 0, 0, 4);
                pageStore.Commit(1, null);
            }

            var readStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                    "TestStoreModifiedExceptionThrown.data",
                                                    BPlusTreeStoreManager.PageSize, true, 1);
            try
            {
                var page = readStore.Retrieve(1, null);
                Assert.AreEqual(1, page.Data[0]);

                using (
                    var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                             "TestStoreModifiedExceptionThrown.data",
                                                             BPlusTreeStoreManager.PageSize, true, 1))
                {
                    var writePage = writeStore.Retrieve(pageId, null);
                    writePage = writeStore.GetWriteablePage(2, writePage);
                    writePage.SetData(buffer2, 0, 0, 4);
                    writeStore.Commit(2, null);
                }

                page = readStore.Retrieve(1, null);
                Assert.AreEqual(1, page.Data[0]);

                using (
                    var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                             "TestStoreModifiedExceptionThrown.data",
                                                             BPlusTreeStoreManager.PageSize, true, 2))
                {
                    var writePage = writeStore.Retrieve(pageId, null);
                    writePage = writeStore.GetWriteablePage(3, writePage);
                    writePage.SetData(buffer3, 0, 0, 4);
                    writeStore.Commit(3, null);
                }

                try
                {
                    readStore.Retrieve(pageId, null);
                    Assert.Fail("Expected ReadWriteStoreModifiedException to be thrown");
                }
                catch (ReadWriteStoreModifiedException)
                {
                    readStore.Close();
                    readStore.Dispose();
                    readStore = null;
                    readStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                        "TestStoreModifiedExceptionThrown.data",
                                                        BPlusTreeStoreManager.PageSize, true, 3);
                    page = readStore.Retrieve(pageId, null);
                    Assert.AreEqual(3, page.Data[0]);
                }
            }
            finally
            {
                if (readStore != null)
                {
                    readStore.Dispose();
                }
            }
        }
        public void CreateSnapshot(string srcStoreLocation, string destStoreLocation,
                                   PersistenceType storePersistenceType, ulong commitPointId = StoreConstants.NullUlong)
        {
            Logging.LogInfo("Snapshot store {0} to new store {1} with persistence type {2}", srcStoreLocation,
                            destStoreLocation, storePersistenceType);
            if (_persistenceManager.DirectoryExists(destStoreLocation))
            {
                throw new StoreManagerException(destStoreLocation, "Store already exists");
            }

            // Open the source store for reading
            using (IStore srcStore = commitPointId == StoreConstants.NullUlong
                                         ? OpenStore(srcStoreLocation, true)
                                         : OpenStore(srcStoreLocation, commitPointId))
            {

                // Create the directory for the destination store
                _persistenceManager.CreateDirectory(destStoreLocation);

                // Create empty data file
                var dataFilePath = Path.Combine(destStoreLocation, DataFileName);
                _persistenceManager.CreateFile(dataFilePath);

                // Create initial master file
                var destStoreConfiguration = _storeConfiguration.Clone() as StoreConfiguration;
                destStoreConfiguration.PersistenceType = storePersistenceType;
                var destMasterFile = MasterFile.Create(_persistenceManager, destStoreLocation, destStoreConfiguration,
                                                       Guid.NewGuid());

                // Copy resource files from source store
                var resourceFilePath = Path.Combine(destStoreLocation, ResourceFileName);
                _persistenceManager.CopyFile(Path.Combine(srcStoreLocation, ResourceFileName), resourceFilePath, true);

                // Initialize data page store
                IPageStore destPageStore = null;
                switch (storePersistenceType)
                {
                    case PersistenceType.AppendOnly:
                        destPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, false,
                                                                    _storeConfiguration.DisableBackgroundWrites);
                        break;
                    case PersistenceType.Rewrite:
                        destPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, false, 0, 1, _storeConfiguration.DisableBackgroundWrites);
                        break;
                    default:
                        throw new BrightstarInternalException("Unrecognized target store type: " + storePersistenceType);
                }
                
                // Copy Data
                ulong destStorePageId = srcStore.CopyTo(destPageStore, 1ul);

                destPageStore.Close();

                destMasterFile.AppendCommitPoint(
                    new CommitPoint(destStorePageId, 1ul, DateTime.UtcNow, Guid.Empty), true);
            }
        }