aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-06-06 12:46:54 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2024-06-06 12:49:32 +0200
commitb007600b769a0b1b99a94ac0e92adbbd7605e4d3 (patch)
tree6061605512232818214df8c8295b1f3e9436d636 /config-model/src/test/java
parentca233de10b749c17356c349fce23eb662372511e (diff)
- Test that deprecation warning is given if specified inside match-phase {}.
- Test that exception is thrown if specified twice.
Diffstat (limited to 'config-model/src/test/java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java55
1 files changed, 38 insertions, 17 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java b/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
index 2c03bab8144..4026341464f 100644
--- a/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/DiversityTestCase.java
@@ -3,19 +3,28 @@ package com.yahoo.schema;
import com.yahoo.search.query.ranking.Diversity;
import com.yahoo.schema.parser.ParseException;
+import com.yahoo.vespa.model.test.utils.DeployLoggerStub;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author baldersheim
*/
public class DiversityTestCase {
- @Test
- void testDiversity() throws ParseException {
+ private static void verifyDiversity(DeployLoggerStub logger, boolean atRankProfile, boolean atMatchPhase) throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
- ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry);
+ ApplicationBuilder builder = new ApplicationBuilder(logger, rankProfileRegistry);
+ String diversitySpec = """
+ diversity {
+ attribute: b
+ min-groups: 74
+ cutoff-factor: 17.3
+ cutoff-strategy: strict
+ }
+ """;
builder.addSchema(
"""
search test {
@@ -29,17 +38,15 @@ public class DiversityTestCase {
}
}
rank-profile parent {
- match-phase {
+ match-phase {""" +
+ (atMatchPhase ? diversitySpec : "") +
+ """
attribute: a
max-hits: 120
max-filter-coverage: 0.065
- }
- diversity {
- attribute: b
- min-groups: 74
- cutoff-factor: 17.3
- cutoff-strategy: strict
- }
+ }""" +
+ (atRankProfile ? diversitySpec : "") +
+ """
}
}
""");
@@ -56,6 +63,21 @@ public class DiversityTestCase {
assertEquals("a", matchPhase.getAttribute());
assertEquals(0.065, matchPhase.getMaxFilterCoverage(), 1e-16);
}
+ @Test
+ void testDiversity() throws ParseException {
+ DeployLoggerStub logger = new DeployLoggerStub();
+ verifyDiversity(logger, true, false);
+ assertTrue(logger.entries.isEmpty());
+ verifyDiversity(logger, false, true);
+ assertEquals(1, logger.entries.size());
+ assertEquals("'diversity is deprecated inside 'match-phase'. Specify it at 'rank-profile' level.", logger.entries.get(0).message);
+ try {
+ verifyDiversity(logger, true, true);
+ fail("Should throw.");
+ } catch (Exception e) {
+ assertEquals("rank-profile 'parent' error: already has diversity", e.getMessage());
+ }
+ }
private static String getMessagePrefix() {
return "In search definition 'test', rank-profile 'parent': diversity attribute 'b' ";
@@ -85,8 +107,7 @@ public class DiversityTestCase {
}
}
private ApplicationBuilder getSearchBuilder(String diversityField) throws ParseException {
- RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
- ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry);
+ ApplicationBuilder builder = new ApplicationBuilder(new RankProfileRegistry());
builder.addSchema("""
search test {
document test {
@@ -99,13 +120,13 @@ public class DiversityTestCase {
}
rank-profile parent {
match-phase {
- diversity {
- attribute: b
- min-groups: 74
- }
attribute: a
max-hits: 120
}
+ diversity {
+ attribute: b
+ min-groups: 74
+ }
}
}""");
return builder;