예제 #1
0
        public ScriptBatchCollection GetScriptBatchCollectionForProcessBuild()
        {
            ScriptBatchCollection sbc = new ScriptBatchCollection();

            string[] scripts = new string[2];
            scripts[0] = "INSERT INTO dbo.TransactionTest VALUES ('PROCESS BUILD1', newid(), getdate())";
            scripts[1] = "INSERT INTO dbo.TransactionTest VALUES ('PROCESS BUILD2', newid(), getdate())";

            string      scriptName = "Transaction Test Insert.sql";
            string      scriptId   = "59F8CBCA-3FE5-4142-ACB0-3D1D2C25184D"; //Must match GUID from AddScriptForProcessBuild()
            ScriptBatch sb         = new ScriptBatch(scriptName, scripts, scriptId);

            sbc.Add(sb);

            string[] scripts2 = new string[2];
            scripts2[0] = "SELECT top 1 * FROM INFORMATION_SCHEMA.tables";
            scripts2[1] = "SELECT top 1 * FROM INFORMATION_SCHEMA.routines";

            scriptName = "Select InfoSchema.sql";
            scriptId   = "8A9CC6E9-D0D3-4525-AAF4-5ACCECEF4D25";

            ScriptBatch sb2 = new ScriptBatch(scriptName, scripts2, scriptId);

            sbc.Add(sb2);

            return(sbc);
        }
        public void CalculateBuildPackageSHA1SignatureFromBatchCollectionTest_BatchOrder()
        {
            ScriptBatch batch1 = new ScriptBatch(
                "File1.sql",
                new string[] { "Line one goes here", "Line 2 goes there" },
                Guid.NewGuid().ToString());

            ScriptBatch batch2 = new ScriptBatch(
                "File2.sql",
                new string[] { "My Batch Line one goes here", "Second batch Line 2 goes there" },
                Guid.NewGuid().ToString());


            ScriptBatchCollection scriptBatchColl = new ScriptBatchCollection();

            scriptBatchColl.Add(batch1);
            scriptBatchColl.Add(batch2);

            string order12 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);

            scriptBatchColl = new ScriptBatchCollection();
            scriptBatchColl.Add(batch2);
            scriptBatchColl.Add(batch1);

            string order21 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);

            Assert.AreNotEqual(order12, order21);
        }
        private int PrepBuildAndScripts(string buildZipFileName, string buildRequestedBy, bool forceCustomDacpac)
        {
            ThreadedExecution.buildZipFileName = buildZipFileName;
            this.buildRequestedBy = buildRequestedBy;

            //Looks like we're good to go... extract the build Zip file (.sbm) into a working folder...

            if (!forceCustomDacpac)
            {
                ExtractAndLoadBuildFile(ThreadedExecution.buildZipFileName, out ThreadedExecution.buildData);
                if (buildData == null)
                {
                    var msg = new LogMsg()
                    {
                        Message = "Unable to procees. SqlSyncBuild data object is null, Returning error code: " + (int)ExecutionReturn.NullBuildData,
                        LogType = LogType.Error
                    };
                    WriteToLog(msg);
                    return((int)ExecutionReturn.NullBuildData);
                }
                else
                {
                    //Load up the batched scripts into a shared object so that we can conserve memory
                    ThreadedExecution.batchColl = SqlBuildHelper.LoadAndBatchSqlScripts(ThreadedExecution.buildData, this.projectFilePath);
                }
            }
            return(0);
        }
        public void GetScriptBatchTest()
        {
            string scriptfileName = "MyFileName";

            string[]    scriptBatchContents = new string[] { "batch1", "batch2", "batch3" };
            string      scriptId            = System.Guid.NewGuid().ToString();
            ScriptBatch batch1 = new ScriptBatch(scriptfileName, scriptBatchContents, scriptId);

            string scriptfileName2 = "Batch2Name";

            string[]    scriptBatchContents2 = new string[] { "batch4", "batch5", "batch5" };
            string      scriptId2            = System.Guid.NewGuid().ToString();
            ScriptBatch batch2 = new ScriptBatch(scriptfileName2, scriptBatchContents2, scriptId2);

            ScriptBatchCollection target = new ScriptBatchCollection();

            target.Add(batch1);
            target.Add(batch2);

            ScriptBatch actual;

            actual = target.GetScriptBatch(scriptId);
            Assert.AreEqual(batch1, actual);
            actual = target.GetScriptBatch(scriptId2);
            Assert.AreEqual(batch2, actual);
            actual = target.GetScriptBatch("Can'tFindMe");
            Assert.IsNull(actual);
        }
        public void CalculateBuildPackageSHA1_CompareMethodologyTest()
        {
            //Set up directory and files...
            string projectFileExtractionPath = Path.GetTempPath() + Guid.NewGuid().ToString() + "\\";

            if (!Directory.Exists(projectFileExtractionPath))
            {
                Directory.CreateDirectory(projectFileExtractionPath);
            }

            string file1 = "File1.sql";

            File.WriteAllText(projectFileExtractionPath + file1, Properties.Resources.CreateDatabaseScript);

            string file2 = "File2.sql";

            File.WriteAllText(projectFileExtractionPath + file2, Properties.Resources.CreateTestTablesScript);

            string file3 = "File3.sql";

            File.WriteAllText(projectFileExtractionPath + file3, Properties.Resources.LoggingTable);


            SqlSyncBuildData buildData = SqlBuildFileHelper.CreateShellSqlSyncBuildDataObject();

            SqlSyncBuildData.ScriptRow row1 = buildData.Script.NewScriptRow();
            row1.BuildOrder           = 1;
            row1.FileName             = file1;
            row1.StripTransactionText = true;

            SqlSyncBuildData.ScriptRow row2 = buildData.Script.NewScriptRow();
            row2.BuildOrder           = 2;
            row2.FileName             = file2;
            row2.StripTransactionText = true;

            SqlSyncBuildData.ScriptRow row3 = buildData.Script.NewScriptRow();
            row3.BuildOrder           = 3;
            row3.FileName             = file3;
            row3.StripTransactionText = true;

            buildData.Script.Rows.Add(row1);
            buildData.Script.Rows.Add(row2);
            buildData.Script.Rows.Add(row3);


            string fromPath = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromPath(projectFileExtractionPath, buildData);


            ScriptBatchCollection batch = SqlBuildHelper.LoadAndBatchSqlScripts(buildData, projectFileExtractionPath);
            string fromBatch            = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(batch);

            if (Directory.Exists(projectFileExtractionPath))
            {
                Directory.Delete(projectFileExtractionPath, true);
            }

            Assert.AreEqual(fromPath, fromBatch);
        }
