public void IndexingHistory_FixDeleteUpdateOverlap() { // delete overlaps with update var fieldvalue1 = "IndexingHistoryFixDeleteAddOverlap"; var history = LuceneManager._history; var car = new GenericContent(TestRoot, "Car"); car.Name = Guid.NewGuid().ToString(); car.Save(); var id = car.Id; // init 2 var node2 = Node.LoadNode(id); node2["Description"] = fieldvalue1; node2.Save(); // delete changes from index DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId); DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId); var docInfo2 = IndexDocumentInfo.Create(node2); var docData2 = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null); var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2); // init 1 var node1 = Node.LoadNode(id); node1.ForceDelete(); // delete changes from index DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId); DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId); // 1 check indexing history var versionId1 = node2.VersionId; var term = new Term(LucObject.FieldName.VersionId, Lucene.Net.Util.NumericUtils.IntToPrefixCoded(versionId1)); LuceneManager._history.ProcessDelete(new Term[] { term }); // timestamp in indexing history should change var actTimestamp1 = history.Get(versionId1); Assert.AreEqual(long.MaxValue, actTimestamp1, "Timestamp in indexing history did not change."); // 2 check indexing history var versionId2 = history.GetVersionId(document2); var timestamp2 = history.GetTimestamp(document2); var historyOk = LuceneManager._history.CheckForUpdate(versionId2, timestamp2); // timestamp in indexing history should not change var actTimestamp2 = history.Get(versionId2); Assert.AreNotEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have."); Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true."); // 2 does not continue, returns // 1 deletes index LuceneManager.SetFlagsForDelete(term); LuceneManager._writer.DeleteDocuments(term); var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count; // check indexing occured correctly // thread 1 deletes from index Assert.AreEqual(0, firstfound); }
public void IndexingHistory_FixAddUpdateOverlap() { // add overlaps with update var fieldvalue1 = "IndexingHistoryFixAddUpdateOverlapFirst"; var fieldvalue2 = "IndexingHistoryFixAddUpdateOverlapSecond"; var history = LuceneManager._history; var car = new GenericContent(TestRoot, "Car"); car.Name = Guid.NewGuid().ToString(); car.Save(); var id = car.Id; // init 1 var node1 = Node.LoadNode(id); node1["Description"] = fieldvalue1; node1.Save(); // delete changes from index DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId); DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId); var docInfo1 = IndexDocumentInfo.Create(node1); var docData1 = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null); var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1); // init 2 var node2 = Node.LoadNode(id); node2["Description"] = fieldvalue2; node2.Save(); // delete changes from index DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId); DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId); var docInfo2 = IndexDocumentInfo.Create(node2); var docData2 = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null); var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2); // 1 check indexing history var versionId1 = history.GetVersionId(document1); var timestamp1 = history.GetTimestamp(document1); var historyOk = LuceneManager._history.CheckForAdd(versionId1, timestamp1); // timestamp in indexing history should be the newest var actTimestamp1 = history.Get(versionId1); Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change."); Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true."); // 2 check indexing history var versionId2 = history.GetVersionId(document2); var timestamp2 = history.GetTimestamp(document2); historyOk = LuceneManager._history.CheckForUpdate(versionId2, timestamp2); // timestamp in indexing history should change var actTimestamp2 = history.Get(versionId2); Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history did not change."); Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true."); // 2 index var document = document2; var updateTerm = UpdateDocumentActivity.GetIdTerm(document); LuceneManager.SetFlagsForUpdate(document); LuceneManager._writer.UpdateDocument(updateTerm, document); var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count; var secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count; // check indexing occured correctly // thread 2 writes values in index Assert.AreEqual(0, firstfound); Assert.AreEqual(1, secondfound); // 1 index document = document1; LuceneManager._writer.AddDocument(document); firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count; secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count; // check indexing occured correctly // thread 1 adds values to index, duplication occurs Assert.AreEqual(1, firstfound); Assert.AreEqual(1, secondfound); // 1 detects problem var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1); Assert.IsTrue(detectChange1, "Thread 1 did not detect indexing overlapping although it should have."); // 2 detects no problem var detectChange2 = history.CheckHistoryChange(versionId2, timestamp2); Assert.IsFalse(detectChange2, "Thread 2 detected indexing overlapping although it should not have."); // 1 fixes index LuceneManager.RefreshDocument(versionId1); firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count; secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count; Assert.AreEqual(0, firstfound); Assert.AreEqual(1, secondfound); var node = Node.LoadNode(id); node.ForceDelete(); }
public void IndexingHistory_FixAddAddOverlap() { // add overlaps with add var fieldvalue1 = "IndexingHistoryFixAddAddOverlap"; var history = LuceneManager._history; var car = new GenericContent(TestRoot, "Car"); car.Name = Guid.NewGuid().ToString(); car.Save(); var id = car.Id; // init 1 & 2 var node1 = Node.LoadNode(id); node1["Description"] = fieldvalue1; node1.Save(); // delete changes from index DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId); DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId); var docInfo1 = IndexDocumentInfo.Create(node1); var docData1 = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null); var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1); // 1 check indexing history var versionId1 = history.GetVersionId(document1); var timestamp1 = history.GetTimestamp(document1); var historyOk = LuceneManager._history.CheckForAdd(versionId1, timestamp1); // timestamp in indexing history should be the newest var actTimestamp1 = history.Get(versionId1); Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change."); Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true."); // 2 check indexing history var versionId2 = history.GetVersionId(document1); var timestamp2 = history.GetTimestamp(document1); historyOk = LuceneManager._history.CheckForAdd(versionId2, timestamp2); // timestamp in indexing history should not change var actTimestamp2 = history.Get(versionId2); Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have."); Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true."); // 2 does not continue, returns // 1 index var document = document1; LuceneManager._writer.AddDocument(document); var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count; // check indexing occured correctly // thread 1 adds values to index Assert.AreEqual(1, firstfound); // 1 detects no problem var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1); Assert.IsFalse(detectChange1, "Thread 1 detected indexing overlapping although it should not have."); var node = Node.LoadNode(id); node.ForceDelete(); }