kaivalnp commented on code in PR #14178:
URL: https://github.com/apache/lucene/pull/14178#discussion_r2134425988


##########
lucene/sandbox/src/test/org/apache/lucene/sandbox/codecs/faiss/TestFaissKnnVectorsFormat.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.sandbox.codecs.faiss;
+
+import static org.apache.lucene.index.VectorEncoding.FLOAT32;
+import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT;
+import static org.apache.lucene.index.VectorSimilarityFunction.EUCLIDEAN;
+
+import java.io.IOException;
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.VectorEncoding;
+import org.apache.lucene.index.VectorSimilarityFunction;
+import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
+import org.apache.lucene.tests.util.TestUtil;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+/**
+ * Tests for {@link FaissKnnVectorsFormat}. Will run only if required shared 
libraries (including
+ * dependencies) are present at runtime, or the {@value #FAISS_RUN_TESTS} JVM 
arg is set to {@code
+ * true}
+ */
+public class TestFaissKnnVectorsFormat extends BaseKnnVectorsFormatTestCase {
+  private static final String FAISS_RUN_TESTS = "tests.faiss.run";
+
+  private static final VectorEncoding[] SUPPORTED_ENCODINGS = {FLOAT32};
+  private static final VectorSimilarityFunction[] SUPPORTED_FUNCTIONS = 
{DOT_PRODUCT, EUCLIDEAN};
+
+  @BeforeClass
+  public static void maybeSuppress() throws ClassNotFoundException {
+    // Explicitly run tests
+    if (Boolean.getBoolean(FAISS_RUN_TESTS)) {
+      return;
+    }
+
+    // Otherwise check if dependencies are present
+    boolean faissLibraryPresent;
+    try {
+      Class.forName("org.apache.lucene.sandbox.codecs.faiss.LibFaissC");
+      faissLibraryPresent = true;
+    } catch (UnsatisfiedLinkError _) {
+      faissLibraryPresent = false;
+    }
+    assumeTrue("Native libraries present", faissLibraryPresent);
+  }
+
+  @Override
+  protected VectorEncoding randomVectorEncoding() {
+    return SUPPORTED_ENCODINGS[random().nextInt(SUPPORTED_ENCODINGS.length)];
+  }
+
+  @Override
+  protected VectorSimilarityFunction randomSimilarity() {
+    return SUPPORTED_FUNCTIONS[random().nextInt(SUPPORTED_FUNCTIONS.length)];
+  }
+
+  @Override

Review Comment:
   We have 
[testRandom](https://github.com/apache/lucene/blob/485141dd34ea866ad9dc59843770969d1b0c8fa2/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseKnnVectorsFormatTestCase.java#L1290)
 which does something like this..



-- 
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

Reply via email to