mayya-sharipova commented on a change in pull request #416: URL: https://github.com/apache/lucene/pull/416#discussion_r783592663
########## File path: lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java ########## @@ -279,6 +303,77 @@ public void testSearch() throws Exception { } } + private void indexData(IndexWriter iw) throws IOException { + // Add a document for every cartesian point in an NxN square so we can + // easily know which are the nearest neighbors to every point. Insert by iterating + // using a prime number that is not a divisor of N*N so that we will hit each point once, + // and chosen so that points will be inserted in a deterministic + // but somewhat distributed pattern + int n = 5, stepSize = 17; + float[][] values = new float[n * n][]; + int index = 0; + for (int i = 0; i < values.length; i++) { + // System.out.printf("%d: (%d, %d)\n", i, index % n, index / n); + int x = index % n, y = index / n; + values[i] = new float[] {x, y}; + index = (index + stepSize) % (n * n); + add(iw, i, values[i]); + if (i == 13) { + // create 2 segments + iw.commit(); + } + } + boolean forceMerge = random().nextBoolean(); + if (forceMerge) { + iw.forceMerge(1); + } + assertConsistentGraph(iw, values); + } + + public void testMultiThreadedSearch() throws Exception { + similarityFunction = VectorSimilarityFunction.EUCLIDEAN; + IndexWriterConfig config = newIndexWriterConfig(); + config.setCodec(codec); + Directory dir = newDirectory(); + IndexWriter iw = new IndexWriter(dir, config); + indexData(iw); + + final SearcherManager manager = new SearcherManager(iw, new SearcherFactory()); + Thread[] threads = new Thread[randomIntBetween(2, 5)]; + final CountDownLatch latch = new CountDownLatch(1); + for (int i = 0; i < threads.length; i++) { + threads[i] = + new Thread( + () -> { + try { + latch.await(); + IndexSearcher searcher = manager.acquire(); + try { + KnnVectorQuery query = new KnnVectorQuery("vector", new float[] {0f, 0.1f}, 5); Review comment: `assertGraphSearch` expects an `IndexReader` and user reader fo search, while in this test we have `SearcherManager` that uses `IndexSearcher` for search; but the assertion of results is copied from `assertGraphSearch` . The test tests that there is no problem with accessing a graph from multiple threads at the same time. We can move this test to `TestKnnVectorQuery` if you think that it will fit there better. -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org 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