alessandrobenedetti commented on code in PR #2809:
URL: https://github.com/apache/solr/pull/2809#discussion_r1830836383


##########
solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.solr.llm;
+
+import java.lang.invoke.MethodHandles;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.io.file.PathUtils;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrResourceLoader;
+import org.apache.solr.llm.embedding.SolrEmbeddingModel;
+import org.apache.solr.llm.store.EmbeddingModelException;
+import org.apache.solr.llm.store.rest.ManagedEmbeddingModelStore;
+import org.apache.solr.util.RestTestBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestLlmBase extends RestTestBase {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected static final SolrResourceLoader solrResourceLoader =
+      new SolrResourceLoader(Path.of("").toAbsolutePath());
+
+  protected static Path tmpSolrHome;
+  protected static Path tmpConfDir;
+
+  public static final String MODEL_FILE_NAME = 
"_schema_embedding-model-store.json";
+  protected static final String COLLECTION = "collection1";
+  protected static final String CONF_DIR = COLLECTION + "/conf";
+
+  protected static Path embeddingModelStoreFile = null;
+
+  protected static String IDField = "id";
+  protected static String stringField = "string_field";
+  protected static String vectorField = "vector";
+  protected static String vectorField2 = "vector2";
+  protected static String vectorFieldByteEncoding = "vector_byte_encoding";
+
+  protected static void setuptest(boolean bulkIndex) throws Exception {
+    setuptest("solrconfig-llm.xml", "schema.xml");
+    if (bulkIndex) prepareIndex();
+  }
+
+  protected static void setupPersistenttest(boolean bulkIndex) throws 
Exception {
+    setupPersistentTest("solrconfig-llm.xml", "schema.xml");
+    if (bulkIndex) prepareIndex();
+  }
+
+  public static ManagedEmbeddingModelStore getManagedModelStore() {
+    try (SolrCore core = 
solrClientTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
+      return ManagedEmbeddingModelStore.getManagedModelStore(core);
+    }
+  }
+
+  protected static void setupTestInit(String solrconfig, String schema, 
boolean isPersistent)
+      throws Exception {
+    tmpSolrHome = createTempDir();
+    tmpConfDir = tmpSolrHome.resolve(CONF_DIR);
+    tmpConfDir.toFile().deleteOnExit();
+    PathUtils.copyDirectory(TEST_PATH(), tmpSolrHome.toAbsolutePath());
+
+    final Path mstore = tmpConfDir.resolve(MODEL_FILE_NAME);
+
+    if (isPersistent) {
+      embeddingModelStoreFile = mstore;
+    }
+
+    if (Files.exists(mstore)) {
+      if (log.isInfoEnabled()) {
+        log.info("remove model store config file in {}", 
mstore.toAbsolutePath());
+      }
+      Files.delete(mstore);
+    }
+    if (!solrconfig.equals("solrconfig-llm.xml")) {
+      Files.copy(
+          tmpSolrHome.resolve(CONF_DIR).resolve(solrconfig),
+          tmpSolrHome.resolve(CONF_DIR).resolve("solrconfig-llm.xml"));
+    }
+    if (!schema.equals("schema.xml")) {
+      Files.copy(
+          tmpSolrHome.resolve(CONF_DIR).resolve(schema),
+          tmpSolrHome.resolve(CONF_DIR).resolve("schema.xml"));
+    }
+
+    System.setProperty("managed.schema.mutable", "true");
+  }
+
+  public static void setuptest(String solrconfig, String schema) throws 
Exception {

Review Comment:
   Done!



-- 
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...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to