Exemplo n.º 1
0
        public void TestCreateStore()
        {
            Configuration.ResourceCacheLimit = 10000;
            Configuration.PageCacheSize      = 4;

            var client    = GetEmbeddedClient();
            var storeName = "TestCreateStore_" + _runId;
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName);


            Assert.IsTrue(client.DoesStoreExist(storeName));
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsTrue(_pm.DirectoryExists(storePath));
            Assert.IsTrue(_pm.FileExists(dataPath));

            client.DeleteStore(storeName);

            Task.Delay(50).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsFalse(_pm.DirectoryExists(storePath));
            Assert.IsFalse(_pm.FileExists(dataPath));
            Assert.IsFalse(client.DoesStoreExist(storeName));
        }
        public IStore CreateStore(string storeLocation, PersistenceType storePersistenceType, bool readOnly, bool withTransactionLogging)
        {
            Logging.LogInfo("Create Store {0} with persistence type {1}", storeLocation, storePersistenceType);
            if (_persistenceManager.DirectoryExists(storeLocation))
            {
                throw new StoreManagerException(storeLocation, "Store already exists");
            }

            _persistenceManager.CreateDirectory(storeLocation);

            var dataFilePath = Path.Combine(storeLocation, DataFileName);

            _persistenceManager.CreateFile(dataFilePath);

            var resourceFilePath = Path.Combine(storeLocation, ResourceFileName);

            _persistenceManager.CreateFile(resourceFilePath);

            var targetStoreConfiguration = _storeConfiguration.Clone() as StoreConfiguration;

            targetStoreConfiguration.PersistenceType = storePersistenceType;
            MasterFile.Create(_persistenceManager, storeLocation, targetStoreConfiguration, Guid.NewGuid());
            IPageStore dataPageStore = null;

            switch (storePersistenceType)
            {
            case PersistenceType.AppendOnly:
                dataPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
                break;

            case PersistenceType.Rewrite:
                dataPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, false, 0, 1, _storeConfiguration.DisableBackgroundWrites);
                break;
            }

            IPageStore resourcePageStore = new AppendOnlyFilePageStore(_persistenceManager, resourceFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
            var        resourceTable     = new ResourceTable(resourcePageStore);

            using (var store = new Store(storeLocation, dataPageStore, resourceTable))
            {
                store.Commit(Guid.Empty);
                store.Close();
            }

            if (withTransactionLogging)
            {
                _persistenceManager.CreateFile(Path.Combine(storeLocation, "transactionheaders.bs"));
                _persistenceManager.CreateFile(Path.Combine(storeLocation, "transactions.bs"));
            }

            Logging.LogInfo("Store created at {0}", storeLocation);
            return(OpenStore(storeLocation, readOnly));
        }
 public void TestCreateDirectory()
 {
     if (_pm.DirectoryExists("newdir"))
     {
         _pm.DeleteDirectory("newdir");
     }
     Assert.IsFalse(_pm.DirectoryExists("newdir"));
     _pm.CreateDirectory("newdir");
     Assert.IsTrue(_pm.DirectoryExists("newdir"));
 }
Exemplo n.º 4
0
        private void CopyTestDataToImportFolder(string testDataFileName, string targetFileName = null)
        {
#if PORTABLE
            using (var srcStream = _persistenceManager.GetInputStream(Configuration.DataLocation + testDataFileName))
            {
                var targetDir  = Path.Combine(Configuration.StoreLocation, "import");
                var targetPath = Path.Combine(targetDir, (targetFileName ?? testDataFileName));
                if (!_persistenceManager.DirectoryExists(targetDir))
                {
                    _persistenceManager.CreateDirectory(targetDir);
                }
                if (_persistenceManager.FileExists(targetPath))
                {
                    _persistenceManager.DeleteFile(targetPath);
                }
                using (var targetStream = _persistenceManager.GetOutputStream(targetPath, FileMode.CreateNew))
                {
                    srcStream.CopyTo(targetStream);
                }
            }
#else
            var importFile = new FileInfo(Path.Combine(Configuration.DataLocation, testDataFileName));
            var targetDir  = new DirectoryInfo(Path.Combine(Configuration.StoreLocation, "import"));
            if (!targetDir.Exists)
            {
                targetDir.Create();
            }
            importFile.CopyTo(Path.Combine(targetDir.FullName, targetFileName ?? testDataFileName), true);
#endif
        }
