msokolov commented on a change in pull request #2231: URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568105107
########## File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java ########## @@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept } } } + + public void testGetFieldNames() throws IOException { + Directory dir = newDirectory(); + + IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); + + assertEquals(Set.of(), writer.getFieldNames()); + + addDocWithField(writer, "f1"); + assertEquals(Set.of("f1"), writer.getFieldNames()); + + // should be unmodifiable: + final Set<String> fieldSet = writer.getFieldNames(); + assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify")); + assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1")); + + addDocWithField(writer, "f2"); + assertEquals(Set.of("f1", "f2"), writer.getFieldNames()); Review comment: Let's also assert that the original `fieldSet` has not been modified - it was a true copy and not some kind of alias over an underlying modifiable Set? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org