aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java
blob: 7e6eaa0683a0c6efd4b6cc75591617e7081458d4 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.yahoo.searchdefinition;

import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.vespa.model.test.utils.DeployLoggerStub;
import org.junit.Test;

import java.io.IOException;
import java.util.logging.Level;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Tests summary validation
 *
 * @author bratseth
 */
public class SummaryTestCase {

    @Test
    public void testMemorySummary() throws ParseException {
        String sd =
                "search memorysummary {\n" +
                "\n" +
                "  document memorysummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index # no summary, so ignored\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertTrue(logger.entries.isEmpty());
    }

    @Test
    public void testDiskSummary() throws ParseException {
        String sd =
                "search disksummary {\n" +
                "\n" +
                "  document-summary foobar {\n" +
                "      summary foo1 type string { source: inmemory }\n" +
                "      summary foo2 type string { source: ondisk }\n" +
                "  }\n" +
                "  document disksummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index | summary\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertEquals(1, logger.entries.size());
        assertEquals(Level.WARNING, logger.entries.get(0).level);
        assertEquals("summary field 'foo2' in document summary 'foobar' references source field 'ondisk', " +
                     "which is not an attribute: Using this summary will cause disk accesses. " +
                     "Set 'from-disk' on this summary class to silence this warning.",
                     logger.entries.get(0).message);
    }

    @Test
    public void testDiskSummaryExplicit() throws ParseException {
        String sd =
                "search disksummary {\n" +
                "\n" +
                "  document disksummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index | summary\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "  document-summary foobar {\n" +
                "      summary foo1 type string { source: inmemory }\n" +
                "      summary foo2 type string { source: ondisk }\n" +
                "      from-disk\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertTrue(logger.entries.isEmpty());
    }

}