Пример #1
0
        private void tidyTest()
        {
            SqlConnection.ClearAllPools();

            if (m_ErrorIndex != null)
            {
                m_ErrorIndex.Deactivate();
                try { m_ErrorIndex.DeleteIndex(); }
                catch {; }
                m_ErrorIndex.Dispose();
                SqlConnection.ClearAllPools();
                m_ErrorIndex = null;
            }

            String sourceDatabaseName = "MoveIndexTestDatabase1";
            String destDatabaseName   = "MoveIndexTestDatabase2";

            DbProviderFactory providerFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");

            SqlCommands sqlCommands = new SqlCommands(providerFactory, s_MasterConnectionString, s_MasterConnectionString, 1);

            // Delete any remnants that may exist from a previous test.
            SqlConnection.ClearAllPools();
            try { sqlCommands.DeleteDatabase(sourceDatabaseName); }
            catch (System.Exception ex) { Console.WriteLine("Failed to delete: " + sourceDatabaseName + " " + ex.ToString()); };

            SqlConnection.ClearAllPools();
            try { sqlCommands.DeleteDatabase(destDatabaseName); }
            catch (System.Exception ex) { Console.WriteLine("Failed to delete: " + destDatabaseName + " " + ex.ToString()); };

            sqlCommands.Dispose();

            SqlConnection.ClearAllPools();

            if (Directory.Exists(m_TestFolder))
            {
                PathUtils.DeleteDirectory(m_TestFolder, true);
            }
            if (Directory.Exists(m_TestFolder2))
            {
                PathUtils.DeleteDirectory(m_TestFolder2, true);
            }
            if (Directory.Exists(m_TestFolder3))
            {
                PathUtils.DeleteDirectory(m_TestFolder3, true);
            }
        }
Пример #2
0
        public void CreateDatabaseUnicode()
        {
            DestroyDatabase();
            String connectionString = StackHashSqlConfiguration.DefaultMaster.ToConnectionString();

            SqlCommands commands = new SqlCommands(m_ProviderFactory, connectionString, connectionString, 1);


            commands.CreateDatabase(m_ErrorIndexPath, "\u125c" + SqlUtils.UnitTestDatabase + "\u125c", false);

            Assert.AreEqual(true, commands.DatabaseExists(SqlUtils.UnitTestDatabase));

            commands.DeleteDatabase(SqlUtils.UnitTestDatabase);
        }
Пример #3
0
        public void DestroyDatabase()
        {
            String connectionString = StackHashSqlConfiguration.DefaultMaster.ToConnectionString();

            SqlCommands commands = new SqlCommands(m_ProviderFactory, connectionString, connectionString, 1);

            String databaseName = s_UnitTestDatabase;

            if (!commands.DatabaseExists(databaseName))
            {
                bool stackHashDbaseExists = commands.CreateDatabase(m_ErrorIndexPath, databaseName, false);
                Assert.AreEqual(true, stackHashDbaseExists);
            }

            commands.DeleteDatabase(databaseName);

            Assert.AreEqual(false, commands.DatabaseExists(databaseName));
        }
Пример #4
0
        public void OpenCloseConnectionDatabaseExists()
        {
            String connectionString = StackHashSqlConfiguration.DefaultMaster.ToConnectionString();

            SqlCommands commands = new SqlCommands(m_ProviderFactory, connectionString, connectionString, 1);

            bool stackHashDbaseExists;

            if (!commands.DatabaseExists(SqlUtils.UnitTestDatabase))
            {
                stackHashDbaseExists = commands.CreateDatabase(m_ErrorIndexPath, SqlUtils.UnitTestDatabase, false);
                Assert.AreEqual(true, stackHashDbaseExists);
            }

            stackHashDbaseExists = commands.DatabaseExists(SqlUtils.UnitTestDatabase);
            Assert.AreEqual(true, stackHashDbaseExists);

            commands.DeleteDatabase(SqlUtils.UnitTestDatabase);
        }