예제 #6
0
        public ScriptBatchCollection GetScriptBatchCollection()
        {
            ScriptBatchCollection coll = new ScriptBatchCollection();

            coll.Add(new ScriptBatch("File1.sql",
                                     new string[] { "SELECT top 1 * from SqlBuild_Logging", "SELECT TOP 1 * from SqlBuild_Logging ORDER BY CommitDate DESC" },
                                     "D0080D2A-7E24-4C47-94D6-8EADFCEF8B57"));

            coll.Add(new ScriptBatch("File2.sql",
                                     new string[] { "SELECT top 2 * from SqlBuild_Logging", "SELECT TOP 2 * from SqlBuild_Logging ORDER BY CommitDate DESC" },
                                     "A8318EF0-D6D9-4D65-8207-BB4AC62C4FB8"));

            coll.Add(new ScriptBatch("File3.sql",
                                     new string[] { "SELECT top 3 * from SqlBuild_Logging", "SELECT TOP 3 * from SqlBuild_Logging ORDER BY CommitDate DESC" },
                                     "1309E71F-4515-46BA-9446-E054F3523BDF"));

            return(coll);
        }
예제 #7
0
        public void ProcessBuildTest_RollbackWithThreeRetries()
        {
            Initialization init = GetInitializationObject();

            init.TableLockingLoopCount = 10000000;
            SqlSyncBuildData buildData = init.CreateSqlSyncSqlBuildDataObject();

            init.AddScriptForProcessBuild(ref buildData, true, 1);

            SqlBuildHelper  target  = init.CreateSqlBuildHelper(buildData);
            SqlBuildRunData runData = init.GetSqlBuildRunData_TransactionalNotTrial(buildData);

            BackgroundWorker      bgWorker        = init.GetBackgroundWorker();
            DoWorkEventArgs       e               = new DoWorkEventArgs(null);
            string                serverName      = init.serverName;
            bool                  isMultiDbRun    = false;
            ScriptBatchCollection scriptBatchColl = init.GetScriptBatchCollectionForProcessBuild();
            int allowableTimeoutRetries           = 3;

            Thread THRInfinite = null;

            try
            {
                THRInfinite = new Thread(new ParameterizedThreadStart(StartInfiniteLockingThread));
                THRInfinite.Start(init);

                string expected = BuildItemStatus.RolledBackAfterRetries;
                SqlSyncBuildData.BuildRow actual;
                actual = target.ProcessBuild(runData, bgWorker, e, serverName, isMultiDbRun, scriptBatchColl, allowableTimeoutRetries);
                Assert.AreEqual(expected, actual.FinalStatus);
            }
            finally
            {
                if (THRInfinite != null)
                {
                    THRInfinite.Interrupt();
                }
            }
        }
