private Tuple <List <GenericContent>, int, int> InitCarsForUnprocessedTests() { // init: create some cars var container = new Folder(TestRoot); container.Name = "unprocessedtest-" + Guid.NewGuid().ToString(); container.Save(); var lastActivityId = IndexingActivityManager.GetLastActivityId(); var carlist = new List <GenericContent>(); for (var i = 0; i < 10; i++) { var car = new GenericContent(container, "Car"); car.Name = "testcar" + i.ToString(); car.Save(); carlist.Add(car); } var expectedLastActivityId = IndexingActivityManager.GetLastActivityId(); // check1: cars can be found in the index for (var i = 0; i < carlist.Count; i++) { Assert.IsTrue(CheckCarInIndex(carlist[i].Id), "Car cannot be found in index after init."); } return(new Tuple <List <GenericContent>, int, int>(carlist, lastActivityId, expectedLastActivityId)); }
[Description("An activity execution with update activity after delete activity not throws any exception.")] // ?? public void Indexing_WritingGapAndGettingUnprocessedActivitiesWithGap() { var content = Content.CreateNew("Car", TestRoot, "Indexing_WritingGapAndGettingUnprocessedActivitiesWithGap"); var handler = (GenericContent)content.ContentHandler; content.Save(); var id = content.Id; for (int i = 0; i < 10; i++) { handler.Index++; handler.Save(); } var maxActivityIdSave = MissingActivityHandler.MaxActivityId; var savedGap = MissingActivityHandler.GetGap(); try { MissingActivityHandler.MaxActivityId -= 2; MissingActivityHandler.SetGap(new List <int>(new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 7 })); EnsureWriterHasChanges(); //LuceneManager.ApplyChanges(); var luceneManagerAcc = new PrivateType(typeof(LuceneManager)); luceneManagerAcc.InvokeStatic("Commit", BindingFlags.Static | BindingFlags.NonPublic, new object[] { true }); IDictionary <string, string> cud; using (var readerFrame = LuceneManager.GetIndexReaderFrame()) { cud = readerFrame.IndexReader.GetCommitUserData(); } var lastIdStr = cud[IndexManager.LastActivityIdKey]; var missingStr = cud[IndexManager.MissingActivitiesKey]; // [0]: {[LastActivityId, 10]} // [1]: {[MissingActivities, 8,7,5]} Assert.IsTrue(cud[IndexManager.LastActivityIdKey] == MissingActivityHandler.MaxActivityId.ToString(), "#1"); Assert.IsTrue(cud[IndexManager.MissingActivitiesKey] == String.Join(",", new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 7 }), "#2"); var mid = MissingActivityHandler.MaxActivityId; var activities = IndexingActivityManager.GetUnprocessedActivities(new[] { mid - 2, mid - 3, mid - 5 }); var exp = String.Join(",", new[] { mid - 5, mid - 3, mid - 2 }); var cur = String.Join(",", activities.Select(t => t.IndexingActivityId)); Assert.AreEqual(exp, cur); var max = 0; activities = IndexingActivityManager.GetUnprocessedActivities(mid, out max); exp = String.Join(",", new[] { mid + 1, mid + 2 }); cur = String.Join(",", activities.Select(t => t.IndexingActivityId)); Assert.AreEqual(exp, cur); } finally { MissingActivityHandler.SetGap(savedGap); MissingActivityHandler.MaxActivityId = maxActivityIdSave; } }
[Description("An activity execution with update activity after delete activity not throws any exception.")] // ?? public void Indexing_ActivitesWithMissingVersion() { var content = Content.CreateNew("Car", TestRoot, "Car_Indexing_ActivitesWithMissingVersion"); var handler = (GenericContent)content.ContentHandler; //handler.VersioningMode = VersioningType.None; content.Save(); var id = content.Id; LuceneManager.UnregisterActivity(0, false); IndexingActivity[] act = new IndexingActivity[3]; act[0] = new IndexingActivity { ActivityType = IndexingActivityType.RemoveDocument, NodeId = _fakeId, VersionId = _fakeId }; act[1] = new IndexingActivity { ActivityType = IndexingActivityType.UpdateDocument, NodeId = _fakeId, VersionId = _fakeId }; act[2] = new IndexingActivity { ActivityType = IndexingActivityType.AddDocument, NodeId = _fakeId, VersionId = _fakeId }; try { using (var context = new IndexingDataContext()) { foreach (var a in act) { context.IndexingActivities.InsertOnSubmit(a); context.SubmitChanges(); } } var max = 0; var activities = IndexingActivityManager.GetUnprocessedActivities(act[2].IndexingActivityId - 1, out max); foreach (var a in activities) { IndexingActivityManager.ExecuteActivityDirect(a); } } finally { RemoveFakeTestActivity(); } }