Пример #5
0
        public void ChangeLogicalNamesDefaultLocation()
        {
            DestroyDatabase();
            String connectionString = StackHashSqlConfiguration.DefaultMaster.ToConnectionString();

            SqlCommands commands = new SqlCommands(m_ProviderFactory, connectionString, connectionString, 1);

            commands.CreateDatabase(m_ErrorIndexPath, SqlUtils.UnitTestDatabase, true); // Create in default location.

            Assert.AreEqual(true, commands.DatabaseExists(SqlUtils.UnitTestDatabase));

            Collection <String> logicalFileNames = commands.GetLogicalFileNames(SqlUtils.UnitTestDatabase);

            Assert.AreNotEqual(null, logicalFileNames);
            Assert.AreEqual(2, logicalFileNames.Count);

            String expectedDatLogicalFile = SqlUtils.UnitTestDatabase;
            String expectedLogLogicalFile = SqlUtils.UnitTestDatabase + "_log";

            Assert.AreEqual(0, String.Compare(expectedDatLogicalFile, logicalFileNames[0], StringComparison.OrdinalIgnoreCase));
            Assert.AreEqual(0, String.Compare(expectedLogLogicalFile, logicalFileNames[1], StringComparison.OrdinalIgnoreCase));

            // Now change the logical filenames.
            String newDatabaseName = "ChangeTest";

            Assert.AreEqual(true, commands.ChangeDatabaseLogicalNames(SqlUtils.UnitTestDatabase, newDatabaseName, false));

            logicalFileNames = commands.GetLogicalFileNames(SqlUtils.UnitTestDatabase);

            Assert.AreNotEqual(null, logicalFileNames);
            Assert.AreEqual(2, logicalFileNames.Count);

            expectedDatLogicalFile = newDatabaseName;
            expectedLogLogicalFile = newDatabaseName + "_log";

            Assert.AreEqual(0, String.Compare(expectedDatLogicalFile, logicalFileNames[0], StringComparison.OrdinalIgnoreCase));
            Assert.AreEqual(0, String.Compare(expectedLogLogicalFile, logicalFileNames[1], StringComparison.OrdinalIgnoreCase));



            commands.DeleteDatabase(SqlUtils.UnitTestDatabase);
        }
Пример #6
0
        /// <summary>
        /// Deletes the unit test database.
        /// </summary>
        /// <param name="providerFactory"></param>
        public static void DeleteTestDatabase(DbProviderFactory providerFactory)
        {
            SqlCommands commands = new SqlCommands(providerFactory, s_ConnectionString, s_MasterConnectionString, 1);

            commands.DeleteDatabase(s_UnitTestDatabase);
        }
