public virtual void TestNoExtraNoise() { Directory dir = NewDirectory(); IndexWriter writer; IndexWriterConfig c = new IndexWriterConfig(TEST_VERSION_CURRENT, new ThrowingAnalyzer()); ByteArrayOutputStream infoBytes = new ByteArrayOutputStream(); StreamWriter infoPrintStream = new StreamWriter(infoBytes, Encoding.UTF8); PrintStreamInfoStream printStreamInfoStream = new PrintStreamInfoStream(infoPrintStream); c.SetInfoStream(printStreamInfoStream); writer = new IndexWriter(dir, c); Document doc = new Document(); doc.Add(NewField("boringFieldName", "aaa ", StoredTextType)); try { writer.AddDocument(doc); } #pragma warning disable 168 catch (BadNews badNews) #pragma warning restore 168 { Assert.Fail("Unwanted exception"); } infoPrintStream.Flush(); string infoStream = Encoding.UTF8.GetString(infoBytes.ToArray()); Assert.IsFalse(infoStream.Contains("boringFieldName")); writer.Dispose(); dir.Dispose(); }
public virtual void TestInfoStreamGetsFieldName() { Directory dir = NewDirectory(); IndexWriter writer; IndexWriterConfig c = new IndexWriterConfig(TEST_VERSION_CURRENT, new ThrowingAnalyzer()); ByteArrayOutputStream infoBytes = new ByteArrayOutputStream(); StreamWriter infoPrintStream = new StreamWriter(infoBytes, Encoding.UTF8); PrintStreamInfoStream printStreamInfoStream = new PrintStreamInfoStream(infoPrintStream); c.SetInfoStream(printStreamInfoStream); writer = new IndexWriter(dir, c); Document doc = new Document(); doc.Add(NewField("distinctiveFieldName", "aaa ", StoredTextType)); try { writer.AddDocument(doc); Assert.Fail("Failed to fail."); } catch (BadNews) { infoPrintStream.Flush(); string infoStream = Encoding.UTF8.GetString(infoBytes.ToArray()); Assert.IsTrue(infoStream.Contains("distinctiveFieldName")); } writer.Dispose(); dir.Dispose(); }
public virtual void TestInfoStreamGetsFieldName() { Directory dir = NewDirectory(); IndexWriter writer; IndexWriterConfig c = new IndexWriterConfig(TEST_VERSION_CURRENT, new ThrowingAnalyzer()); ByteArrayOutputStream infoBytes = new ByteArrayOutputStream(); StreamWriter infoPrintStream = new StreamWriter(infoBytes, Encoding.UTF8); PrintStreamInfoStream printStreamInfoStream = new PrintStreamInfoStream(infoPrintStream); c.InfoStream = printStreamInfoStream; writer = new IndexWriter(dir, c); Document doc = new Document(); doc.Add(NewField("distinctiveFieldName", "aaa ", StoredTextType)); try { writer.AddDocument(doc); Assert.Fail("Failed to fail."); } catch (BadNews badNews) { infoPrintStream.Flush(); string infoStream = Encoding.UTF8.GetString(infoBytes.GetBuffer()); Assert.IsTrue(infoStream.Contains("distinctiveFieldName")); } writer.Dispose(); dir.Dispose(); }