[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; } }
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."); } }
public void Indexing_PlayMissingactivitiesTwoTimes() { var content = Content.CreateNew("Car", TestRoot, "Indexing_PlayMissingactivitiesTwoTimes"); 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; try { MissingActivityHandler.MaxActivityId -= 3; MissingActivityHandler.SetGap(new List <int>(new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 6, maxActivityIdSave - 7 })); // reset indexing history, so that executeunprocessedactivities will actually execute adddocument as it should be tested ResetIndexingHistory(); LuceneManager.ExecuteUnprocessedIndexingActivities(null, false); // call it with false, so last persisted maxactivityid will not overwrite the one we set above MissingActivityHandler.MaxActivityId -= 3; MissingActivityHandler.SetGap(new List <int>(new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 6, maxActivityIdSave - 7 })); // reset indexing history, so that executeunprocessedactivities will actually execute adddocument as it should be tested ResetIndexingHistory(); LuceneManager.ExecuteUnprocessedIndexingActivities(null, false); // call it with false, so last persisted maxactivityid will not overwrite the one we set above Assert.IsTrue(maxActivityIdSave == MissingActivityHandler.MaxActivityId, string.Format("MissingActivityHandler.MaxActivityId is {0}, expected {1}", MissingActivityHandler.MaxActivityId, maxActivityIdSave)); var gap = MissingActivityHandler.GetGap(); var gapString = string.Join(", ", gap); Assert.IsTrue(gap.Count == 0, string.Format("The gap is {0}, expected: empty", gapString)); } finally { MissingActivityHandler.MaxActivityId = maxActivityIdSave; } var result = ContentQuery.Query("Name:Indexing_PlayMissingactivitiesTwoTimes .AUTOFILTERS:OFF"); Assert.IsTrue(result.Count == 1, string.Format("The result count is {0}, expected: 1", result.Count)); }
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_PlayMissingactivitiesTwoTimes() { var content = Content.CreateNew("Car", TestRoot, "Indexing_PlayMissingactivitiesTwoTimes"); 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; try { MissingActivityHandler.MaxActivityId -= 3; MissingActivityHandler.SetGap(new List <int>(new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 6, maxActivityIdSave - 7 })); LuceneManager.ExecuteUnprocessedIndexingActivities(null); MissingActivityHandler.MaxActivityId -= 3; MissingActivityHandler.SetGap(new List <int>(new[] { maxActivityIdSave - 4, maxActivityIdSave - 5, maxActivityIdSave - 6, maxActivityIdSave - 7 })); LuceneManager.ExecuteUnprocessedIndexingActivities(null); Assert.IsTrue(maxActivityIdSave == MissingActivityHandler.MaxActivityId, string.Format("MissingActivityHandler.MaxActivityId is {0}, expected {1}", maxActivityIdSave, MissingActivityHandler.MaxActivityId)); var gap = MissingActivityHandler.GetGap(); var gapString = string.Join(", ", gap); Assert.IsTrue(gap.Count == 0, string.Format("The gap is {0}, expected: empty", gapString)); } finally { MissingActivityHandler.MaxActivityId = maxActivityIdSave; } var result = ContentQuery.Query("Name:Indexing_PlayMissingactivitiesTwoTimes .AUTOFILTERS:OFF"); Assert.IsTrue(result.Count == 1, string.Format("The result count is {0}, expected: 1", result.Count)); }