Пример #7
0
        /// <summary>
        /// An index will be created in sourceFolder\SourceIndex called SourceIndex.
        /// It will then be moved to destFolder\DestIndex.
        /// If defaultDatabaseLocation is specified then only the cab files will be moved and not the SQL database.
        /// </summary>
        private void runMoveTask(String settingsFolder, String sourceErrorIndexFolder, String sourceErrorIndexName, String destErrorIndexFolder,
                                 String destErrorIndexName, bool defaultDatabaseLocation, StackHashTestIndexData testIndexData)
        {
            String scriptFolder = settingsFolder + "\\Scripts";


            SqlCommands sqlCommands = new SqlCommands(m_ProviderFactory, s_MasterConnectionString, s_MasterConnectionString, 1);

            // Create the source database folders and settings.

            if (sqlCommands.DatabaseExists(destErrorIndexName))
            {
                try { sqlCommands.DeleteDatabase(destErrorIndexName); }
                catch {; }
            }
            if (sqlCommands.DatabaseExists(sourceErrorIndexName))
            {
                try { sqlCommands.DeleteDatabase(sourceErrorIndexName); }
                catch {; }
            }

            if (Directory.Exists(settingsFolder))
            {
                PathUtils.DeleteDirectory(settingsFolder, true);
            }
            if (Directory.Exists(destErrorIndexFolder))
            {
                PathUtils.DeleteDirectory(destErrorIndexFolder, true);
            }
            if (Directory.Exists(sourceErrorIndexFolder))
            {
                PathUtils.DeleteDirectory(sourceErrorIndexFolder, true);
            }

            if (!Directory.Exists(sourceErrorIndexFolder))
            {
                Directory.CreateDirectory(sourceErrorIndexFolder);
            }
            if (!Directory.Exists(settingsFolder))
            {
                Directory.CreateDirectory(settingsFolder);
            }
            if (!Directory.Exists(scriptFolder))
            {
                Directory.CreateDirectory(scriptFolder);
            }
            if (!Directory.Exists(destErrorIndexFolder))
            {
                Directory.CreateDirectory(destErrorIndexFolder);
            }


            try
            {
                // Create a settings manager and a new context.
                SettingsManager          settingsManager = new SettingsManager(settingsFolder + "\\ServiceSettings.XML");
                StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings();

                contextSettings.ErrorIndexSettings        = new ErrorIndexSettings();
                contextSettings.ErrorIndexSettings.Folder = sourceErrorIndexFolder;
                contextSettings.ErrorIndexSettings.Name   = sourceErrorIndexName;
                contextSettings.ErrorIndexSettings.Type   = ErrorIndexType.SqlExpress;

                contextSettings.SqlSettings = StackHashSqlConfiguration.Default;
                contextSettings.SqlSettings.ConnectionString = s_ConnectionString;
                contextSettings.SqlSettings.InitialCatalog   = sourceErrorIndexName;

                ScriptManager scriptManager = new ScriptManager(scriptFolder);

                string         licenseFileName = string.Format("{0}\\License.bin", settingsFolder);
                LicenseManager licenseManager  = new LicenseManager(licenseFileName, s_ServiceGuid);
                licenseManager.SetLicense(s_LicenseId);

                // Create a dummy controller to record the callbacks.
                BugTrackerManager bugTrackerManager = new BugTrackerManager(new String[0]);

                // Create a dummy controller to record the callbacks.
                ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(),
                                                                            settingsManager, true, null, licenseManager);

                // Hook up to receive admin reports.
                controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport);

                // Progress reports don't come through the controller context - they come straight through the contoller so create a dummy.
                Controller controller = new Controller();
                Reporter   reporter   = new Reporter(controller);
                controller.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport);


                // ******************************************
                // CREATE THE SOURCE INDEX
                // ******************************************

                // Delete any old index first.
                SqlConnection.ClearAllPools();

                try
                {
                    controllerContext.DeleteIndex();
                }
                catch {; }

                // Activate the context and the associated index - this will create the index if necessary.
                controllerContext.Activate(null, defaultDatabaseLocation);

                String[] databaseFiles = Directory.GetFiles(Path.Combine(sourceErrorIndexFolder, sourceErrorIndexName), "*.mdf");
                Assert.AreEqual(defaultDatabaseLocation, databaseFiles.Length == 0);

                controllerContext.CreateTestIndex(testIndexData);


                Guid guid = new Guid();
                StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1);


                // ******************************************
                // MOVE TO DESTINATION
                // ******************************************

                // Deactivate before the move.
                controllerContext.Deactivate();

                StackHashSqlConfiguration sqlConfig = new StackHashSqlConfiguration(s_ConnectionString, destErrorIndexName, 1, 100, 15, 100);

                // Move the index.
                controllerContext.RunMoveIndexTask(clientData, destErrorIndexFolder, destErrorIndexName, sqlConfig);

                // Wait for the move task to complete.
                waitForMoveCompleted(60000 * 20);

                Assert.AreEqual(2, m_AdminReports.Count);

                Assert.AreEqual(null, m_AdminReports[0].Report.LastException);
                Assert.AreEqual(0, m_AdminReports[0].Report.ContextId);
                Assert.AreEqual(StackHashAdminOperation.ErrorIndexMoveStarted, m_AdminReports[0].Report.Operation);

                Assert.AreEqual(0, m_AdminReports[1].Report.ContextId);
                Assert.AreEqual(StackHashAdminOperation.ErrorIndexMoveCompleted, m_AdminReports[1].Report.Operation);

                Assert.AreEqual(null, m_AdminReports[1].Report.LastException);
                Assert.AreEqual(StackHashServiceErrorCode.NoError, m_AdminReports[1].Report.ServiceErrorCode);

                if ((testIndexData.NumberOfCabs > 0) && (sourceErrorIndexFolder[0] != destErrorIndexFolder[0]))
                {
                    Assert.AreEqual(true, m_MoveAdminReports.Count > 0);
                }

                controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport);

                ErrorIndexSettings destIndexData = new ErrorIndexSettings()
                {
                    Folder = destErrorIndexFolder,
                    Name   = destErrorIndexName,
                    Type   = ErrorIndexType.SqlExpress
                };

                IErrorIndex index1 = getIndex(destIndexData, sqlConfig);

                try
                {
                    index1.Activate();

                    // Make a single call just to ensure the database is still in tact.
                    StackHashProductCollection products = index1.LoadProductList();

                    Assert.AreEqual(testIndexData.NumberOfProducts, products.Count);
                }
                finally
                {
                    index1.Deactivate();
                    index1.Dispose();
                    SqlConnection.ClearAllPools();
                }
            }
            finally
            {
                SqlConnection.ClearAllPools();
                if (sqlCommands.DatabaseExists(destErrorIndexName))
                {
                    try { sqlCommands.DeleteDatabase(destErrorIndexName); }
                    catch {; }
                }
                if (sqlCommands.DatabaseExists(sourceErrorIndexName))
                {
                    try { sqlCommands.DeleteDatabase(sourceErrorIndexName); }
                    catch {; }
                }

                SqlConnection.ClearAllPools();

                if (Directory.Exists(sourceErrorIndexFolder))
                {
                    PathUtils.SetFilesWritable(sourceErrorIndexFolder, true);
                    PathUtils.DeleteDirectory(sourceErrorIndexFolder, true);
                }
                if (Directory.Exists(destErrorIndexFolder))
                {
                    PathUtils.SetFilesWritable(destErrorIndexFolder, true);
                    PathUtils.DeleteDirectory(destErrorIndexFolder, true);
                }
                if (Directory.Exists(settingsFolder))
                {
                    PathUtils.SetFilesWritable(settingsFolder, true);
                    PathUtils.DeleteDirectory(settingsFolder, true);
                }
            }
        }