public void Sql_NonEmptySource_DestinationFolderChanged() { bool databaseInDefaultLocation = false; StackHashTestIndexData testIndexData = new StackHashTestIndexData() { NumberOfProducts = 2, NumberOfFiles = 2, NumberOfEvents = 2, NumberOfEventInfos = 2, NumberOfCabs = 2, NumberOfEventNotes = 2, NumberOfCabNotes = 2, UnwrapCabs = true, CabFileName = s_TestCab }; String settingsFolder = "c:\\stackhashunittests\\Settings\\"; String sourceFolder = "c:\\stackhashunittests\\MoveUnitTests\\"; String sourceDatabaseName = "SourceMoveIndex"; String destFolder = "c:\\stackhashunittests\\MoveUnitTestsDest\\"; String destDatabaseName = "SourceMoveIndex"; runMoveTask(settingsFolder, sourceFolder, sourceDatabaseName, destFolder, destDatabaseName, databaseInDefaultLocation, testIndexData); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void getProductSummary(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, int productId) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); GetProductRollupResponse resp2 = m_Utils.GetProductSummary(0, productId); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.HitDateSummary.Count); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.LocaleSummaryCollection.Count); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.OperatingSystemSummary.Count); m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
public void Sql_NonEmptySource_NameChanged_DefaultDatabaseLocation() { bool databaseInDefaultLocation = true; StackHashTestIndexData testIndexData = new StackHashTestIndexData() { NumberOfProducts = 2, NumberOfFiles = 2, NumberOfEvents = 2, NumberOfEventInfos = 2, NumberOfCabs = 2, NumberOfEventNotes = 2, NumberOfCabNotes = 2, UnwrapCabs = true, CabFileName = s_TestCab }; String settingsFolder = "c:\\stackhashunittests\\Settings\\"; String sourceFolder = "c:\\stackhashunittests\\MoveUnitTests\\"; String sourceDatabaseName = "SourceMoveIndex"; String destFolder = "c:\\Stackhashunittests\\MoveUnitTESTS"; // Change the case and strip the backslash to try and confuse. String destDatabaseName = "DestinationMoveIndex"; runMoveTask(settingsFolder, sourceFolder, sourceDatabaseName, destFolder, destDatabaseName, databaseInDefaultLocation, testIndexData); }
// Set the workflow status. public void setWorkFlowStatus(ErrorIndexType indexType, bool resetService) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(1, getProductsResp.Products.Count()); GetFilesResponse allFiles = m_Utils.GetFiles(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allFiles.Files.Count()); GetProductEventPackageResponse allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); // Set the workflow status int workFlowStatus = 10; m_Utils.SetWorkFlowStatus(0, getProductsResp.Products[0].Product, allFiles.Files[0], allEvents.EventPackages[0].EventData, workFlowStatus); if (resetService) { m_Utils.RestartService(); } allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); Assert.AreEqual(workFlowStatus, allEvents.EventPackages[0].EventData.WorkFlowStatus); Assert.AreEqual("Resolved - Responded", allEvents.EventPackages[0].EventData.WorkFlowStatusName); m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
public void DontCountAllMatchesOnFirstPage() { // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 2; testIndexData.NumberOfEventInfos = 1; testIndexData.NumberOfCabs = 1; testIndexData.NumberOfScriptResults = 1; testIndexData.UseLargeCab = false; StackHashSearchCriteria criteria1 = new StackHashSearchCriteria(); criteria1.SearchFieldOptions = new StackHashSearchOptionCollection(); criteria1.SearchFieldOptions.Add(new IntSearchOption() { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.GreaterThan, Start = 0, End = 0 }); criteria1.SearchFieldOptions.Add(new StringSearchOption() { ObjectType = StackHashObjectType.Script, FieldName = "Content", SearchOptionType = StackHashSearchOptionType.StringContains, Start = "Script", End = null, CaseSensitive = false }); StackHashSearchCriteriaCollection allSearchCriteria = new StackHashSearchCriteriaCollection(); allSearchCriteria.Add(criteria1); StackHashSortOrderCollection sortOrder = new StackHashSortOrderCollection(); sortOrder.Add(new StackHashSortOrder() { ObjectType = StackHashObjectType.Event, FieldName = "Id", Ascending = true }); long startRow = 1; long numRows = 1; bool countAllMatches = false; StackHashSearchDirection direction = StackHashSearchDirection.Forwards; GetWindowedEventPackageResponse eventPackageResp = windowSearch(ErrorIndexType.SqlExpress, testIndexData, allSearchCriteria, startRow, numRows, sortOrder, direction, countAllMatches); Assert.AreEqual(1, eventPackageResp.EventPackages.Count); Assert.AreEqual(1, eventPackageResp.MinimumRowNumber); Assert.AreEqual(1, eventPackageResp.MaximumRowNumber); Assert.AreEqual(numRows, eventPackageResp.TotalRows); }
/// <summary> /// Make sure notification only comes back to the one client. /// Username and password are incorrect so should just fail to login. /// </summary> public void adminReportShouldBeSentToIndividualClient(ErrorIndexType indexType) { m_Utils.RegisterForNotifications(true, Guid.NewGuid()); m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.RegisterForNotifications(true, Guid.NewGuid()); m_Utils.CreateAndSetNewContext(indexType); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 1; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000); StackHashAdminReport adminReport = m_Utils.DownloadCabAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(m_Utils.LastClientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(m_Utils.LastClientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(m_Utils.LastClientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(m_Utils.LastClientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreNotEqual(null, adminReport.LastException); Assert.AreEqual(true, adminReport.LastException.Contains("username and password")); Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Failed, adminReport.ResultData); // Should receive 3 admin register + download started + download completed. Assert.AreEqual(5, m_Utils.AllReports.Count); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public static void CreateTestIndex(bool sqlIndex, String folder, String name, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, String cabFile) { // The folder must exist. if (Directory.Exists(folder)) { throw new ArgumentException("Destination folder must not exist", "folder"); } if (String.IsNullOrEmpty(name)) { throw new ArgumentException("You must specify an index name"); } if (!File.Exists(cabFile)) { throw new ArgumentException("Cab file must be specified and must exist"); } Directory.CreateDirectory(folder); // Create an index. IErrorIndex index; if (sqlIndex) { index = new SqlErrorIndex(StackHashSqlConfiguration.Default, name, folder); } else { index = new XmlErrorIndex(folder, name); } index.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = numProducts; testData.NumberOfFiles = numFiles; testData.NumberOfEvents = numEvents; testData.NumberOfEventInfos = numEventInfos; testData.NumberOfCabs = numCabs; testData.CabFileName = cabFile; CreateTestIndex(index, testData); }
public void CopyNonEmptyIndexToSqlNoSwitchCreateLocally() { StackHashTestIndexData testIndexData = new StackHashTestIndexData { NumberOfProducts = 1, NumberOfFiles = 2, NumberOfEvents = 3, NumberOfEventInfos = 4, NumberOfCabs = 4, NumberOfEventNotes = 5, NumberOfCabNotes = 5, UnwrapCabs = true, CabFileName = s_TestCab }; copyIndex(true, false, testIndexData); }
public void CopyEmptyIndexToSqlSwitch() { StackHashTestIndexData testIndexData = new StackHashTestIndexData { NumberOfProducts = 0, NumberOfFiles = 0, NumberOfEvents = 0, NumberOfEventInfos = 0, NumberOfCabs = 0, NumberOfEventNotes = 0, NumberOfCabNotes = 0, UnwrapCabs = false, CabFileName = s_TestCab }; copyIndex(false, true, testIndexData); }
public void Sql_NonEmptySource_NameAndFolderChanged_DefaultDatabaseLocation() { bool databaseInDefaultLocation = true; try { DriveInfo allDrives = new DriveInfo("z:"); if (allDrives == null) { return; } if (!allDrives.IsReady) { return; } } catch { // Drive not defined. return; } StackHashTestIndexData testIndexData = new StackHashTestIndexData() { NumberOfProducts = 2, NumberOfFiles = 2, NumberOfEvents = 2, NumberOfEventInfos = 2, NumberOfCabs = 2, NumberOfEventNotes = 2, NumberOfCabNotes = 2, UnwrapCabs = true, CabFileName = s_TestCab }; String settingsFolder = "c:\\stackhashunittests\\Settings\\"; String sourceFolder = "c:\\stackhashunittests\\MoveUnitTests\\"; String sourceDatabaseName = "SourceMoveIndex"; String destFolder = "z:\\Stackhashunittests\\MoveUnitTESTS"; // Change the case and strip the backslash to try and confuse. String destDatabaseName = "DestinationMoveIndex"; runMoveTask(settingsFolder, sourceFolder, sourceDatabaseName, destFolder, destDatabaseName, databaseInDefaultLocation, testIndexData); }
// Get the public void getCabPackage(ErrorIndexType indexType) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 1; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(1, getProductsResp.Products.Count()); GetFilesResponse allFiles = m_Utils.GetFiles(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allFiles.Files.Count()); GetProductEventPackageResponse allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); Assert.AreEqual(1, allEvents.EventPackages[0].Cabs.Count); // Get the Cab package. GetCabPackageResponse cabPackageResp = m_Utils.GetCabPackage(0, getProductsResp.Products[0].Product, allFiles.Files[0], allEvents.EventPackages[0].EventData, allEvents.EventPackages[0].Cabs[0].Cab); Assert.AreEqual("c:\\stackhashunittests\\testindex\\TestIndex\\00\\00\\00\\00\\CAB_0000000001\\1-Crash 32bit-0.cab", cabPackageResp.CabPackage.FullPath); }
/// <summary> /// Product doesn't exist. /// </summary> public void downloadCabProductDoesntExist(ErrorIndexType indexType) { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(indexType); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 1; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; products[0].Product.Id++; // Wrong ID. DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000); } catch (FaultException <ReceiverFaultDetail> ex) { Assert.AreEqual(true, ex.Message.Contains("Product does not exist")); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { _testData = new StackHashTestIndexData(); _testData.CabFileName = "1630796338-Crash32bit-0760025228.cab"; _testData.NumberOfCabNotes = 5; _testData.NumberOfCabs = 5; _testData.NumberOfEventInfos = 100; _testData.NumberOfEventNotes = 3; _testData.NumberOfEvents = 5000; _testData.NumberOfFiles = 7; _testData.NumberOfProducts = 10; _testData.UnwrapCabs = false; _testData.UseLargeCab = false; _testData.DuplicateFileIdsAcrossProducts = false; _testData.NumberOfScriptResults = 2; this.DataContext = _testData; if (!DesignerProperties.GetIsInDesignMode(this)) { _clientLogic.PropertyChanged += new PropertyChangedEventHandler(_clientLogic_PropertyChanged); _clientLogic.ClientLogicUI += new EventHandler <ClientLogicUIEventArgs>(_clientLogic_ClientLogicUI); } }
public void AutoScriptOnOneCabProductNotEnabled() { // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters(); // Standard task parameters. analyzeParams.IsBackgroundTask = true; analyzeParams.Name = "TestRunOneTask"; analyzeParams.RunInParallel = false; analyzeParams.UseSeparateThread = true; analyzeParams.AnalysisSettings = new StackHashAnalysisSettings(); analyzeParams.AnalysisSettings.ForceRerun = true; analyzeParams.ContextId = 0; analyzeParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); analyzeParams.Debugger = m_Debugger; analyzeParams.DebuggerSettings = m_DebuggerSettings; analyzeParams.TheScriptManager = scriptManager; analyzeParams.TheScriptResultsManager = scriptResultsManager; analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection(); analyzeParams.ErrorIndex = errorIndex; // Create the task and run it. AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted); StackHashProductCollection products = errorIndex.LoadProductList(); StackHashFileCollection files = errorIndex.LoadFileList(products[0]); StackHashEventCollection events = errorIndex.LoadEventList(products[0], files[0]); StackHashCabCollection cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; Assert.AreEqual(null, analysis.DotNetVersion); Assert.AreEqual(null, analysis.MachineArchitecture); Assert.AreEqual(null, analysis.OSVersion); Assert.AreEqual(null, analysis.ProcessUpTime); Assert.AreEqual(null, analysis.SystemUpTime); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void copyIndex(bool createDestinationIndexLocally, bool switchIndex, StackHashTestIndexData testData) { try { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(ErrorIndexType.Xml); // Create a context and give it a non-default name. m_Utils.DeleteIndex(0); GetStackHashPropertiesResponse getResp = m_Utils.GetContextSettings(); Assert.AreEqual(ErrorIndexStatus.NotCreated, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); m_Utils.ActivateContext(0); // Create the index. m_Utils.CreateTestIndex(0, testData); getResp = m_Utils.GetContextSettings(); Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); String originalIndexPath = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder; String originalIndexName = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name; String destIndexName = "UnitTestsCopyIndexName"; String destIndexPath = "c:\\stackhashunittests\\copyindexpath\\"; // Make sure the destination folder does not exist. String fullDestPath = Path.Combine(destIndexPath, destIndexName); if (Directory.Exists(fullDestPath)) { PathUtils.DeleteDirectory(fullDestPath, true); } ErrorIndexSettings destSettings = new ErrorIndexSettings() { Folder = destIndexPath, Name = destIndexName, Type = ErrorIndexType.SqlExpress }; StackHashSqlConfiguration sqlConfig = new StackHashSqlConfiguration() { ConnectionString = String.Format(TestSettings.DefaultConnectionString, destIndexName), InitialCatalog = destIndexName, MaxPoolSize = 100, MinPoolSize = 2, ConnectionTimeout = 20, }; if (createDestinationIndexLocally) { StackHashSqlControl.InstallerInterface installerInterface = new StackHashSqlControl.InstallerInterface(TestSettings.DefaultConnectionString + "Initial Catalog=MASTER;", destSettings.Name, destSettings.Folder); installerInterface.Connect(); installerInterface.CreateDatabase(true); installerInterface.Disconnect(); SqlConnection.ClearAllPools(); } m_Utils.DeactivateContext(0); m_Utils.CopyIndex(0, destSettings, sqlConfig, switchIndex, 60000); m_Utils.ActivateContext(0); Assert.AreEqual(true, Directory.Exists(Path.Combine(originalIndexPath, originalIndexName))); Assert.AreEqual(true, Directory.Exists(fullDestPath)); Assert.AreNotEqual(null, m_Utils.CopyCompleteAdminReport); Assert.AreEqual(null, m_Utils.CopyCompleteAdminReport.LastException); Assert.AreEqual(StackHashAsyncOperationResult.Success, m_Utils.CopyCompleteAdminReport.ResultData); getResp = m_Utils.GetContextSettings(); if (switchIndex) { Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); Assert.AreEqual(destSettings.Folder.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant()); Assert.AreEqual(destSettings.Name.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant()); } else { Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); Assert.AreEqual(originalIndexPath.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant()); Assert.AreEqual(originalIndexName.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant()); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void getWindowedEventsByOrder(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, int windowSize, bool restrictSearchToParticularProduct, bool addLotsOfSearchOptions, List <int> enabledProducts, StackHashSearchDirection direction) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; testIndexData.NumberOfScriptResults = numCabs; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection(); // Just get events for even numbered product ids. for (int productCount = 0; productCount < numProducts; productCount++) { if ((enabledProducts == null) || enabledProducts.Contains(productCount + 1)) { m_Utils.SetProductSynchronizationState(0, productCount + 1, true); } // This doesn't really do anything - just in here so there is at least 1 search option. StackHashSearchCriteria newCriteria = new StackHashSearchCriteria { SearchFieldOptions = new StackHashSearchOptionCollection() { new IntSearchOption { ObjectType = StackHashObjectType.Product, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.Equal, Start = productCount + 1, End = productCount + 1 }, } }; if (addLotsOfSearchOptions) { // Add some "always true" options just to complicate things. newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeInclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.GreaterThan, Start = 0, End = 0 }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.EventInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.CabInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); } if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { allCriteria.Add(newCriteria); } } else { allCriteria.Add(newCriteria); } } // The events will be returned possibly in event id order from the search. // Set the sort order based on the Offset - ascending - this should return the events // in reverse event ID order as the offsets descend. StackHashSortOrderCollection allSortOrders = new StackHashSortOrderCollection() { new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "Offset", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateCreatedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateModifiedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "EventTypeName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "Id", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "TotalHits", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "BugId", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ExceptionCode", Ascending = true }, }; int totalEventsExpected = numProducts * numFiles * numEvents; List <int> expectedEventIds = new List <int>(); int expectedEventId = 1; for (int productCount = 0; productCount < numProducts; productCount++) { for (int fileCount = 0; fileCount < numFiles; fileCount++) { for (int eventCount = 0; eventCount < numEvents; eventCount++) { // Only add product events for even numbered products. if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { expectedEventIds.Add(expectedEventId++); } else { expectedEventId++; } } else if ((enabledProducts != null) && !enabledProducts.Contains(productCount + 1)) { expectedEventId++; } else { expectedEventIds.Add(expectedEventId++); } } } } expectedEventIds.Reverse(); for (int startRow = 1; startRow <= expectedEventIds.Count; startRow++) { DateTime startTime = DateTime.Now; // Get the next window. GetWindowedEventPackageResponse allPackages = m_Utils.GetWindowedEvents(0, allCriteria, startRow, windowSize, allSortOrders, direction, startRow == 1); TimeSpan totalTime = DateTime.Now - startTime; Console.WriteLine("Window: {0}, startRow: {1}, numRows: {2}, duration: {3}", windowSize, startRow, allPackages.EventPackages.Count, totalTime); Assert.AreNotEqual(null, allPackages.EventPackages); int expectedRowsReturned = startRow + windowSize - 1 > expectedEventIds.Count ? expectedEventIds.Count - startRow + 1 : windowSize; if (expectedRowsReturned < 0) { expectedRowsReturned = 0; } Assert.AreEqual(expectedRowsReturned, allPackages.EventPackages.Count); for (int eventIndex = 0; eventIndex < expectedRowsReturned; eventIndex++) { int nextExpectedEventId = expectedEventIds[startRow + eventIndex - 1]; StackHashEventPackage eventRetrieved = allPackages.EventPackages[eventIndex]; Assert.AreEqual(nextExpectedEventId, eventRetrieved.EventData.Id); Assert.AreEqual(numCabs, eventRetrieved.Cabs.Count); Assert.AreEqual(numEventInfos, eventRetrieved.EventInfoList.Count); foreach (StackHashCabPackage cabPackage in eventRetrieved.Cabs) { Assert.AreNotEqual(null, cabPackage.Cab); Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } // Get the event package through the other interface. StackHashProduct product = new StackHashProduct() { Id = eventRetrieved.ProductId }; StackHashFile file = new StackHashFile() { Id = eventRetrieved.EventData.FileId }; StackHashEventPackage matchedPackage = m_Utils.GetEventPackage(0, product, file, eventRetrieved.EventData).EventPackage; Assert.AreEqual(eventRetrieved.Cabs.Count, matchedPackage.Cabs.Count); foreach (StackHashCabPackage cabPackage in matchedPackage.Cabs) { Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } } } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
public void RunScriptOnCorruptCab() { // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); // Delete the cab file. StackHashProduct product = errorIndex.GetProduct(1); StackHashFile file = errorIndex.GetFile(product, 1); StackHashEventPackageCollection events = errorIndex.GetProductEvents(product); String cabFileName = errorIndex.GetCabFileName(product, file, events[0].EventData, events[0].Cabs[0].Cab); if (File.Exists(cabFileName)) { FileStream fileStream = File.Open(cabFileName, FileMode.Open, FileAccess.ReadWrite); try { fileStream.SetLength(100); } finally { fileStream.Close(); } } ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. DebugScriptTaskParameters runScriptParams = new DebugScriptTaskParameters(); // Standard task parameters. runScriptParams.IsBackgroundTask = true; runScriptParams.Name = "TestRunOneTask"; runScriptParams.RunInParallel = false; runScriptParams.UseSeparateThread = true; runScriptParams.ContextId = 0; runScriptParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); runScriptParams.Debugger = m_Debugger; runScriptParams.TheScriptManager = scriptManager; runScriptParams.TheScriptResultsManager = scriptResultsManager; runScriptParams.Product = product; runScriptParams.File = file; runScriptParams.TheEvent = events[0].EventData; runScriptParams.Cab = events[0].Cabs[0].Cab; runScriptParams.ErrorIndex = errorIndex; // Create the task and run it. DebugScriptTask debugScriptTask = new DebugScriptTask(runScriptParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(debugScriptTask); taskManager.WaitForTaskCompletion(debugScriptTask, s_TaskTimeout); Assert.AreEqual(true, debugScriptTask.CurrentTaskState.TaskCompleted); Assert.AreNotEqual(null, debugScriptTask.LastException); Assert.AreEqual(true, debugScriptTask.LastException is StackHashException); StackHashException ex = debugScriptTask.LastException as StackHashException; Assert.AreEqual(StackHashServiceErrorCode.CabIsCorrupt, ex.ServiceErrorCode); StackHashCabCollection cabs = errorIndex.LoadCabList(product, file, events[0].EventData); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void addRemoveEventNotes(int numberOfNotes) { StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(ErrorIndexType.SqlExpress); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = ErrorIndexType.SqlExpress; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashProduct product = products[0].Product; StackHashFileCollection files = m_Utils.GetFiles(0, product).Files; StackHashEventCollection events = m_Utils.GetEvents(0, product, files[0]).Events; // Add the specified number of event notes. for (int eventCount = 0; eventCount < numberOfNotes; eventCount++) { StackHashNoteEntry note = new StackHashNoteEntry(); note.Note = "Note" + (eventCount + 1).ToString(); note.Source = "USER"; note.User = "******"; note.TimeOfEntry = DateTime.Now.AddDays(-1); m_Utils.AddEventNote(0, product, files[0], events[0], note); StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes; Assert.AreEqual(eventCount + 1, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == eventCount + 1) { Assert.AreEqual(note.Note, noteEntry.Note); Assert.AreEqual(note.Source, noteEntry.Source); Assert.AreEqual(note.User, noteEntry.User); Assert.AreEqual(DateTime.UtcNow.Date, noteEntry.TimeOfEntry.Date); found = true; break; } } Assert.AreEqual(true, found); } // Now delete the event notes. int expectedEventNotes = numberOfNotes; for (int eventCount = 0; eventCount < numberOfNotes; eventCount++) { m_Utils.DeleteEventNote(0, product, files[0], events[0], eventCount + 1); expectedEventNotes--; StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes; Assert.AreEqual(expectedEventNotes, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == eventCount + 1) { found = true; break; } } Assert.AreEqual(false, found); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData, bool includeDuplicates) { if (testData.EventsToAssignCabs == 0) { testData.EventsToAssignCabs = 1; } Random rand = new Random(1); Random scriptRand = new Random(1); if (index == null) { throw new ArgumentNullException("index"); } if (testData == null) { throw new ArgumentNullException("testData"); } DateTime now = DateTime.Now; int fileId = 1; int eventId = 1; int cabId = 1; int productId = 1; int offset = 10000; if (!s_IsTestMode) { productId = 26214; fileId = 1035620; eventId = 1099309964; cabId = 939529168; } int initialFileId = fileId; int initialEventId = eventId; int initialCabId = cabId; int initialOffset = offset; int totalEventsPerProduct = testData.NumberOfFiles * testData.NumberOfEvents; index.SetLastSyncTimeLocal(-2, DateTime.Now.AddDays(-14)); for (int i = 0; i < testData.NumberOfProducts; i++) { StackHashProduct product = new StackHashProduct(); product.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); product.DateModifiedLocal = product.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); product.FilesLink = "http://www.cucku.com"; product.Id = productId; product.Name = "StackHash" + productId.ToString(CultureInfo.InvariantCulture); product.TotalEvents = totalEventsPerProduct; product.TotalResponses = 1; product.Version = "1.2.3." + productId.ToString(CultureInfo.InvariantCulture); index.AddProduct(product); productId++; if (includeDuplicates) { fileId = initialFileId; eventId = initialEventId; cabId = initialCabId; offset = initialOffset; rand = new Random(1); } for (int j = 0; j < testData.NumberOfFiles; j++) { StackHashFile file = new StackHashFile(); file.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); file.DateModifiedLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); file.Id = fileId++; file.LinkDateLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); int fileIndex = rand.Next() % s_FileNames.Length; file.Name = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", s_FileNames[fileIndex], "dll"); file.Version = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", fileId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (j + 1) * 1237); index.AddFile(product, file); for (int k = 0; k < testData.NumberOfEvents; k++) { int totalHits = 0; Random hitsRand = new Random(k); for (int l = 0; l < testData.NumberOfEventInfos; l++) { if (s_IsTestMode) { totalHits += (l + k); } else { totalHits += hitsRand.Next(0, 50); } } StackHashEvent theEvent = new StackHashEvent(); theEvent.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); theEvent.DateModifiedLocal = theEvent.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); theEvent.EventTypeName = s_EventTypes[rand.Next(0, s_EventTypes.Length)]; theEvent.FileId = file.Id; theEvent.Id = eventId; theEvent.BugId = "Bug" + eventId.ToString(CultureInfo.InvariantCulture); theEvent.TotalHits = totalHits; theEvent.EventSignature = new StackHashEventSignature(); theEvent.EventSignature.ApplicationName = "StackHash.exe"; theEvent.EventSignature.ApplicationTimeStamp = now.ToUniversalTime().AddDays(rand.Next(-180, 0)); theEvent.EventSignature.ApplicationVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234); theEvent.EventSignature.ExceptionCode = 0xc0000000 + rand.Next(0, 16); theEvent.EventSignature.ModuleName = "Module" + k.ToString(CultureInfo.InvariantCulture); theEvent.EventSignature.ModuleTimeStamp = now.ToUniversalTime().AddDays(-1 * ((rand.Next() % 200))); theEvent.EventSignature.ModuleVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234); if (s_IsTestMode) { theEvent.EventSignature.Offset = offset--; // Make these go backwards. } else { theEvent.EventSignature.Offset = rand.Next(0, 0xfffff); } theEvent.EventSignature.Parameters = new StackHashParameterCollection(); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationName", theEvent.EventSignature.ApplicationName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationTimeStamp", theEvent.EventSignature.ApplicationTimeStamp.ToString(CultureInfo.InvariantCulture))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationVersion", theEvent.EventSignature.ApplicationVersion)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("exceptionCode", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.ExceptionCode))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleName", theEvent.EventSignature.ModuleName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleTimeStamp", theEvent.EventSignature.ModuleTimeStamp.ToString(CultureInfo.InvariantCulture))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleVersion", theEvent.EventSignature.ModuleVersion.ToString())); theEvent.EventSignature.Parameters.Add(new StackHashParameter("offset", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.Offset))); theEvent.EventSignature.InterpretParameters(); index.AddEvent(product, file, theEvent); // Allow for some duplicate event ids. if (!s_IsTestMode) { eventId++; //if (rand.Next(0, 100) > 5) // eventId++; //if (rand.Next(0, 100) > 50) // eventId = -1 * eventId; } else { eventId++; } hitsRand = new Random(k); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int l = 0; l < testData.NumberOfEventInfos; l++) { int languageIndex = rand.Next() % s_Languages.Length; if (s_IsTestMode) { languageIndex = l % s_Languages.Length; } StackHashEventInfo eventInfo = new StackHashEventInfo(); eventInfo.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); eventInfo.DateModifiedLocal = eventInfo.DateCreatedLocal.AddDays(l).RoundToPreviousMinute(); if (s_IsTestMode) { eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(-1 * l).RoundToPreviousMinute(); } else { eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(rand.Next(-180, 0)).RoundToPreviousMinute(); } eventInfo.Language = s_Languages[languageIndex].Name; eventInfo.Lcid = s_Languages[languageIndex].Lcid; eventInfo.Locale = s_Languages[languageIndex].LocaleCode; int osIndex = rand.Next(0, s_OperatingSystems.Length); if (s_IsTestMode) { osIndex = l % s_OperatingSystems.Length; } eventInfo.OperatingSystemName = s_OperatingSystems[osIndex]; if (s_IsTestMode) { eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex] + l.ToString(CultureInfo.InvariantCulture); } else { eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex]; } if (s_IsTestMode) { eventInfo.TotalHits = l + k; } else { eventInfo.TotalHits = hitsRand.Next(0, 50); } if (eventInfoCollection.FindEventInfo(eventInfo) == null) { eventInfoCollection.Add(eventInfo); } } index.MergeEventInfoCollection(product, file, theEvent, eventInfoCollection); for (int m = 0; m < testData.NumberOfCabs; m++) { if ((k % testData.EventsToAssignCabs) != 0) { break; } StackHashCab cab = new StackHashCab(); if (IsTestMode) { cab.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * m).RoundToPreviousMinute(); cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute(); } else { cab.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute(); } cab.EventId = theEvent.Id; cab.EventTypeName = theEvent.EventTypeName; cab.FileName = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}.cab", cab.EventId, cab.EventTypeName, cab.Id); cab.Id = cabId++; cab.SizeInBytes = 64123 + rand.Next(-4000, 4000); // Some random value - corrected later if a real file exists. cab.CabDownloaded = true; // Get the size of the cab file. String sourceCabFile; if (testData.CabFileName != null) { sourceCabFile = Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName); } else if (testData.UseLargeCab) { sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab"; } else { sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab"; } if (File.Exists(sourceCabFile)) { FileInfo sourceCabFileInfo = new FileInfo(sourceCabFile); cab.SizeInBytes = sourceCabFileInfo.Length; } index.AddCab(product, file, theEvent, cab, false); // Copy in a test cab file. String cabFolder = index.GetCabFolder(product, file, theEvent, cab); if (!Directory.Exists(cabFolder)) { Directory.CreateDirectory(cabFolder); } String cabFileName = index.GetCabFileName(product, file, theEvent, cab); if (!File.Exists(cabFileName)) { if (testData.CabFileName != null) { File.Copy(Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName), cabFileName); } else if (testData.UseLargeCab) { File.Copy(TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName); } else { File.Copy(TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName); } } // Make sure the file is not read only. FileAttributes attributes = File.GetAttributes(cabFileName); attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(cabFileName, attributes); // Unwrap the cab. if (testData.UnwrapCabs) { Cabs.ExtractCab(cabFileName, cabFolder); } if (testData.NumberOfScriptResults > 0) { String analysisFolder = index.GetCabFolder(product, file, theEvent, cab) + "\\analysis"; if (!Directory.Exists(analysisFolder)) { Directory.CreateDirectory(analysisFolder); } for (int scriptCount = 0; scriptCount < testData.NumberOfScriptResults; scriptCount++) { CreateScriptFile(scriptCount, cab.Id, analysisFolder, scriptRand.Next(5), CultureInfo.InvariantCulture, 2, testData.ScriptFileSize); } } StackHashNotes cabNotes = index.GetCabNotes(product, file, theEvent, cab); for (int q = 0; q < testData.NumberOfCabNotes; q++) { StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is a cab note" + q.ToString(CultureInfo.InvariantCulture)); // Don't add duplicate cab notes in the SQL index. The XML index may contain duplicates. if (index.IndexType == ErrorIndexType.Xml || !cabNotes.ContainsNote(note)) { index.AddCabNote(product, file, theEvent, cab, note); } } } StackHashNotes eventNotes = index.GetEventNotes(product, file, theEvent); for (int p = 0; p < testData.NumberOfEventNotes; p++) { StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is an event note" + p.ToString(CultureInfo.InvariantCulture)); // Don't add duplicate event notes in the SQL index. The XML index may contain duplicates. if (index.IndexType == ErrorIndexType.Xml || !eventNotes.ContainsNote(note)) { index.AddEventNote(product, file, theEvent, note); } } } } index.UpdateProductStatistics(product); } }
} // Private constructor because this is a static class. public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData) { CreateTestIndex(index, testData, false); }
public void RunBugReportSpecificFileProgressCheckManyEventsAbortTest() { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(ErrorIndexType.SqlExpress); GetContextBugTrackerPlugInSettingsResponse resp = m_Utils.GetContextBugTrackerPlugInSettings(0); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings.PlugInSettings); Assert.AreEqual(0, resp.BugTrackerPlugInSettings.PlugInSettings.Count); resp.BugTrackerPlugInSettings.PlugInSettings.Add(new StackHashBugTrackerPlugIn()); resp.BugTrackerPlugInSettings.PlugInSettings[0].Enabled = true; resp.BugTrackerPlugInSettings.PlugInSettings[0].Name = "TestPlugIn"; resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties = new StackHashNameValueCollection(); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam1", Value = "TestValue1" }); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam2", Value = "TestValue2" }); m_Utils.SetContextBugTrackerPlugInSettings(0, resp.BugTrackerPlugInSettings); m_Utils.RestartService(); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 200; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; StackHashBugReportDataCollection bugReportDataCollection = new StackHashBugReportDataCollection(); bugReportDataCollection.Add(new StackHashBugReportData() { Product = products[0].Product, File = files[0], TheEvent = null, Cab = null, ScriptName = null, Options = StackHashReportOptions.IncludeAllObjects }); m_Utils.RunBugReportTask(0, bugReportDataCollection, 0, false); // Don't wait. m_Utils.WaitForBugReportProgress(30000); m_Utils.AbortTask(0, StackHashTaskType.BugReportTask); m_Utils.WaitForBugReportTaskCompleted(30000); // Check the progress reports. Assert.AreEqual(true, m_Utils.BugReportProgressReports.Count < 100); long lastProgress = -1; foreach (StackHashAdminReport report in m_Utils.BugReportProgressReports) { StackHashBugReportProgressAdminReport progress = report as StackHashBugReportProgressAdminReport; Assert.AreEqual(true, progress.CurrentEvent > lastProgress); Assert.AreEqual(true, progress.CurrentEvent < progress.TotalEvents); lastProgress = progress.CurrentEvent; } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
// Get the public void productInfoGet(ErrorIndexType indexType, int numProducts, bool resetService) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = 0; testIndexData.NumberOfEvents = 0; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(false, productInfo.SynchronizeEnabled); Assert.AreEqual(null, productInfo.ProductSyncData); } // Now enable the products for sync. foreach (StackHashProductInfo productInfo in getProductsResp.Products) { m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(true, productInfo.SynchronizeEnabled); Assert.AreNotEqual(null, productInfo.ProductSyncData); Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId); } foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProductSyncData syncData = new StackHashProductSyncData(); syncData.ProductId = productInfo.Product.Id; m_Utils.SetProductSynchronizationData(0, syncData); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); if (resetService) { m_Utils.RestartService(); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(true, productInfo.SynchronizeEnabled); Assert.AreNotEqual(null, productInfo.ProductSyncData); Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId); } // Disable all products for sync. foreach (StackHashProductInfo productInfo in getProductsResp.Products) { m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, false); } getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(false, productInfo.SynchronizeEnabled); Assert.AreEqual(null, productInfo.ProductSyncData); } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public GetWindowedEventPackageResponse windowSearch(ErrorIndexType errorIndexType, StackHashTestIndexData testIndexData, StackHashSearchCriteriaCollection allSearchCriteria, long startRow, long numRows, StackHashSortOrderCollection sortOrder, StackHashSearchDirection direction, bool countAllMatches) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(errorIndexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = errorIndexType; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { m_Utils.SetProductSynchronizationState(0, product.Product.Id, true); } GetWindowedEventPackageResponse eventPackages = m_Utils.GetWindowedEvents(0, allSearchCriteria, startRow, numRows, sortOrder, direction, countAllMatches); return(eventPackages); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(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); } } }
public void getProductsNProductsNFilesNEvents(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreNotEqual(new DateTime(0), getProductsResp.LastSiteUpdateTime); Assert.AreEqual(true, Math.Abs((DateTime.Now - getProductsResp.LastSiteUpdateTime).TotalDays) <= 15); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); int productId = 1; int fileId = 1; int eventId = 1; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(productId++, product.Id); GetFilesResponse getFilesResp = m_Utils.GetFiles(0, product); Assert.AreEqual(numFiles, getFilesResp.Files.Count()); foreach (StackHashFile file in getFilesResp.Files) { Assert.AreEqual(fileId++, file.Id); GetEventsResponse getEventsResp = m_Utils.GetEvents(0, product, file); Assert.AreEqual(numEvents, getEventsResp.Events.Count()); foreach (StackHashEvent theEvent in getEventsResp.Events) { Assert.AreEqual(eventId++, theEvent.Id); GetEventPackageResponse getEventPackageResp = m_Utils.GetEventPackage(0, product, file, theEvent); Assert.AreEqual(numCabs, getEventPackageResp.EventPackage.Cabs.Count); Assert.AreEqual(numEventInfos, getEventPackageResp.EventPackage.EventInfoList.Count); } } } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void streamCabs(ErrorIndexType errorIndexType, bool useBigCabs, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, String fileName, String cabFileName) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(errorIndexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = errorIndexType; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; testIndexData.UseLargeCab = useBigCabs; testIndexData.CabFileName = cabFileName; m_Utils.CreateTestIndex(0, testIndexData); // Find the cab. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); int productId = 1; int fileId = 1; int eventId = 1; try { foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(productId++, product.Id); GetFilesResponse getFilesResp = m_Utils.GetFiles(0, product); Assert.AreEqual(numFiles, getFilesResp.Files.Count()); foreach (StackHashFile file in getFilesResp.Files) { Assert.AreEqual(fileId++, file.Id); GetEventsResponse getEventsResp = m_Utils.GetEvents(0, product, file); Assert.AreEqual(numEvents, getEventsResp.Events.Count()); foreach (StackHashEvent theEvent in getEventsResp.Events) { Assert.AreEqual(eventId++, theEvent.Id); GetEventPackageResponse getEventPackageResp = m_Utils.GetEventPackage(0, product, file, theEvent); Assert.AreEqual(numCabs, getEventPackageResp.EventPackage.Cabs.Count); Assert.AreEqual(numEventInfos, getEventPackageResp.EventPackage.EventInfoList.Count); // Stream the cabs. foreach (StackHashCabPackage cab in getEventPackageResp.EventPackage.Cabs) { String tempCabFileName = Path.GetTempFileName(); File.Delete(tempCabFileName); m_Utils.GetCab(tempCabFileName, 0, product, file, theEvent, cab.Cab, fileName); try { if (String.IsNullOrEmpty(fileName)) { Assert.AreEqual(true, File.Exists(tempCabFileName)); FileInfo fileInfo = new FileInfo(tempCabFileName); if (useBigCabs) { Assert.AreEqual(true, fileInfo.Length > 64 * 1024); } else if (cabFileName != null) { FileInfo sourceCabFileInfo = new FileInfo(cabFileName); Assert.AreEqual(true, fileInfo.Length == sourceCabFileInfo.Length); Assert.AreEqual(true, fileInfo.Length > 20000000); } else { Assert.AreEqual(true, fileInfo.Length <= 64 * 1024); } } else if (String.Compare("version.txt", fileName, StringComparison.OrdinalIgnoreCase) == 0) { String allText = File.ReadAllText(tempCabFileName); Assert.AreEqual(true, allText.Contains("Architecture:")); } } finally { File.Delete(tempCabFileName); } } } } } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public void MoveNonEmptyIndex() { try { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); SetStackHashPropertiesResponse newContextResp = m_Utils.CreateAndSetNewContext(); // Create a context and give it a non-default name. GetStackHashPropertiesResponse getResp = m_Utils.GetContextSettings(); Assert.AreEqual(ErrorIndexStatus.NotCreated, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); m_Utils.ActivateContext(0); // Create the index. getResp = m_Utils.GetContextSettings(); Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); // Create a small error index. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 1; testIndexData.NumberOfCabs = 1; m_Utils.CreateTestIndex(0, testIndexData); String originalIndexPath = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder; String originalIndexName = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name; String indexName = "NewIndexName"; String testPath = "c:\\stackhashunittests\\testindex\\"; // TODO: This won't work if testing across machines. // Make sure the destination folder does not exist. String fullDestPath = Path.Combine(testPath, indexName); if (Directory.Exists(fullDestPath)) { PathUtils.DeleteDirectory(fullDestPath, true); } m_Utils.DeactivateContext(0); // Must be inactive before the move. m_Utils.MoveIndex(0, testPath, indexName, 20000, newContextResp.Settings.ContextCollection[0].SqlSettings); m_Utils.ActivateContext(0); // Must be inactive before the move. Assert.AreEqual(false, Directory.Exists(Path.Combine(originalIndexPath, originalIndexName))); Assert.AreEqual(true, Directory.Exists(Path.Combine(testPath, indexName))); Assert.AreEqual(null, m_Utils.MoveCompleteAdminReport.LastException); Assert.AreEqual(StackHashAsyncOperationResult.Success, m_Utils.MoveCompleteAdminReport.ResultData); getResp = m_Utils.GetContextSettings(); Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status); Assert.AreEqual(testPath.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant()); Assert.AreEqual(indexName.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant()); // Check that the products etc.. have been moved. GetProductsResponse products = m_Utils.GetProducts(0); Assert.AreEqual(1, products.Products.Count); foreach (StackHashProductInfo productInfo in products.Products) { StackHashProduct product = productInfo.Product; GetFilesResponse files = m_Utils.GetFiles(0, product); Assert.AreEqual(1, files.Files.Count); foreach (StackHashFile file in files.Files) { GetEventsResponse events = m_Utils.GetEvents(0, product, file); Assert.AreEqual(1, events.Events.Count); foreach (StackHashEvent theEvent in events.Events) { GetEventPackageResponse eventPackage = m_Utils.GetEventPackage(0, product, file, theEvent); Assert.AreEqual(1, eventPackage.EventPackage.Cabs.Count); Assert.AreEqual(1, eventPackage.EventPackage.EventInfoList.Count); } } } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public void AutoScriptOnOneCabAlreadyRunButNewerVersion() { // If the auto task sees the AutoScript.log file exists and has the same // version as the current AutoScript.xml then it shouldn't run it again. // Determine this by checking the file time after a second run. // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters(); // Standard task parameters. analyzeParams.IsBackgroundTask = true; analyzeParams.Name = "TestRunOneTask"; analyzeParams.RunInParallel = false; analyzeParams.UseSeparateThread = true; analyzeParams.AnalysisSettings = new StackHashAnalysisSettings(); analyzeParams.AnalysisSettings.ForceRerun = true; analyzeParams.ContextId = 0; analyzeParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); analyzeParams.Debugger = m_Debugger; analyzeParams.DebuggerSettings = m_DebuggerSettings; analyzeParams.TheScriptManager = scriptManager; analyzeParams.TheScriptResultsManager = scriptResultsManager; int productId = 1; analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection(); analyzeParams.ProductsToSynchronize.Add(new StackHashProductSyncData(productId)); analyzeParams.ErrorIndex = errorIndex; // Create the task and run it. AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); StackHashProductCollection products = errorIndex.LoadProductList(); StackHashFileCollection files = errorIndex.LoadFileList(products[0]); StackHashEventCollection events = errorIndex.LoadEventList(products[0], files[0]); StackHashCabCollection cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashScriptResult script1 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); // Wait for 1 second - so file time granularity exceeded. Thread.Sleep(1000); // Change the version on the autoscript. StackHashScriptSettings settings = scriptManager.LoadScript("AutoScript"); settings.LastModifiedDate = DateTime.Now; scriptManager.AddScript(settings, true, true); // Now run the task again. analyzeTask = new AnalyzeTask(analyzeParams); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted); // Refresh the cab list data. cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; Assert.AreEqual("not available", analysis.SystemUpTime); Assert.AreEqual("0 days 0:00:15.000", analysis.ProcessUpTime); Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion); StackHashScriptResult script2 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); Assert.AreEqual(true, script2.RunDate > script1.RunDate); }
public void RunBugReportSpecificEvent() { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(ErrorIndexType.SqlExpress); GetContextBugTrackerPlugInSettingsResponse resp = m_Utils.GetContextBugTrackerPlugInSettings(0); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings.PlugInSettings); Assert.AreEqual(0, resp.BugTrackerPlugInSettings.PlugInSettings.Count); resp.BugTrackerPlugInSettings.PlugInSettings.Add(new StackHashBugTrackerPlugIn()); resp.BugTrackerPlugInSettings.PlugInSettings[0].Enabled = true; resp.BugTrackerPlugInSettings.PlugInSettings[0].Name = "TestPlugIn"; resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties = new StackHashNameValueCollection(); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam1", Value = "TestValue1" }); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam2", Value = "TestValue2" }); m_Utils.SetContextBugTrackerPlugInSettings(0, resp.BugTrackerPlugInSettings); m_Utils.RestartService(); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 1; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; StackHashBugReportDataCollection bugReportDataCollection = new StackHashBugReportDataCollection(); bugReportDataCollection.Add(new StackHashBugReportData() { Product = products[0].Product, File = files[0], TheEvent = events[0].EventData, Cab = null, ScriptName = null, Options = StackHashReportOptions.IncludeAllObjects }); m_Utils.RunBugReportTask(0, bugReportDataCollection, 30000, true); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public void getProductEventPackages(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashsoaktest\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); try { DateTime startTime = DateTime.Now; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; GetProductEventPackageResponse response = m_Utils.GetProductEventPackages(0, product); Assert.AreEqual(1 * numFiles * numEvents, response.EventPackages.Count); foreach (StackHashEventPackage package in response.EventPackages) { Assert.AreEqual(numCabs, package.Cabs.Count); Assert.AreEqual(numEventInfos, package.EventInfoList.Count); } } DateTime endTime = DateTime.Now; TimeSpan duration = endTime - startTime; Console.WriteLine("Duration: {0}", duration); m_Utils.RestartService(); startTime = DateTime.Now; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; GetProductEventPackageResponse response = m_Utils.GetProductEventPackages(0, product); Assert.AreEqual(1 * numFiles * numEvents, response.EventPackages.Count); foreach (StackHashEventPackage package in response.EventPackages) { Assert.AreEqual(numCabs, package.Cabs.Count); Assert.AreEqual(numEventInfos, package.EventInfoList.Count); } } endTime = DateTime.Now; duration = endTime - startTime; Console.WriteLine("Duration: {0}", duration); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }