Пример #1
0
        public void GlobalSetup()
        {
            _useExportProviderAttribute.Before(null);

            if (_workspace != null)
            {
                throw new InvalidOperationException();
            }

            _workspace = TestWorkspace.Create(
                @"<Workspace>
    <Project Language=""NoCompilation"" CommonReferences=""false"">
        <Document>
            // a no-compilation document
        </Document>
    </Project>
</Workspace>"
                );

            // Explicitly choose the sqlite db to test.
            _workspace.TryApplyChanges(
                _workspace.CurrentSolution.WithOptions(
                    _workspace.Options.WithChangedOption(
                        StorageOptions.Database,
                        StorageDatabase.SQLite
                        )
                    )
                );

            var connectionPoolService =
                _workspace.ExportProvider.GetExportedValue <SQLiteConnectionPoolService>();

            _storageService = new SQLitePersistentStorageService(
                connectionPoolService,
                new LocationService()
                );

            var solution = _workspace.CurrentSolution;

            _storage = _storageService
                       .GetStorageWorkerAsync(
                _workspace,
                SolutionKey.ToSolutionKey(solution),
                solution,
                CancellationToken.None
                )
                       .AsTask()
                       .GetAwaiter()
                       .GetResult();
            if (_storage == NoOpPersistentStorage.Instance)
            {
                throw new InvalidOperationException(
                          "We didn't properly get the sqlite storage instance."
                          );
            }

            Console.WriteLine("Storage type: " + _storage.GetType());
            _document = _workspace.CurrentSolution.Projects.Single().Documents.Single();
            _random   = new Random(0);
        }
Пример #2
0
        private bool TryCreatePersistentStorage(
            Solution solution,
            string workingFolderPath,
            out IChecksummedPersistentStorage persistentStorage)
        {
            persistentStorage = null;

            var databaseFilePath = GetDatabaseFilePath(workingFolderPath);

            try
            {
                if (!TryOpenDatabase(solution, workingFolderPath, databaseFilePath, out persistentStorage))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                StorageDatabaseLogger.LogException(ex);

                if (ShouldDeleteDatabase(ex))
                {
                    // this was not a normal exception that we expected during DB open.
                    // Report this so we can try to address whatever is causing this.
                    FatalError.ReportWithoutCrash(ex);
                    IOUtilities.PerformIO(() => Directory.Delete(Path.GetDirectoryName(databaseFilePath), recursive: true));
                }

                return(false);
            }
        }
        public void GlobalSetup()
        {
            _useExportProviderAttribute.Before(null);

            if (_workspace != null)
            {
                throw new InvalidOperationException();
            }

            _workspace = TestWorkspace.Create(
                @"<Workspace>
    <Project Language=""NoCompilation"" CommonReferences=""false"">
        <Document>
            // a no-compilation document
        </Document>
    </Project>
</Workspace>");

            var connectionPoolService = _workspace.ExportProvider.GetExportedValue <SQLiteConnectionPoolService>();
            var asyncListener         = _workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>().GetListener(FeatureAttribute.PersistentStorage);

            _storageService = new SQLitePersistentStorageService(connectionPoolService, new StorageConfiguration(), asyncListener);

            var solution = _workspace.CurrentSolution;

            _storage = _storageService.GetStorageWorkerAsync(SolutionKey.ToSolutionKey(solution), CancellationToken.None).AsTask().GetAwaiter().GetResult();

            Console.WriteLine("Storage type: " + _storage.GetType());
            _document = _workspace.CurrentSolution.Projects.Single().Documents.Single();
            _random   = new Random(0);
        }
Пример #4
0
 public SQLitePersistentStorageBenchmarks()
 {
     _document       = null !;
     _storage        = null !;
     _storageService = null !;
     _workspace      = null !;
     _random         = null !;
 }
        public void GlobalCleanup()
        {
            if (_workspace == null)
            {
                throw new InvalidOperationException();
            }

            _document = null;
            _storage.Dispose();
            _storage        = null;
            _storageService = null;
            _workspace.Dispose();
            _workspace = null;

            _useExportProviderAttribute.After(null);
        }
        protected override bool TryOpenDatabase(
            Solution solution, string workingFolderPath, string databaseFilePath, out IChecksummedPersistentStorage storage)
        {
            if (!TryInitializeLibraries())
            {
                // SQLite is not supported on the current platform
                storage = null;
                return(false);
            }

            // try to get db ownership lock. if someone else already has the lock. it will throw
            var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath);

            if (dbOwnershipLock == null)
            {
                storage = null;
                return(false);
            }

            SQLitePersistentStorage sqlStorage = null;

            try
            {
                sqlStorage = new SQLitePersistentStorage(
                    workingFolderPath, solution.FilePath, databaseFilePath, dbOwnershipLock, _faultInjectorOpt);

                sqlStorage.Initialize(solution);
            }
            catch (Exception)
            {
                if (sqlStorage != null)
                {
                    // Dispose of the storage, releasing the ownership lock.
                    sqlStorage.Dispose();
                }
                else
                {
                    // The storage was not created so nothing owns the lock.
                    // Dispose the lock to allow reuse.
                    dbOwnershipLock.Dispose();
                }
                throw;
            }

            storage = sqlStorage;
            return(true);
        }
Пример #7
0
        public void GlobalSetup()
        {
            _useExportProviderAttribute.Before(null);

            if (_workspace != null)
            {
                throw new InvalidOperationException();
            }

            _workspace = TestWorkspace.Create(
                @"<Workspace>
    <Project Language=""NoCompilation"" CommonReferences=""false"">
        <Document>
            // a no-compilation document
        </Document>
    </Project>
</Workspace>");

            // Ensure we always use the storage service, no matter what the size of the solution.
            _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(
                                           _workspace.CurrentSolution.Options.WithChangedOption(StorageOptions.SolutionSizeThreshold, -1)));

            _storageService = new SQLitePersistentStorageService(
                _workspace.Services.GetService <IOptionService>(),
                new LocationService(),
                new SolutionSizeTracker());

            _storage = _storageService.GetStorageWorker(_workspace.CurrentSolution);
            if (_storage == NoOpPersistentStorage.Instance)
            {
                throw new InvalidOperationException("We didn't properly get the sqlite storage instance.");
            }

            Console.WriteLine("Storage type: " + _storage.GetType());
            _document = _workspace.CurrentSolution.Projects.Single().Documents.Single();
            _random   = new Random(0);
        }
Пример #8
0
 protected abstract bool TryOpenDatabase(Solution solution, string workingFolderPath, string databaseFilePath, out IChecksummedPersistentStorage storage);