/// <summary> /// Gets all the event data stored about a particular event. /// </summary> /// <param name="requestData">Request data.</param> /// <returns>Event package included per instance and cab data.</returns> public GetEventPackageResponse GetEventPackage(GetEventPackageRequest requestData) { if (requestData == null) { throw new ArgumentNullException("requestData"); } GetEventPackageResponse resp = new GetEventPackageResponse(); StackHashEventPackage eventPackage = StaticObjects.TheStaticObjects.TheController.GetEventPackage( requestData.ContextId, requestData.Product, requestData.File, requestData.Event); resp.EventPackage = eventPackage; resp.Product = requestData.Product; resp.File = requestData.File; resp.Event = requestData.Event; resp.ResultData = new StackHashServiceResultData( StackHashServiceResult.Success, s_OperationSuccessful, null); return(resp); }
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 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); } }