public void Indexing_HandlingGap() { //if (MissingActivityHandler.GetGap().Count != 0) // Assert.Inconclusive("This test cannot run correctly with any gap."); MissingActivityHandler.SetGap(new List <int>()); var savedMaxActivityId = MissingActivityHandler.MaxActivityId; MissingActivityHandler.MaxActivityId = 0; try { for (int i = 1; i <= MissingActivityHandler.GapSegments * 2; i++) { var currentActivityId = i * 3; MissingActivityHandler.RemoveActivityAndAddGap(currentActivityId); Assert.IsTrue(MissingActivityHandler.MaxActivityId == currentActivityId, String.Format("MaxActivityId is {0}, expected: {1}", MissingActivityHandler.MaxActivityId, currentActivityId)); if (i % 2 == 0) { MissingActivityHandler.GetOldestGapAndMoveToNext(); } } var expectedGapSize = MissingActivityHandler.GetGap().Count; for (int i = 1; i <= MissingActivityHandler.MaxActivityId; i += 3) { MissingActivityHandler.RemoveActivityAndAddGap(i); var gapSize = MissingActivityHandler.GetGap().Count; --expectedGapSize; Assert.IsTrue(gapSize == expectedGapSize, String.Format("Gap size is {0}, expected: {1}", gapSize, expectedGapSize)); } var gap = MissingActivityHandler.GetGap(); Assert.IsTrue(gap.Count == MissingActivityHandler.GapSegments * 2, ""); gap.Sort(); var expectedGap = "2,5,8,11,14,17,20,23,26,29,32,35,38,41,44,47,50,53,56,59"; var gapstring = String.Join(",", gap); Assert.IsTrue(gapstring == expectedGap, String.Format("Gap size is {0}, expected: {1}", gapstring, expectedGap)); } finally { MissingActivityHandler.SetGap(new List <int>()); MissingActivityHandler.MaxActivityId = savedMaxActivityId; } }
public void Indexing_ExecuteLostIndexingActivities() { 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] }; MissingActivityHandler.SetGap(activitiesToDelete.Select(a => a.IndexingActivityId).ToList()); // 0,2,5,7,8 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 } } // make sure to move current gap to oldest gap, since always the oldest gap will get processed for (var i = 0; i < MissingActivityHandler.GapSegments - 1; i++) { MissingActivityHandler.GetOldestGapAndMoveToNext(); } // execute unprocessed indexing tasks LuceneManager.ExecuteLostIndexingActivities(); // check: all cars can be found in the index again for (var i = 0; i < carlist.Count; i++) { Assert.IsTrue(CheckCarInIndex(carlist[i].Id), "ExecuteLostIndexingActivities did not repair lost document."); } Assert.AreEqual(expectedLastActivityId, MissingActivityHandler.MaxActivityId, "Maxtaskid is not what is expected."); Assert.AreEqual(0, MissingActivityHandler.GetGap().Count, "Gap size is not 0."); } }