aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/significance/test/SignificanceModelTestCase.java
blob: 26e8c67a226b5114339720aa232019477bf61d81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.significance.test;

import com.yahoo.component.ComponentId;
import com.yahoo.config.InnerNode;
import com.yahoo.config.ModelNode;
import com.yahoo.config.ModelReference;
import com.yahoo.search.significance.config.SignificanceConfig;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.component.SignificanceModelRegistry;
import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg;
import org.junit.jupiter.api.Test;


import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author MariusArhaug
 */

public class SignificanceModelTestCase {
    private VespaModel createModel(String filename) {
        return new VespaModelCreatorWithFilePkg(filename).create();
    }

    @Test
    void testIndexGreaterThanNumNodes() {
        VespaModel vespaModel = createModel("src/test/cfg/significance");
        ApplicationContainerCluster containerCluster = vespaModel.getContainerClusters().get("container");
        assertEquals(1, containerCluster.getContainers().size());
    }

    @Test
    void testSignificance() {
        VespaModel vespaModel = createModel("src/test/cfg/significance");
        ApplicationContainerCluster containerCluster = vespaModel.getContainerClusters().get("container");
        var significanceConfig = assertSignificancePresent(containerCluster);
        assertEquals(3, significanceConfig.model().size());

        assertEquals("models/idf-norwegian-wiki.json.zst", modelReference(significanceConfig.model().get(1), "path").path().orElseThrow().value());
        assertEquals("https://some/uri/blob.json", modelReference(significanceConfig.model().get(2), "path").url().orElseThrow().value());


    }

    private SignificanceConfig assertSignificancePresent(ApplicationContainerCluster cluster) {

        var id = new ComponentId("com.yahoo.language.significance.impl.DefaultSignificanceModelRegistry");
        var significance = (SignificanceModelRegistry) cluster.getComponentsMap().get(id);
        assertEquals("com.yahoo.language.significance.impl.DefaultSignificanceModelRegistry", significance.getClassId().getName());
        var cfgBuilder = new SignificanceConfig.Builder();
        significance.getConfig(cfgBuilder);
        return cfgBuilder.build();
    }

    // Ugly hack to read underlying model reference from config instance
    private static ModelReference modelReference(InnerNode cfg, String name) {
        try {
            var f = cfg.getClass().getDeclaredField(name);
            f.setAccessible(true);
            return ((ModelNode) f.get(cfg)).getModelReference();
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}