Пример #1
0
		public virtual void  TestSegmentsChecksumError()
		{
			Directory dir = new MockRAMDirectory();
			
			IndexWriter writer = null;
			
			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
			
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			Assert.IsTrue(gen > 1, "segment generation should be > 1 but got " + gen);
			
			System.String segmentsFileName = SegmentInfos.GetCurrentSegmentFileName(dir);
			IndexInput in_Renamed = dir.OpenInput(segmentsFileName);
			IndexOutput out_Renamed = dir.CreateOutput(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1 + gen));
			out_Renamed.CopyBytes(in_Renamed, in_Renamed.Length() - 1);
			byte b = in_Renamed.ReadByte();
			out_Renamed.WriteByte((byte) (1 + b));
			out_Renamed.Close();
			in_Renamed.Close();
			
			IndexReader reader = null;
			try
			{
				reader = IndexReader.Open(dir);
			}
			catch (System.IO.IOException e)
			{
				System.Console.Out.WriteLine(e.StackTrace);
				Assert.Fail("segmentInfos failed to retry fallback to correct segments_N file");
			}
			reader.Close();
		}