2020import co .elastic .clients .elasticsearch .indices .get_mapping .IndexMappingRecord ;
2121import co .elastic .clients .json .JsonData ;
2222import com .fasterxml .jackson .core .JsonProcessingException ;
23+ import com .fasterxml .jackson .core .TreeNode ;
2324import com .fasterxml .jackson .databind .JsonNode ;
2425import com .fasterxml .jackson .databind .ObjectMapper ;
2526import com .fasterxml .jackson .databind .json .JsonMapper ;
2627import com .fasterxml .jackson .databind .node .ArrayNode ;
2728import com .fasterxml .jackson .databind .node .ObjectNode ;
29+ import com .fasterxml .jackson .databind .node .TextNode ;
2830import com .github .tomakehurst .wiremock .client .WireMock ;
2931import com .github .tomakehurst .wiremock .core .WireMockConfiguration ;
3032import com .github .tomakehurst .wiremock .junit .WireMockRule ;
4547import org .apache .jackrabbit .oak .stats .DefaultStatisticsProvider ;
4648import org .apache .jackrabbit .oak .stats .StatisticsProvider ;
4749import org .apache .jackrabbit .oak .stats .StatsOptions ;
48- import org .jetbrains .annotations .NotNull ;
4950import org .junit .After ;
5051import org .junit .Before ;
5152import org .junit .Ignore ;
6263import java .nio .file .Paths ;
6364import java .time .Instant ;
6465import java .util .Collection ;
66+ import java .util .HashMap ;
6567import java .util .List ;
6668import java .util .Map ;
6769import java .util .UUID ;
8183public 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