Github user jpountz commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/497#discussion_r232740066
--- Diff:
lucene/core/src/test/org/apache/lucene/index/TestExitableDirectoryReader.java
---
@@ -152,13 +150,130 @@ public void testExitableFilterIndexReader() throws
Exception {
// Set a negative time allowed and expect the query to complete
(should disable timeouts)
// Not checking the validity of the result, all we are bothered about
in this test is the timing out.
directoryReader = DirectoryReader.open(directory);
- exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
new QueryTimeoutImpl(-189034L));
+ exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
disabledQueryTimeout());
reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader));
searcher = new IndexSearcher(reader);
searcher.search(query, 10);
reader.close();
directory.close();
}
+
+ /**
+ * Tests timing out of PointValues queries
+ *
+ * @throws Exception on error
+ */
+ public void testExitablePointValuesIndexReader() throws Exception {
+ Directory directory = newDirectory();
+ IndexWriter writer = new IndexWriter(directory,
newIndexWriterConfig(new MockAnalyzer(random())));
+
+ Document d1 = new Document();
+ d1.add(new IntPoint("default", 10));
+ writer.addDocument(d1);
+
+ Document d2 = new Document();
+ d2.add(new IntPoint("default", 100));
+ writer.addDocument(d2);
+
+ Document d3 = new Document();
+ d3.add(new IntPoint("default", 1000));
+ writer.addDocument(d3);
+
+ writer.forceMerge(1);
+ writer.commit();
+ writer.close();
+
+ DirectoryReader directoryReader;
+ DirectoryReader exitableDirectoryReader;
+ IndexReader reader;
+ IndexSearcher searcher;
+
+ Query query = IntPoint.newRangeQuery("default", 10, 20);
+
+ // Set a fairly high timeout value (1 second) and expect the query to
complete in that time frame.
+ // Not checking the validity of the result, all we are bothered about
in this test is the timing out.
+ directoryReader = DirectoryReader.open(directory);
+ exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
inifiniteQueryTimeout());
+ reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader));
+ searcher = new IndexSearcher(reader);
+ searcher.search(query, 10);
+ reader.close();
+
+ // Set a really low timeout value (1 millisecond) and expect an
Exception
+ directoryReader = DirectoryReader.open(directory);
+ exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
immediateQueryTimeout());
+ reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader));
+ IndexSearcher slowSearcher = new IndexSearcher(reader);
+ expectThrows(ExitingReaderException.class, () -> {
+ slowSearcher.search(query, 10);
+ });
+ reader.close();
+
+ // Set maximum time out and expect the query to complete.
+ // Not checking the validity of the result, all we are bothered about
in this test is the timing out.
+ directoryReader = DirectoryReader.open(directory);
+ exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
inifiniteQueryTimeout());
+ reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader));
+ searcher = new IndexSearcher(reader);
+ searcher.search(query, 10);
+ reader.close();
+
+ // Set a negative time allowed and expect the query to complete
(should disable timeouts)
+ // Not checking the validity of the result, all we are bothered about
in this test is the timing out.
+ directoryReader = DirectoryReader.open(directory);
+ exitableDirectoryReader = new ExitableDirectoryReader(directoryReader,
disabledQueryTimeout());
+ reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader));
+ searcher = new IndexSearcher(reader);
+ searcher.search(query, 10);
+ reader.close();
+
+ directory.close();
+ }
+
+ private static QueryTimeout disabledQueryTimeout() {
+ return new QueryTimeout() {
+
+ @Override
+ public boolean shouldExit() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeoutEnabled() {
+ return false;
+ }
+ };
+ }
+
+ private static QueryTimeout inifiniteQueryTimeout() {
+ return new QueryTimeout() {
+
+ @Override
+ public boolean shouldExit() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeoutEnabled() {
+ return true;
+ }
+ };
+ }
+
+ private static QueryTimeout immediateQueryTimeout() {
+ return new QueryTimeout() {
+
+ @Override
+ public boolean shouldExit() {
+ return true;
+ }
+
+ @Override
+ public boolean isTimeoutEnabled() {
+ return true;
+ }
+ };
+ }
--- End diff --
:+1:
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]