Skip to content

Commit 30c27fc

Browse files
authored
OAK-11734: Update inferenceConfigTest to check status is updated prop… (#2301)
* OAK-11734: Update inferenceConfigTest to check status is updated properly * OAK-11734: Update inferenceConfigTest to check status is updated properly
1 parent 03ee9ab commit 30c27fc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/inference/ElasticInferenceUsingConfigTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import co.elastic.clients.elasticsearch.indices.get_mapping.IndexMappingRecord;
2121
import co.elastic.clients.json.JsonData;
2222
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.core.TreeNode;
2324
import com.fasterxml.jackson.databind.JsonNode;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
2526
import com.fasterxml.jackson.databind.json.JsonMapper;
2627
import com.fasterxml.jackson.databind.node.ArrayNode;
2728
import com.fasterxml.jackson.databind.node.ObjectNode;
29+
import com.fasterxml.jackson.databind.node.TextNode;
2830
import com.github.tomakehurst.wiremock.client.WireMock;
2931
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
3032
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -45,7 +47,6 @@
4547
import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
4648
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
4749
import org.apache.jackrabbit.oak.stats.StatsOptions;
48-
import org.jetbrains.annotations.NotNull;
4950
import org.junit.After;
5051
import org.junit.Before;
5152
import org.junit.Ignore;
@@ -62,6 +63,7 @@
6263
import java.nio.file.Paths;
6364
import java.time.Instant;
6465
import java.util.Collection;
66+
import java.util.HashMap;
6567
import java.util.List;
6668
import java.util.Map;
6769
import java.util.UUID;
@@ -81,6 +83,7 @@
8183
public class ElasticInferenceUsingConfigTest extends ElasticAbstractQueryTest {
8284

8385
private static final Logger LOG = LoggerFactory.getLogger(ElasticInferenceUsingConfigTest.class);
86+
private static ObjectMapper MAPPER = new JsonMapper();
8487

8588
private ScheduledExecutorService executorService;
8689
private StatisticsProvider statisticsProvider;
@@ -396,14 +399,13 @@ private void addTestContent() throws CommitFailedException {
396399
* Sets up embeddings for content based on JSON files.
397400
*/
398401
private void setupEmbeddingsForContent(Tree index, String inferenceModelConfigName, String inferenceModelName) throws Exception {
399-
ObjectMapper mapper = new JsonMapper();
400402
List<String> paths = executeQuery("select [jcr:path] from [nt:base] where ISDESCENDANTNODE('/content') and title is not null", SQL2);
401403

402404
for (String path : paths) {
403405
URL json = this.getClass().getResource("/inferenceUsingConfig" + path + ".json");
404406
if (json != null) {
405-
Map<String, Collection<Double>> map = mapper.readValue(json, Map.class);
406-
ObjectNode updateDoc = mapper.createObjectNode();
407+
Map<String, Collection<Double>> map = MAPPER.readValue(json, Map.class);
408+
ObjectNode updateDoc = MAPPER.createObjectNode();
407409
List<Float> embeddings = map.get("embedding").stream()
408410
.map(d -> ((Double) d).floatValue())
409411
.collect(Collectors.toList());
@@ -417,7 +419,10 @@ private void setupEmbeddingsForContent(Tree index, String inferenceModelConfigNa
417419
ObjectNode vectorSpacesNode = updateDoc.putObject(InferenceConstants.VECTOR_SPACES);
418420
ArrayNode inferenceModelConfigNode = vectorSpacesNode.putArray(inferenceModelConfigName);
419421
inferenceModelConfigNode.addPOJO(vectorDocument);
420-
422+
Map<String, Object> enricherStatusConfig = new HashMap<>();
423+
InferenceConfig.getInstance().getEnricherStatus().entrySet().forEach(k -> enricherStatusConfig.put(k.getKey(), k.getValue()));
424+
enricherStatusConfig.put("status", "COMPLETED");
425+
updateDoc.putPOJO(InferenceConstants.ENRICH_NODE, enricherStatusConfig);
421426
updateDocument(index, path, updateDoc);
422427
}
423428
}
@@ -519,6 +524,12 @@ private void testInferenceDataPersistenceOnUpdate(Tree index) throws CommitFaile
519524

520525
ObjectNode carsDocUpdated = getDocument(index, "/content/cars");
521526
assertNotNull(carsDocUpdated.get(InferenceConstants.VECTOR_SPACES));
527+
try {
528+
TreeNode tree = MAPPER.readTree(carsDocUpdated.get(InferenceConstants.ENRICH_NODE).traverse());
529+
assertEquals(((TextNode) tree.get("status")).asText(), (String) InferenceConfig.getInstance().getEnricherStatus().get("status"));
530+
} catch (IOException e) {
531+
throw new RuntimeException(e);
532+
}
522533
});
523534
}
524535

@@ -775,8 +786,7 @@ private void verifyEnricherStatus(Tree index, String path, String expectedEnrich
775786
*/
776787
private void createDocumentWithEmbeddings(Tree index, String path, String inferenceModelConfigName,
777788
String inferenceModelName, List<Float> embeddings) throws IOException {
778-
ObjectMapper mapper = new JsonMapper();
779-
ObjectNode updateDoc = mapper.createObjectNode();
789+
ObjectNode updateDoc = MAPPER.createObjectNode();
780790
VectorDocument vectorDocument = new VectorDocument(UUID.randomUUID().toString(), embeddings,
781791
Map.of("updatedAt", Instant.now().toEpochMilli(), "model", inferenceModelName));
782792
ObjectNode vectorSpacesNode = updateDoc.putObject(InferenceConstants.VECTOR_SPACES);

0 commit comments

Comments
 (0)