public void Indexing_ExecuteUnprocessedIndexingActivities() { lock (LuceneManager._executingUnprocessedIndexingActivitiesLock) // make sure indexhealthmonitor will not overlap { var initInfo = InitCarsForUnprocessedTests(); var carlist = initInfo.Item1; var lastActivityId = initInfo.Item2; var expectedLastActivityId = initInfo.Item3; // generate a gap and delete corresponding documents from index var activities = GetCarActivities(lastActivityId); var activitiesToDelete = new IndexingActivity[] { activities[0], activities[2], activities[5], activities[7], activities[8], activities[9] }; MissingActivityHandler.SetGap(activitiesToDelete.Take(3).Select(a => a.IndexingActivityId).ToList()); // 0,2,5 will be missing MissingActivityHandler.MaxActivityId = activities[6].IndexingActivityId; // 7,8,9 will be missing // commit gap and maxactivityid to the index EnsureWriterHasChanges(); LuceneManager.Commit(true); foreach (var activity in activitiesToDelete) { DeleteVersionFromIndex(activity.VersionId); DeleteVersionIdFromIndexingHistory(activity.VersionId); } // check: cars deleted can NOT be found in the index for (var i = 0; i < carlist.Count; i++) { var id = carlist[i].Id; if (activitiesToDelete.Select(a => a.NodeId).Contains(id)) { Assert.IsFalse(CheckCarInIndex(id), "Deleted car can still be found in the index."); // deleted car should not be in index } else { Assert.IsTrue(CheckCarInIndex(id), "Untouched car can not be found in the index."); // untouched car should still be in index } } // execute unprocessed indexing tasks LuceneManager.ExecuteUnprocessedIndexingActivities(null, true); // check: all cars can be found in the index again for (var i = 0; i < carlist.Count; i++) { Assert.IsTrue(CheckCarInIndex(carlist[i].Id), "ExecuteUnprocessedIndexingActivities did not repair lost document."); } Assert.AreEqual(expectedLastActivityId, MissingActivityHandler.MaxActivityId, "Maxtaskid was not updated correctly."); Assert.AreEqual(0, MissingActivityHandler.GetGap().Count, "Gap size is not 0."); } }
[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(); } }
public static T CreateFromIndexingActivity <T>(IndexingActivity activity) where T : LuceneIndexingActivity, new() { T result = new T(); result.ActivityId = activity.IndexingActivityId; result.IndexingActivityType = activity.ActivityType; result.SingleVersion = activity.SingleVersion; result.MoveOrRename = activity.MoveOrRename.HasValue ? activity.MoveOrRename.Value : false; result.Path = activity.Path; result.VersionId = activity.VersionId; result.NodeId = activity.NodeId; if (activity.IndexDocumentData != null) { var lucDocAct = result as LuceneDocumentActivity; if (lucDocAct != null) { lucDocAct.IndexDocumentData = activity.IndexDocumentData; } } return(result); }