예제 #8
0
        public void ProcessBuildTest_CommitWithRetriesNotUsed()
        {
            Initialization   init      = GetInitializationObject();
            SqlSyncBuildData buildData = init.CreateSqlSyncSqlBuildDataObject();

            init.AddScriptForProcessBuild(ref buildData, true, 20);

            SqlBuildHelper        target          = init.CreateSqlBuildHelper(buildData);
            SqlBuildRunData       runData         = init.GetSqlBuildRunData_TransactionalNotTrial(buildData);
            BackgroundWorker      bgWorker        = init.GetBackgroundWorker();
            DoWorkEventArgs       e               = new DoWorkEventArgs(null);
            string                serverName      = init.serverName;
            bool                  isMultiDbRun    = false;
            ScriptBatchCollection scriptBatchColl = init.GetScriptBatchCollectionForProcessBuild();
            int allowableTimeoutRetries           = 3;

            string expected = BuildItemStatus.Committed;

            SqlSyncBuildData.BuildRow actual;
            actual = target.ProcessBuild(runData, bgWorker, e, serverName, isMultiDbRun, scriptBatchColl, allowableTimeoutRetries);
            Assert.AreEqual(expected, actual.FinalStatus);
        }
        public void CalculateBuildPackageSHA1SignatureFromBatchCollectionTest()
        {
            ScriptBatch batch1 = new ScriptBatch(
                "File1.sql",
                new string[] { "Line one goes here", "Line 2 goes there" },
                Guid.NewGuid().ToString());

            ScriptBatch batch2 = new ScriptBatch(
                "File2.sql",
                new string[] { "My Batch Line one goes here", "Second batch Line 2 goes there" },
                Guid.NewGuid().ToString());


            ScriptBatchCollection scriptBatchColl = new ScriptBatchCollection();

            scriptBatchColl.Add(batch1);
            scriptBatchColl.Add(batch2);
            string expected = "E00B044F80A5F40EDAFC53BE8B559BD4DB5229A0";
            string actual;

            actual = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);
            Assert.AreEqual(expected, actual);
        }
        public void CalculateBuildPackageSHA1_CompareMethodologyTest_OrderCheckingWithTransactionsToRemove()
        {
            //Set up directory and files...
            string projectFileExtractionPath = Path.GetTempPath() + Guid.NewGuid().ToString() + "\\";

            if (!Directory.Exists(projectFileExtractionPath))
            {
                Directory.CreateDirectory(projectFileExtractionPath);
            }

            string file1 = "File1.sql";

            File.WriteAllText(projectFileExtractionPath + file1, @"This is My script
with my 
COMMIT TRANS
test");

            string file2 = "File2.sql";

            File.WriteAllText(projectFileExtractionPath + file2, Properties.Resources.CreateTestTablesScript);

            string file3 = "File3.sql";

            File.WriteAllText(projectFileExtractionPath + file3, @"This is another test that has
--ROLLBACK TRANSACTION
where the 
BEGIN TRAN
needs to be removed");


            SqlSyncBuildData buildData = SqlBuildFileHelper.CreateShellSqlSyncBuildDataObject();

            SqlSyncBuildData.ScriptRow row1 = buildData.Script.NewScriptRow();
            row1.BuildOrder           = 1;
            row1.FileName             = file1;
            row1.StripTransactionText = true;

            SqlSyncBuildData.ScriptRow row2 = buildData.Script.NewScriptRow();
            row2.BuildOrder           = 2;
            row2.FileName             = file2;
            row2.StripTransactionText = true;

            SqlSyncBuildData.ScriptRow row3 = buildData.Script.NewScriptRow();
            row3.BuildOrder           = 3;
            row3.FileName             = file3;
            row3.StripTransactionText = true;

            buildData.Script.Rows.Add(row1);
            buildData.Script.Rows.Add(row2);
            buildData.Script.Rows.Add(row3);


            string fromPath123 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromPath(projectFileExtractionPath, buildData);

            ScriptBatchCollection batch = SqlBuildHelper.LoadAndBatchSqlScripts(buildData, projectFileExtractionPath);
            string fromBatch123         = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(batch);

            buildData.Script[0].BuildOrder = 2;
            buildData.Script[1].BuildOrder = 1;
            buildData.Script[2].BuildOrder = 3;
            buildData.AcceptChanges();

            string fromPath213 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromPath(projectFileExtractionPath, buildData);

            batch = SqlBuildHelper.LoadAndBatchSqlScripts(buildData, projectFileExtractionPath);
            string fromBatch213 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(batch);


            if (Directory.Exists(projectFileExtractionPath))
            {
                Directory.Delete(projectFileExtractionPath, true);
            }

            Assert.AreEqual(fromPath123, fromBatch123);
            Assert.AreEqual(fromPath213, fromBatch213);
            Assert.AreNotEqual(fromPath123, fromBatch213);
            Assert.AreNotEqual(fromPath213, fromBatch123);
        }
        public void ScriptBatchCollectionConstructorTest()
        {
            ScriptBatchCollection target = new ScriptBatchCollection();

            Assert.IsInstanceOfType(target, typeof(ScriptBatchCollection));
        }