Exemplo n.º 5
0
 private void EnsureEmptyDirectory(IPersistenceManager pm, string dirName)
 {
     if (pm.DirectoryExists(dirName))
     {
         pm.DeleteDirectory(dirName);
     }
     Thread.Sleep(10);
     pm.CreateDirectory(dirName);
 }
        public IStore CreateStore(string storeLocation, bool readOnly = false)
        {
            Logging.LogInfo("Create Store {0}", storeLocation);
            if (_persistenceManager.DirectoryExists(storeLocation))
            {
                throw new StoreManagerException(storeLocation, "Store already exists");
            }

            _persistenceManager.CreateDirectory(storeLocation);

            var dataFilePath = Path.Combine(storeLocation, DataFileName);

            _persistenceManager.CreateFile(dataFilePath);

            var store = new Store(storeLocation, readOnly);

            store.Commit(Guid.Empty);

            Logging.LogInfo("Store created at {0}", storeLocation);
            return(store);
        }
Exemplo n.º 7
0
        public void TestCreateStore(PersistenceType persistenceType)
        {
            var client    = GetEmbeddedClient();
            var storeName = MakeStoreName("TestCreateStore", persistenceType);
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName, persistenceType);


            Assert.IsTrue(client.DoesStoreExist(storeName));
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsTrue(_pm.DirectoryExists(storePath));
            Assert.IsTrue(_pm.FileExists(dataPath));

            client.DeleteStore(storeName);

            Task.Delay(1000).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsFalse(_pm.FileExists(dataPath), "Expected data file to be deleted, but it was still found at {0}", dataPath);
            Assert.IsFalse(_pm.DirectoryExists(storePath), "Expected store directory to be deleted, but it was still found at {0}", storePath);
            Assert.IsFalse(client.DoesStoreExist(storeName), "Expected client to report that store not longer exists after deletion");
        }
Exemplo n.º 8
0
        public void TestCreateAndDeleteStore()
        {
            var client    = GetEmbeddedClient();
            var storeName = "TestCreateStore_" + _runId;
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName);


            Assert.IsTrue(client.DoesStoreExist(storeName), "Expected True from DoesStoreExist after store created.");
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation), "Expected stores directory at {0}", TestConfiguration.StoreLocation);
            Assert.IsTrue(_pm.DirectoryExists(storePath), "Expected store directory at {0}", storePath);
            Assert.IsTrue(_pm.FileExists(dataPath), "Expected B* data file at {0}", dataPath);

            client.DeleteStore(storeName);

            Task.Delay(50).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation), "Expected stores directory at {0} after store deleted.", TestConfiguration.StoreLocation);
            Assert.IsFalse(_pm.FileExists(dataPath), "Expected data file to be deleted from {0}.", dataPath);
            Assert.IsFalse(_pm.DirectoryExists(storePath), "Expected store directory to be deleted from {0}.", storePath);
            Assert.IsFalse(client.DoesStoreExist(storeName), "Expected False from DoesStoreExist after store deleted.");
        }
Exemplo n.º 9
0
        public void TestCreateAndDeleteDirectory()
        {
            string dirName = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "CreateDirectory_" + DateTime.Now.Ticks);

            Assert.False(_pm.DirectoryExists(dirName), "Directory exists before it is created");
            _pm.CreateDirectory(dirName);
            Assert.True(_pm.DirectoryExists(dirName), "Directory does not exist after creation");
            _pm.DeleteDirectory(dirName);
            Assert.False(_pm.DirectoryExists(dirName), "Directory exists after deletion");
        }
Exemplo n.º 10
0
        public void TestCreateAndDeleteDirectory()
        {
            string dirName = Path.Combine(TestConfiguration.StoreLocation, "CreateDirectory_" + DateTime.Now.Ticks);

            Assert.False(_pm.DirectoryExists(dirName), "Directory exists before it is created");
            _pm.CreateDirectory(dirName);
            Assert.True(_pm.DirectoryExists(dirName), "Directory does not exist after creation");
            _pm.DeleteDirectory(dirName);
            Assert.False(_pm.DirectoryExists(dirName), "Directory exists after deletion");
        }
Exemplo n.º 11
0
 private void EnsureEmptyDirectory(IPersistenceManager pm, string dirName)
 {
     if (pm.DirectoryExists(dirName))
     {
         pm.DeleteDirectory(dirName);
     }
     Thread.Sleep(10);
     pm.CreateDirectory(dirName);
 }