aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/SummaryDiskAccessValidatorTestCase.java
blob: bac29b52949db6a895234a86f9f2c2405c7bbc85 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;

import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.derived.TestableDeployLogger;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

import static com.yahoo.config.model.test.TestUtil.joinLines;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class SummaryDiskAccessValidatorTestCase {

    @Test
    void logs_warning_when_accessing_field_that_needs_disk_access() throws ParseException {
        var sd = joinLines(
                "schema test {",
                "  document test {",
                "    field str_map type map<string, string> {",
                "      indexing: summary",
                "      # Not all struct fields are attributes -> needs disk access",
                "      struct-field key { indexing: attribute }",
                "    }",
                "  }",
                "  document-summary my_sum {",
                "    summary str_map { source: str_map }",
                "  }",
                "}");

        var logger = new TestableDeployLogger();
        ApplicationBuilder.createFromString(sd, logger);
        assertEquals(1, logger.warnings.size());
        assertThat(logger.warnings.get(0),
                containsString("In schema 'test', document summary 'my_sum': " +
                        "Fields [str_map] references non-attribute fields: Using this summary will cause disk accesses"));
    }

    @Test
    void does_not_log_warning_when_accessing_imported_map_field() throws ParseException {
        var parent = joinLines(
                "schema parent {",
                "  document parent {",
                "    field str_map type map<string, string> {",
                "      indexing: summary",
                "      # All struct fields must be attributes in order to import this fields",
                "      struct-field key { indexing: attribute }",
                "      struct-field value { indexing: attribute }",
                "    }",
                "  }",
                "}");

        var child = joinLines(
                "schema child {",
                "  document child {",
                "    field ref type reference<parent> { indexing: attribute }",
                "  }",
                "  import field ref.str_map as ref_str_map {}",
                "  document-summary my_sum {",
                "    summary ref_str_map { source: ref_str_map }",
                "  }",
                "}");
        var logger = new TestableDeployLogger();
        ApplicationBuilder.createFromStrings(logger, child, parent);
        assertEquals(0, logger.warnings.size());
    }

}