diff options
author | Lester Solbakken <lester.solbakken@gmail.com> | 2024-04-12 13:04:01 +0200 |
---|---|---|
committer | Lester Solbakken <lester.solbakken@gmail.com> | 2024-04-12 13:04:01 +0200 |
commit | b4d6c0856e0313e8925505265121ce743f079ada (patch) | |
tree | fd8a28fb707d7dae4ac9c4f19d48aad082cf01ff /config-model | |
parent | e11438c6335038f6d99ea50eef086511eb204d43 (diff) | |
parent | dd996cbeb9ddf7c22089b6115966f03227b35a48 (diff) |
Merge branch 'master' into lesters/add-local-llms
Diffstat (limited to 'config-model')
121 files changed, 420 insertions, 413 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java index 51bd01de5bc..f25f130eed0 100644 --- a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java +++ b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java @@ -5,7 +5,7 @@ import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; import java.util.Collection; -import java.util.Collections; +import java.util.List; /** * A resolver of implementations of named config models. @@ -44,7 +44,7 @@ public abstract class ConfigModelRegistry { @Override public Collection<ConfigModelBuilder> resolve(ConfigModelId id) { - return Collections.emptyList(); + return List.of(); } } diff --git a/config-model/src/main/java/com/yahoo/config/model/MapConfigModelRegistry.java b/config-model/src/main/java/com/yahoo/config/model/MapConfigModelRegistry.java index 8fe1372ef2f..7242d3de1dd 100644 --- a/config-model/src/main/java/com/yahoo/config/model/MapConfigModelRegistry.java +++ b/config-model/src/main/java/com/yahoo/config/model/MapConfigModelRegistry.java @@ -7,7 +7,6 @@ import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -58,7 +57,7 @@ public class MapConfigModelRegistry extends ConfigModelRegistry { @SafeVarargs @SuppressWarnings("varargs") public static ConfigModelRegistry createFromList(ConfigModelBuilder<? extends ConfigModel> ... builders) { - return new MapConfigModelRegistry(Arrays.asList(builders)); + return new MapConfigModelRegistry(List.of(builders)); } } diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java index f19341098f4..57a75bd8a38 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java @@ -50,7 +50,6 @@ import java.io.Reader; import java.io.UncheckedIOException; import java.time.Instant; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -329,7 +328,7 @@ public class DeployState implements ConfigDefinitionStore { private Optional<ConfigDefinitionRepo> configDefinitionRepo = Optional.empty(); private Optional<Model> previousModel = Optional.empty(); private Set<ContainerEndpoint> endpoints = Set.of(); - private Collection<MlModelImporter> modelImporters = Collections.emptyList(); + private Collection<MlModelImporter> modelImporters = List.of(); private Zone zone = Zone.defaultZone(); private Instant now = Instant.now(); private Version wantedNodeVespaVersion = Vtag.currentVersion; diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/TestProperties.java b/config-model/src/main/java/com/yahoo/config/model/deploy/TestProperties.java index 11d3a48ee51..3e91b8afe88 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/TestProperties.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/TestProperties.java @@ -19,7 +19,6 @@ import com.yahoo.vespa.model.container.ApplicationContainerCluster; import java.net.URI; import java.security.cert.X509Certificate; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; @@ -35,10 +34,10 @@ public class TestProperties implements ModelContext.Properties, ModelContext.Fea private boolean multitenant = false; private ApplicationId applicationId = ApplicationId.defaultId(); - private List<ConfigServerSpec> configServerSpecs = Collections.emptyList(); + private List<ConfigServerSpec> configServerSpecs = List.of(); private boolean hostedVespa = false; private Zone zone = Zone.defaultZone(); - private final Set<ContainerEndpoint> endpoints = Collections.emptySet(); + private final Set<ContainerEndpoint> endpoints = Set.of(); private boolean useDedicatedNodeForLogserver = false; private double defaultTermwiseLimit = 1.0; private String jvmGCOptions = null; @@ -55,10 +54,10 @@ public class TestProperties implements ModelContext.Properties, ModelContext.Fea private double feedConcurrency = 0.5; private double feedNiceness = 0.0; private int maxActivationInhibitedOutOfSyncGroups = 0; - private List<TenantSecretStore> tenantSecretStores = Collections.emptyList(); + private List<TenantSecretStore> tenantSecretStores = List.of(); private String jvmOmitStackTraceInFastThrowOption; private boolean allowDisableMtls = true; - private List<X509Certificate> operatorCertificates = Collections.emptyList(); + private List<X509Certificate> operatorCertificates = List.of(); private double resourceLimitDisk = 0.75; private double resourceLimitMemory = 0.8; private double minNodeRatioPerGroup = 0.0; diff --git a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java index e411a8e3e77..dcf1c8629a4 100644 --- a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java +++ b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java @@ -135,7 +135,7 @@ public class ModelNode<MODEL extends ConfigModel> implements ConfigModelInstance } // For collections, we don't require that dependency has been added, we just give an empty collection if (isCollection(param)) - return Collections.emptyList(); + return List.of(); throw new IllegalArgumentException("Unable to find constructor argument " + param + " for " + clazz.getName()); } diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java index 5d3db7f676a..365543a549b 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java @@ -31,7 +31,6 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -143,7 +142,7 @@ public class MockApplicationPackage implements ApplicationPackage { @Override public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() { - return Collections.emptyMap(); + return Map.of(); } @Override @@ -203,7 +202,7 @@ public class MockApplicationPackage implements ApplicationPackage { } public List<ComponentInfo> getComponentsInfo(Version vespaVersion) { - return Collections.emptyList(); + return List.of(); } public QueryProfileRegistry getQueryProfiles() { return queryProfileRegistry; } @@ -240,7 +239,7 @@ public class MockApplicationPackage implements ApplicationPackage { private File root = new File("nonexisting"); private String hosts = null; private String services = null; - private List<String> schemas = Collections.emptyList(); + private List<String> schemas = List.of(); private Map<Path, MockApplicationFile> files = new LinkedHashMap<>(); private String schemaDir = null; private String deploymentSpec = null; @@ -277,12 +276,12 @@ public class MockApplicationPackage implements ApplicationPackage { } public Builder withSearchDefinition(String searchDefinition) { - this.schemas = Collections.singletonList(searchDefinition); + this.schemas = List.of(searchDefinition); return this; } public Builder withSchemas(List<String> searchDefinition) { - this.schemas = Collections.unmodifiableList(searchDefinition); + this.schemas = List.copyOf(searchDefinition); return this; } @@ -369,8 +368,8 @@ public class MockApplicationPackage implements ApplicationPackage { } private List<NamedReader> asNamedReaderList(String value) { - if (value == null) return Collections.emptyList(); - return Collections.singletonList(new NamedReader(extractId(value) + ".xml", new StringReader(value))); + if (value == null) return List.of(); + return List.of(new NamedReader(extractId(value) + ".xml", new StringReader(value))); } private String extractId(String xmlStringWithIdAttribute) { diff --git a/config-model/src/main/java/com/yahoo/config/model/test/TestUtil.java b/config-model/src/main/java/com/yahoo/config/model/test/TestUtil.java index 94969aa5324..509c10c7fc9 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/TestUtil.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/TestUtil.java @@ -6,7 +6,6 @@ import com.yahoo.config.model.builder.xml.XmlHelper; import org.w3c.dom.Element; import java.io.StringReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -20,7 +19,7 @@ public class TestUtil { public static Element parse(String... xmlLines) { List<String> lines = new ArrayList<>(); lines.add("<?xml version='1.0' encoding='utf-8' ?>"); - lines.addAll(Arrays.asList(xmlLines)); + lines.addAll(List.of(xmlLines)); try { return XmlHelper.getDocument(new StringReader(CollectionUtil.mkString(lines, "\n").replace("'", "\""))).getDocumentElement(); diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java index 77e123fefef..c5140dd6fc8 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import static java.util.Collections.emptySet; /** * @author baldersheim @@ -47,7 +46,7 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp private final Set<String> importedFieldNames; public NewDocumentType(Name name) { - this(name, emptySet()); + this(name, Set.of()); } public NewDocumentType(Name name, Set<Name> documentReferences, Set<String> importedFieldNames) { @@ -60,7 +59,7 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp } public NewDocumentType(Name name, Set<Name> documentReferences) { - this(name, documentReferences, emptySet()); + this(name, documentReferences, Set.of()); } public NewDocumentType(Name name, @@ -74,8 +73,8 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp if (fs != null) { this.fieldSets.addAll(fs.userFieldSets().values()); for (FieldSet f : fs.builtInFieldSets().values()) { - if ((f.getName() != BuiltInFieldSets.INTERNAL_FIELDSET_NAME) && - (f.getName() != BuiltInFieldSets.SEARCH_FIELDSET_NAME)) { + if (!BuiltInFieldSets.INTERNAL_FIELDSET_NAME.equals(f.getName()) && + !BuiltInFieldSets.SEARCH_FIELDSET_NAME.equals(f.getName())) { fieldSets.add(f); } } diff --git a/config-model/src/main/java/com/yahoo/schema/ApplicationBuilder.java b/config-model/src/main/java/com/yahoo/schema/ApplicationBuilder.java index 2e964ac3624..749cdbfd8b7 100644 --- a/config-model/src/main/java/com/yahoo/schema/ApplicationBuilder.java +++ b/config-model/src/main/java/com/yahoo/schema/ApplicationBuilder.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -351,7 +350,7 @@ public class ApplicationBuilder { RankProfileRegistry rankProfileRegistry, QueryProfileRegistry queryprofileRegistry) throws IOException, ParseException { - return createFromFiles(Collections.singletonList(fileName), new MockFileRegistry(), deployLogger, new TestProperties(), + return createFromFiles(List.of(fileName), new MockFileRegistry(), deployLogger, new TestProperties(), rankProfileRegistry, queryprofileRegistry); } @@ -414,8 +413,8 @@ public class ApplicationBuilder { queryProfileRegistry); var fnli = Files.list(new File(dir).toPath()) - .map(p -> p.toString()) - .filter(fn -> AbstractApplicationPackage.validSchemaFilename(fn)) + .map(java.nio.file.Path::toString) + .filter(AbstractApplicationPackage::validSchemaFilename) .sorted(); for (var i = fnli.iterator(); i.hasNext(); ) { builder.addSchemaFile(i.next()); diff --git a/config-model/src/main/java/com/yahoo/schema/FieldSets.java b/config-model/src/main/java/com/yahoo/schema/FieldSets.java index 1dbf496992b..6464bd1681e 100644 --- a/config-model/src/main/java/com/yahoo/schema/FieldSets.java +++ b/config-model/src/main/java/com/yahoo/schema/FieldSets.java @@ -47,11 +47,7 @@ public class FieldSets { * @param field field to add to field set */ public void addBuiltInFieldSetItem(String setName, String field) { - if (builtInFieldSets.get(setName) == null) { - // First entry in this set - builtInFieldSets.put(setName, new FieldSet(setName)); - } - builtInFieldSets.get(setName).addFieldName(field); + builtInFieldSets.computeIfAbsent(setName, FieldSet::new).addFieldName(field); } /** Returns the built in field sets, unmodifiable */ diff --git a/config-model/src/main/java/com/yahoo/schema/RankProfile.java b/config-model/src/main/java/com/yahoo/schema/RankProfile.java index 22bf1880cd7..82ed45028b3 100644 --- a/config-model/src/main/java/com/yahoo/schema/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/schema/RankProfile.java @@ -32,7 +32,6 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -487,12 +486,12 @@ public class RankProfile implements Cloneable { } void setFirstPhaseRanking(RankingExpression rankingExpression) { - this.firstPhaseRanking = new RankingExpressionFunction(new ExpressionFunction(FIRST_PHASE, Collections.emptyList(), rankingExpression), false); + this.firstPhaseRanking = new RankingExpressionFunction(new ExpressionFunction(FIRST_PHASE, List.of(), rankingExpression), false); } public void setFirstPhaseRanking(String expression) { try { - firstPhaseRanking = new RankingExpressionFunction(parseRankingExpression(FIRST_PHASE, Collections.emptyList(), expression), false); + firstPhaseRanking = new RankingExpressionFunction(parseRankingExpression(FIRST_PHASE, List.of(), expression), false); } catch (ParseException e) { throw new IllegalArgumentException("Illegal first phase ranking function", e); } @@ -515,7 +514,7 @@ public class RankProfile implements Cloneable { public void setSecondPhaseRanking(String expression) { try { - secondPhaseRanking = new RankingExpressionFunction(parseRankingExpression(SECOND_PHASE, Collections.emptyList(), expression), false); + secondPhaseRanking = new RankingExpressionFunction(parseRankingExpression(SECOND_PHASE, List.of(), expression), false); } catch (ParseException e) { throw new IllegalArgumentException("Illegal second phase ranking function", e); @@ -535,7 +534,7 @@ public class RankProfile implements Cloneable { public void setGlobalPhaseRanking(String expression) { try { - globalPhaseRanking = new RankingExpressionFunction(parseRankingExpression(GLOBAL_PHASE, Collections.emptyList(), expression), false); + globalPhaseRanking = new RankingExpressionFunction(parseRankingExpression(GLOBAL_PHASE, List.of(), expression), false); } catch (ParseException e) { throw new IllegalArgumentException("Illegal global-phase ranking function", e); @@ -1036,7 +1035,7 @@ public class RankProfile implements Cloneable { Map<Reference, TensorType> featureTypes = featureTypes(); // Function compiling first pass: compile inline functions without resolving other functions Map<String, RankingExpressionFunction> inlineFunctions = - compileFunctions(this::getInlineFunctions, queryProfiles, featureTypes, importedModels, Collections.emptyMap(), expressionTransforms); + compileFunctions(this::getInlineFunctions, queryProfiles, featureTypes, importedModels, Map.of(), expressionTransforms); firstPhaseRanking = compile(this.getFirstPhase(), queryProfiles, featureTypes, importedModels, constants(), inlineFunctions, expressionTransforms); secondPhaseRanking = compile(this.getSecondPhase(), queryProfiles, featureTypes, importedModels, constants(), inlineFunctions, expressionTransforms); diff --git a/config-model/src/main/java/com/yahoo/schema/RankProfileRegistry.java b/config-model/src/main/java/com/yahoo/schema/RankProfileRegistry.java index 0fddcbd4cc7..4deee1dce9f 100644 --- a/config-model/src/main/java/com/yahoo/schema/RankProfileRegistry.java +++ b/config-model/src/main/java/com/yahoo/schema/RankProfileRegistry.java @@ -4,9 +4,7 @@ package com.yahoo.schema; import com.yahoo.schema.document.SDDocumentType; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -27,7 +25,7 @@ public class RankProfileRegistry { private static final String globalRankProfilesKey = "[global]"; /* These rank profiles can be overridden: 'default' rank profile, as that is documented to work. And 'unranked'. */ - static final Set<String> overridableRankProfileNames = new HashSet<>(Arrays.asList("default", "unranked")); + static final Set<String> overridableRankProfileNames = Set.of("default", "unranked"); public static RankProfileRegistry createRankProfileRegistryWithBuiltinRankProfiles(Schema schema) { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); diff --git a/config-model/src/main/java/com/yahoo/schema/derived/Deriver.java b/config-model/src/main/java/com/yahoo/schema/derived/Deriver.java index 9774868db9c..0c669e29538 100644 --- a/config-model/src/main/java/com/yahoo/schema/derived/Deriver.java +++ b/config-model/src/main/java/com/yahoo/schema/derived/Deriver.java @@ -7,7 +7,6 @@ import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.configmodel.producers.DocumentManager; import com.yahoo.vespa.configmodel.producers.DocumentTypes; import java.io.IOException; -import java.util.Collections; import java.util.List; /** @@ -30,7 +29,7 @@ public class Deriver { } public static DocumentmanagerConfig.Builder getDocumentManagerConfig(String sd) { - return getDocumentManagerConfig(Collections.singletonList(sd)); + return getDocumentManagerConfig(List.of(sd)); } public static DocumentmanagerConfig.Builder getDocumentManagerConfig(List<String> schemas) { @@ -38,7 +37,7 @@ public class Deriver { } public static DocumenttypesConfig.Builder getDocumentTypesConfig(String schema) { - return getDocumentTypesConfig(Collections.singletonList(schema)); + return getDocumentTypesConfig(List.of(schema)); } public static DocumenttypesConfig.Builder getDocumentTypesConfig(List<String> schemas) { diff --git a/config-model/src/main/java/com/yahoo/schema/derived/IndexSchema.java b/config-model/src/main/java/com/yahoo/schema/derived/IndexSchema.java index 34ed9f2f60c..677e4b31bdf 100644 --- a/config-model/src/main/java/com/yahoo/schema/derived/IndexSchema.java +++ b/config-model/src/main/java/com/yahoo/schema/derived/IndexSchema.java @@ -14,7 +14,6 @@ import com.yahoo.vespa.config.search.IndexschemaConfig; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -147,7 +146,7 @@ public class IndexSchema extends Derived { static List<Field> flattenField(Field field) { DataType fieldType = field.getDataType(); if (fieldType.getPrimitiveType() != null){ - return Collections.singletonList(field); + return List.of(field); } if (fieldType instanceof ArrayDataType) { List<Field> ret = new LinkedList<>(); diff --git a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java index 999d040b48c..ac936ee989e 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java +++ b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java @@ -5,7 +5,9 @@ import com.yahoo.document.ArrayDataType; import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; +import com.yahoo.document.MapDataType; import com.yahoo.document.PrimitiveDataType; +import com.yahoo.document.StructDataType; import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructuredDataType; import com.yahoo.document.TensorDataType; @@ -143,8 +145,8 @@ public final class Attribute implements Cloneable, Serializable { } /** Creates an attribute with default settings */ - public Attribute(String name, DataType fieldType) { - this(name, convertDataType(fieldType), convertCollectionType(fieldType), convertTensorType(fieldType), convertTargetType(fieldType)); + public Attribute(String schemaName, String fieldName, String name, DataType fieldType) { + this(name, convertDataType(schemaName, fieldName, fieldType), convertCollectionType(fieldType), convertTensorType(fieldType), convertTargetType(fieldType)); setRemoveIfZero(fieldType instanceof WeightedSetDataType wsdt && wsdt.removeIfZero()); setCreateIfNonExistent(fieldType instanceof WeightedSetDataType wsdt && wsdt.createIfNonExistent()); } @@ -266,12 +268,26 @@ public final class Attribute implements Cloneable, Serializable { private void setType(Type type) { this.type=type; } public void setCollectionType(CollectionType type) { this.collectionType=type; } + private static void failDataType(String schemaName, String fieldName, String dataType) throws IllegalArgumentException { + throw new IllegalArgumentException("For schema '" + schemaName + "': Field '" + fieldName + "' of type '" + dataType + "' cannot be an attribute. " + + "Instead specify the struct fields to be searchable as attribute"); + } + public static void validateDataType(String schemaName, String fieldName, DataType fieldType) throws IllegalArgumentException { + if (fieldType instanceof MapDataType mapType) { + failDataType(schemaName, fieldName, "map<" + mapType.getKeyType().getName() + "," + mapType.getValueType().getName() + ">"); + } + if (fieldType instanceof ArrayDataType arrayType && arrayType.getNestedType() instanceof StructDataType nestedType) { + failDataType(schemaName, fieldName, "array<" + nestedType.getName() + ">"); + } + } + /** Converts to the right attribute type from a field datatype */ - public static Type convertDataType(DataType fieldType) { + public static Type convertDataType(String schemaName, String fieldName, DataType fieldType) { + validateDataType(schemaName, fieldName, fieldType); if (fieldType instanceof NewDocumentReferenceDataType) { return Type.REFERENCE; } else if (fieldType instanceof CollectionDataType) { - return convertDataType(((CollectionDataType) fieldType).getNestedType()); + return convertDataType(schemaName, fieldName, ((CollectionDataType) fieldType).getNestedType()); } FieldValue fval = fieldType.createFieldValue(); if (fval instanceof StringFieldValue) { diff --git a/config-model/src/main/java/com/yahoo/schema/document/ImmutableImportedSDField.java b/config-model/src/main/java/com/yahoo/schema/document/ImmutableImportedSDField.java index cb98cb79e01..7ade7ada061 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/ImmutableImportedSDField.java +++ b/config-model/src/main/java/com/yahoo/schema/document/ImmutableImportedSDField.java @@ -10,7 +10,6 @@ import com.yahoo.vespa.indexinglanguage.expressions.Expression; import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -131,7 +130,7 @@ public class ImmutableImportedSDField implements ImmutableSDField { @Override public Map<String, String> getAliasToName() { - return Collections.emptyMap(); + return Map.of(); } @Override diff --git a/config-model/src/main/java/com/yahoo/schema/document/SDField.java b/config-model/src/main/java/com/yahoo/schema/document/SDField.java index 538cb56d210..f165141b16e 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/SDField.java +++ b/config-model/src/main/java/com/yahoo/schema/document/SDField.java @@ -398,22 +398,23 @@ public class SDField extends Field implements TypedKey, ImmutableSDField { } /** Parse an indexing expression which will use the simple linguistics implementation suitable for testing */ - public void parseIndexingScript(String script) { - parseIndexingScript(script, new SimpleLinguistics(), Embedder.throwsOnUse.asMap()); + public void parseIndexingScript(String schemaName, String script) { + parseIndexingScript(schemaName, script, new SimpleLinguistics(), Embedder.throwsOnUse.asMap()); } - public void parseIndexingScript(String script, Linguistics linguistics, Map<String, Embedder> embedders) { + public void parseIndexingScript(String schemaName, String script, Linguistics linguistics, Map<String, Embedder> embedders) { try { ScriptParserContext config = new ScriptParserContext(linguistics, embedders); config.setInputStream(new IndexingInput(script)); - setIndexingScript(ScriptExpression.newInstance(config)); + setIndexingScript(schemaName, ScriptExpression.newInstance(config)); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse script '" + script + "'", e); } } /** Sets the indexing script of this, or null to not use a script */ - public void setIndexingScript(ScriptExpression exp) { + + public void setIndexingScript(String schemaName, ScriptExpression exp) { if (exp == null) { exp = new ScriptExpression(); } @@ -441,13 +442,13 @@ public class SDField extends Field implements TypedKey, ImmutableSDField { } Attribute attribute = attributes.get(fieldName); if (attribute == null) { - addAttribute(new Attribute(fieldName, getDataType())); + addAttribute(new Attribute(schemaName, fieldName, fieldName, getDataType())); } } }.visit(indexingScript); } for (SDField structField : getStructFields()) { - structField.setIndexingScript(exp); + structField.setIndexingScript(schemaName, exp); } } diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java index 22a9eed2914..5a0c2c3c915 100644 --- a/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java +++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java @@ -12,7 +12,7 @@ import com.yahoo.schema.document.SDField; public interface FieldOperation extends Comparable<FieldOperation> { /** Apply this operation on the given field */ - void apply(SDField field); + void apply(String schemaName, SDField field); @Override default int compareTo(FieldOperation other) { diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java index f5366c4b07a..11065f040ea 100644 --- a/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java +++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java @@ -28,8 +28,8 @@ public class IndexingOperation implements FieldOperation { public ScriptExpression getScript() { return script; } - public void apply(SDField field) { - field.setIndexingScript(script); + public void apply(String schemaName, SDField field) { + field.setIndexingScript(schemaName, script); } /** Creates an indexing operation which will use the simple linguistics implementation suitable for testing */ diff --git a/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedFields.java b/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedFields.java index e3ca0090408..053a5ac777b 100644 --- a/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedFields.java +++ b/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedFields.java @@ -2,6 +2,7 @@ package com.yahoo.schema.parser; import com.yahoo.document.DataType; +import com.yahoo.schema.document.GeoPos; import com.yahoo.schema.parser.ConvertParsedTypes.TypeResolver; import com.yahoo.schema.Index; import com.yahoo.schema.Schema; @@ -49,10 +50,10 @@ public class ConvertParsedFields { (exactMatchTerminator -> field.getMatching().setExactMatchTerminator(exactMatchTerminator)); } - void convertSorting(SDField field, ParsedSorting parsed, String name) { + void convertSorting(Schema schema, SDField field, ParsedSorting parsed, String name) { Attribute attribute = field.getAttributes().get(name); if (attribute == null) { - attribute = new Attribute(name, field.getDataType()); + attribute = new Attribute(schema.getName(), field.getName(), name, field.getDataType()); field.addAttribute(attribute); } Sorting sorting = attribute.getSorting(); @@ -66,7 +67,7 @@ public class ConvertParsedFields { parsed.getLocale().ifPresent(locale -> sorting.setLocale(locale)); } - void convertAttribute(SDField field, ParsedAttribute parsed) { + void convertAttribute(Schema schema, SDField field, ParsedAttribute parsed) { String name = parsed.name(); String fieldName = field.getName(); Attribute attribute = null; @@ -76,7 +77,7 @@ public class ConvertParsedFields { if (attribute == null) { attribute = field.getAttributes().get(name); if (attribute == null) { - attribute = new Attribute(name, field.getDataType()); + attribute = new Attribute(schema.getName(), field.getName(), name, field.getDataType()); field.addAttribute(attribute); } } @@ -102,7 +103,7 @@ public class ConvertParsedFields { } var sorting = parsed.getSorting(); if (sorting.isPresent()) { - convertSorting(field, sorting.get(), name); + convertSorting(schema, field, sorting.get(), name); } } @@ -143,13 +144,16 @@ public class ConvertParsedFields { convertMatchSettings(field, parsed.matchSettings()); var indexing = parsed.getIndexing(); if (indexing.isPresent()) { - field.setIndexingScript(indexing.get().script()); + field.setIndexingScript(schema.getName(), indexing.get().script()); + } + if (field.doesAttributing() && !GeoPos.isAnyPos(field.getDataType())) { + Attribute.validateDataType(schema.getName(), field.getName(), field.getDataType()); } parsed.getWeight().ifPresent(value -> field.setWeight(value)); parsed.getStemming().ifPresent(value -> field.setStemming(value)); parsed.getNormalizing().ifPresent(value -> convertNormalizing(field, value)); for (var attribute : parsed.getAttributes()) { - convertAttribute(field, attribute); + convertAttribute(schema, field, attribute); } for (var summaryField : parsed.getSummaryFields()) { var dataType = field.getDataType(); @@ -190,7 +194,7 @@ public class ConvertParsedFields { convertCommonFieldSettings(schema, structField, parsed); } - private void convertExtraFieldSettings(SDField field, ParsedField parsed) { + private void convertExtraFieldSettings(Schema schema, SDField field, ParsedField parsed) { String name = parsed.name(); for (var dictOp : parsed.getDictionaryOptions()) { var dictionary = field.getOrSetDictionary(); @@ -208,7 +212,7 @@ public class ConvertParsedFields { field.getAliasToName().put(alias, parsed.lookupAliasedFrom(alias)); } parsed.getRankTypes().forEach((indexName, rankType) -> convertRankType(field, indexName, rankType)); - parsed.getSorting().ifPresent(sortInfo -> convertSorting(field, sortInfo, name)); + parsed.getSorting().ifPresent(sortInfo -> convertSorting(schema, field, sortInfo, name)); if (parsed.hasBolding()) { // TODO must it be so ugly: SummaryField summaryField = field.getSummaryField(name, true); @@ -288,7 +292,7 @@ public class ConvertParsedFields { DataType dataType = context.resolveType(parsed.getType()); var field = new SDField(document, name, dataType); convertCommonFieldSettings(schema, field, parsed); - convertExtraFieldSettings(field, parsed); + convertExtraFieldSettings(schema, field, parsed); document.addField(field); return field; } @@ -298,7 +302,7 @@ public class ConvertParsedFields { DataType dataType = context.resolveType(parsed.getType()); var field = new SDField(schema.getDocument(), name, dataType); convertCommonFieldSettings(schema, field, parsed); - convertExtraFieldSettings(field, parsed); + convertExtraFieldSettings(schema, field, parsed); schema.addExtraField(field); } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/CreatePositionZCurve.java b/config-model/src/main/java/com/yahoo/schema/processing/CreatePositionZCurve.java index 7bd66ad8f0b..deb57e157f3 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/CreatePositionZCurve.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/CreatePositionZCurve.java @@ -86,14 +86,14 @@ public class CreatePositionZCurve extends Processor { SummaryTransform.DISTANCE, summaryTo, validate); } // clear indexing script - field.setIndexingScript(null); + field.setIndexingScript(schema.getName(), null); SDField posX = field.getStructField(PositionDataType.FIELD_X); if (posX != null) { - posX.setIndexingScript(null); + posX.setIndexingScript(schema.getName(), null); } SDField posY = field.getStructField(PositionDataType.FIELD_Y); if (posY != null) { - posY.setIndexingScript(null); + posY.setIndexingScript(schema.getName(), null); } if (doesSummary) ensureCompatibleSummary(field, zName, field.getName(), @@ -118,7 +118,7 @@ public class CreatePositionZCurve extends Processor { ScriptExpression script = inputField.getIndexingScript(); script = (ScriptExpression)new RemoveSummary(inputField.getName()).convert(script); script = (ScriptExpression)new PerformZCurve(field, fieldName).convert(script); - field.setIndexingScript(script); + field.setIndexingScript(schema.getName(), script); return field; } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/ExactMatch.java b/config-model/src/main/java/com/yahoo/schema/processing/ExactMatch.java index a12183262c4..056c37a9830 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/ExactMatch.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/ExactMatch.java @@ -75,7 +75,7 @@ public class ExactMatch extends Processor { } ScriptExpression script = field.getIndexingScript(); if (new ExpressionSearcher<>(IndexExpression.class).containedIn(script)) { - field.setIndexingScript((ScriptExpression)new MyProvider(schema).convert(field.getIndexingScript())); + field.setIndexingScript(schema.getName(), (ScriptExpression)new MyProvider(schema).convert(field.getIndexingScript())); } } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java index 53ebd136e08..a5ba67d6976 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java @@ -36,7 +36,7 @@ public class IndexingInputs extends Processor { if (validate) new VerifyInputExpression(schema, field).visit(script); - field.setIndexingScript(script); + field.setIndexingScript(schema.getName(), script); } } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingOutputs.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingOutputs.java index 071c2878ae8..b5d1cf71809 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingOutputs.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingOutputs.java @@ -37,7 +37,7 @@ public class IndexingOutputs extends Processor { Set<String> summaryFields = new TreeSet<>(); findSummaryTo(schema, field, summaryFields, summaryFields); MyConverter converter = new MyConverter(schema, field, summaryFields, validate); - field.setIndexingScript((ScriptExpression)converter.convert(script)); + field.setIndexingScript(schema.getName(), (ScriptExpression)converter.convert(script)); } } @@ -106,7 +106,7 @@ public class IndexingOutputs extends Processor { MyConverter(Schema schema, Field field, Set<String> summaryFields, boolean validate) { this.schema = schema; this.field = field; - this.summaryFields = summaryFields.isEmpty() ? Collections.singleton(field.getName()) : summaryFields; + this.summaryFields = summaryFields.isEmpty() ? Set.of(field.getName()) : summaryFields; this.validate = validate; } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IntegerIndex2Attribute.java b/config-model/src/main/java/com/yahoo/schema/processing/IntegerIndex2Attribute.java index 0d296783cfb..37815ef5396 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IntegerIndex2Attribute.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IntegerIndex2Attribute.java @@ -38,7 +38,7 @@ public class IntegerIndex2Attribute extends Processor { ScriptExpression script = field.getIndexingScript(); Set<String> attributeNames = new HashSet<>(); new MyVisitor(attributeNames).visit(script); - field.setIndexingScript((ScriptExpression)new MyConverter(attributeNames).convert(script)); + field.setIndexingScript(schema.getName(), (ScriptExpression)new MyConverter(attributeNames).convert(script)); warn(schema, field, "Changed to attribute because numerical indexes (field has type " + field.getDataType().getName() + ") is not currently supported." + " Index-only settings may fail. Ignore this warning for streaming search."); diff --git a/config-model/src/main/java/com/yahoo/schema/processing/NGramMatch.java b/config-model/src/main/java/com/yahoo/schema/processing/NGramMatch.java index 2ec5c03e04c..c06e0565109 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/NGramMatch.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/NGramMatch.java @@ -46,7 +46,7 @@ public class NGramMatch extends Processor { field.getNormalizing().inferCodepoint(); field.setStemming(Stemming.NONE); // not compatible with stemming and normalizing field.addQueryCommand("ngram " + n); - field.setIndexingScript((ScriptExpression)new MyProvider(schema, n).convert(field.getIndexingScript())); + field.setIndexingScript(schema.getName(), (ScriptExpression)new MyProvider(schema, n).convert(field.getIndexingScript())); } private static class MyProvider extends TypedTransformProvider { diff --git a/config-model/src/main/java/com/yahoo/schema/processing/OptimizeIlscript.java b/config-model/src/main/java/com/yahoo/schema/processing/OptimizeIlscript.java index b268a7a9c03..fbb49497837 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/OptimizeIlscript.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/OptimizeIlscript.java @@ -27,7 +27,7 @@ public class OptimizeIlscript extends Processor { ScriptExpression script = field.getIndexingScript(); if (script == null) continue; - field.setIndexingScript((ScriptExpression)new ExpressionOptimizer().convert(script)); + field.setIndexingScript(schema.getName(), (ScriptExpression)new ExpressionOptimizer().convert(script)); if ( ! field.getIndexingScript().toString().equals(script.toString())) { info(schema, field, "Rewrote ilscript from:\n" + script.toString() + "\nto\n" + field.getIndexingScript().toString()); diff --git a/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java b/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java index 2a654991835..c451df6370d 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java @@ -107,7 +107,7 @@ public class PredicateProcessor extends Processor { script = new StatementExpression(makeSetPredicateVariablesScript(booleanIndexDefiniton), script); ExpressionConverter converter = new PredicateOutputTransformer(schema); - field.setIndexingScript(new ScriptExpression((StatementExpression)converter.convert(script))); + field.setIndexingScript(schema.getName(), new ScriptExpression((StatementExpression)converter.convert(script))); } private Expression makeSetPredicateVariablesScript(BooleanIndexDefinition options) { diff --git a/config-model/src/main/java/com/yahoo/schema/processing/Processing.java b/config-model/src/main/java/com/yahoo/schema/processing/Processing.java index c23d87e9eba..52078326aec 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/Processing.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/Processing.java @@ -9,8 +9,8 @@ import com.yahoo.vespa.model.container.search.QueryProfiles; import com.yahoo.config.model.api.ModelContext; import com.yahoo.config.model.deploy.TestProperties; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Set; /** @@ -28,7 +28,7 @@ public class Processing { public Processing(ModelContext.Properties properties) { this.properties = properties; } private Collection<ProcessorFactory> processors() { - return Arrays.asList( + return List.<ProcessorFactory>of( SearchMustHaveDocument::new, UrlFieldValidator::new, BuiltInFieldSets::new, @@ -99,7 +99,7 @@ public class Processing { /** Processors of rank profiles only (those who tolerate and do something useful when the search field is null) */ private Collection<ProcessorFactory> rankProfileProcessors() { - return Arrays.asList( + return List.of( RankProfileTypeSettingsProcessor::new, ReservedFunctionNames::new, RankingExpressionTypeResolver::new); diff --git a/config-model/src/main/java/com/yahoo/schema/processing/Processor.java b/config-model/src/main/java/com/yahoo/schema/processing/Processor.java index beaff13c613..dd36bbb3b61 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/Processor.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/Processor.java @@ -87,7 +87,7 @@ public abstract class Processor { implementationField.setRankType(RankType.EMPTY); implementationField.setStemming(Stemming.NONE); implementationField.getNormalizing().inferCodepoint(); - implementationField.parseIndexingScript(indexing); + implementationField.parseIndexingScript(schema.getName(), indexing); String indexName = field.getName(); String implementationIndexName = indexName + "_" + suffix; Index implementationIndex = new Index(implementationIndexName); diff --git a/config-model/src/main/java/com/yahoo/schema/processing/TextMatch.java b/config-model/src/main/java/com/yahoo/schema/processing/TextMatch.java index e6fed35b821..e29f683761f 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/TextMatch.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/TextMatch.java @@ -48,7 +48,7 @@ public class TextMatch extends Processor { if ( ! visitor.requiresTokenize) continue; ExpressionConverter converter = new MyStringTokenizer(schema, findAnnotatorConfig(schema, field)); - field.setIndexingScript((ScriptExpression)converter.convert(script)); + field.setIndexingScript(schema.getName(), (ScriptExpression)converter.convert(script)); } } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/UriHack.java b/config-model/src/main/java/com/yahoo/schema/processing/UriHack.java index e4e2ac9f5be..9a4c4038953 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/UriHack.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/UriHack.java @@ -12,7 +12,6 @@ import com.yahoo.schema.document.SDField; import com.yahoo.schema.document.Stemming; import com.yahoo.vespa.model.container.search.QueryProfiles; -import java.util.Arrays; import java.util.List; /** @@ -21,7 +20,7 @@ import java.util.List; public class UriHack extends Processor { private static final List<String> URL_SUFFIX = - Arrays.asList("scheme", "host", "port", "path", "query", "fragment", "hostname"); + List.of("scheme", "host", "port", "path", "query", "fragment", "hostname"); UriHack(Schema schema, DeployLogger deployLogger, @@ -52,8 +51,7 @@ public class UriHack extends Processor { if (uriField.getDataType() instanceof ArrayDataType) { generatedType = new ArrayDataType(DataType.STRING); } - else if (uriField.getDataType() instanceof WeightedSetDataType) { - WeightedSetDataType wdt = (WeightedSetDataType) uriField.getDataType(); + else if (uriField.getDataType() instanceof WeightedSetDataType wdt) { generatedType = new WeightedSetDataType(DataType.STRING, wdt.createIfNonExistent(), wdt.removeIfZero()); } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/multifieldresolver/IndexCommandResolver.java b/config-model/src/main/java/com/yahoo/schema/processing/multifieldresolver/IndexCommandResolver.java index 111f5384c41..2854824e5b7 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/multifieldresolver/IndexCommandResolver.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/multifieldresolver/IndexCommandResolver.java @@ -5,8 +5,6 @@ import com.yahoo.config.application.api.DeployLogger; import com.yahoo.schema.document.SDField; import com.yahoo.schema.Schema; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -16,17 +14,10 @@ import java.util.logging.Level; public class IndexCommandResolver extends MultiFieldResolver { /** Commands which don't have to be harmonized between fields */ - private static List<String> ignoredCommands = new ArrayList<>(); + private static final List<String> ignoredCommands = List.of( "complete-boost", "literal-boost", "highlight"); /** Commands which must be harmonized between fields */ - private static List<String> harmonizedCommands = new ArrayList<>(); - - static { - String[] ignore = { "complete-boost", "literal-boost", "highlight" }; - ignoredCommands.addAll(Arrays.asList(ignore)); - String[] harmonize = { "stemming", "normalizing" }; - harmonizedCommands.addAll(Arrays.asList(harmonize)); - } + private static final List<String> harmonizedCommands = List.of("stemming", "normalizing"); public IndexCommandResolver(String indexName, List<SDField> fields, Schema schema, DeployLogger logger) { super(indexName, fields, schema, logger); @@ -53,8 +44,8 @@ public class IndexCommandResolver extends MultiFieldResolver { ", adding to field " + field.getName()); field.addQueryCommand(command); } else { - deployLogger.logApplicationPackage(Level.WARNING, "All fields going to the same index should have the same query-commands. Field \'" + field.getName() + - "\' doesn't contain command \'" + command+"\'"); + deployLogger.logApplicationPackage(Level.WARNING, "All fields going to the same index should have the same query-commands. Field '" + field.getName() + + "' doesn't contain command '" + command+"'"); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java b/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java index f1d3b38e8ff..348a5d575eb 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.model; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.provision.NetworkPorts; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -28,7 +27,7 @@ public class HostPorts { private int allocatedPorts = 0; - private PortFinder portFinder = new PortFinder(Collections.emptyList()); + private PortFinder portFinder = new PortFinder(List.of()); private boolean flushed = false; private Optional<NetworkPorts> networkPortsList = Optional.empty(); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 1c4b0d31ab2..c876976917b 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -36,7 +36,6 @@ import java.io.IOException; import java.time.Clock; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.logging.Level; @@ -96,7 +95,7 @@ public class VespaModelFactory implements ModelFactory { } else { this.configModelRegistry = configModelRegistry; } - this.modelImporters = Collections.emptyList(); + this.modelImporters = List.of(); this.additionalValidators = List.of(); this.zone = zone; this.clock = clock; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainerCluster.java index 78ef6826d26..c19d186df42 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainerCluster.java @@ -10,7 +10,6 @@ import com.yahoo.vespa.model.container.ContainerCluster; import com.yahoo.vespa.model.container.PlatformBundles; import java.nio.file.Path; -import java.util.Collections; import java.util.Optional; import java.util.Set; @@ -22,7 +21,7 @@ import java.util.Set; */ public class ClusterControllerContainerCluster extends ContainerCluster<ClusterControllerContainer> { - private static final Set<Path> UNNECESSARY_BUNDLES = Collections.unmodifiableSet(PlatformBundles.VESPA_SECURITY_BUNDLES); + private static final Set<Path> UNNECESSARY_BUNDLES = Set.copyOf(PlatformBundles.VESPA_SECURITY_BUNDLES); private final ReindexingContext reindexingContext; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java index 0d85696d503..913ae0e1a00 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java @@ -36,7 +36,6 @@ import com.yahoo.vespa.model.container.component.Handler; import com.yahoo.vespa.model.container.component.SystemBindingPattern; import java.nio.file.Path; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; @@ -198,7 +197,7 @@ public class MetricsProxyContainerCluster extends ContainerCluster<MetricsProxyC private Map<String, MetricsConsumer> getUserMetricsConsumers() { return getAdmin() .map(admin -> admin.getUserMetrics().getConsumers()) - .orElse(Collections.emptyMap()); + .orElse(Map.of()); } private Optional<String> getSystemName() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricsConsumer.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricsConsumer.java index aa476b1ae39..0a933e7d5ed 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricsConsumer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricsConsumer.java @@ -7,7 +7,6 @@ import ai.vespa.metrics.set.Vespa9VespaMetricSet; import ai.vespa.metricsproxy.core.VespaMetrics; import ai.vespa.metricsproxy.http.ValuesFetcher; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Objects; @@ -71,7 +70,7 @@ public class MetricsConsumer { } public static MetricsConsumer consumer(String id, MetricSet ... metricSets) { - return new MetricsConsumer(id, new MetricSet(id + "-consumer-metrics", List.of(), Arrays.asList(metricSets))); + return new MetricsConsumer(id, new MetricSet(id + "-consumer-metrics", List.of(), List.of(metricSets))); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java index 0a23e25e432..4b4cb1530d4 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java @@ -5,7 +5,6 @@ import com.yahoo.config.model.deploy.DeployState; import org.w3c.dom.Document; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -35,7 +34,7 @@ public class BundleValidator extends AbstractBundleValidator { for (Map.Entry<Object,Object> entry : attributes.entrySet()) { mfAttributes.add(entry.getKey().toString()); } - List<String> requiredOSGIHeaders = Arrays.asList( + List<String> requiredOSGIHeaders = List.of( "Bundle-ManifestVersion", "Bundle-Name", "Bundle-SymbolicName", "Bundle-Version"); for (String header : requiredOSGIHeaders) { if (!mfAttributes.contains(header)) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidator.java index e0a43f0988a..ddffe20f725 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidator.java @@ -3,7 +3,7 @@ package com.yahoo.vespa.model.application.validation; import org.w3c.dom.Document; -import java.util.Arrays; +import java.util.List; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.logging.Level; @@ -18,7 +18,7 @@ public class PublicApiBundleValidator extends AbstractBundleValidator { String nonPublicApiAttribute = mf.getMainAttributes().getValue("X-JDisc-Non-PublicApi-Import-Package"); if (nonPublicApiAttribute == null) return; - var nonPublicApisUsed = Arrays.asList(nonPublicApiAttribute.split(",")); + var nonPublicApisUsed = List.of(nonPublicApiAttribute.split(",")); if (! nonPublicApisUsed.isEmpty()) { log(context.deployState(), Level.WARNING, "Jar file '%s' uses non-public Vespa APIs: %s", filename(jar), nonPublicApisUsed); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java index 046980087ed..bde12bb1d5a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java @@ -151,7 +151,7 @@ public class ComponentsBuilder<T extends ChainedComponent<?>> { private Map<String, ComponentType<?>> unmodifiable(Map<String, ComponentType<?>> outerComponentTypeByComponentName) { return (outerComponentTypeByComponentName != null)? Collections.unmodifiableMap(outerComponentTypeByComponentName): - Collections.emptyMap(); + Map.of(); } public Collection<T> getComponentDefinitions() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomGenericTargetBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomGenericTargetBuilder.java index 565cdf3a5f5..b8de223c0cb 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomGenericTargetBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomGenericTargetBuilder.java @@ -9,7 +9,7 @@ import com.yahoo.vespa.model.container.search.searchchain.GenericTarget; import com.yahoo.vespa.model.container.search.searchchain.Searcher; import org.w3c.dom.Element; -import java.util.Arrays; +import java.util.List; import java.util.Map; /** @@ -20,7 +20,7 @@ import java.util.Map; abstract public class DomGenericTargetBuilder<T extends GenericTarget> extends DomChainBuilderBase<Searcher<?>, T> { DomGenericTargetBuilder(Map<String, ComponentsBuilder.ComponentType<?>> outerSearcherTypeByComponentName) { - super(Arrays.asList(ComponentsBuilder.ComponentType.searcher, ComponentsBuilder.ComponentType.federation), + super(List.of(ComponentsBuilder.ComponentType.searcher, ComponentsBuilder.ComponentType.federation), outerSearcherTypeByComponentName); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainBuilder.java index 2eb1127d75b..4ada9e99e5e 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainBuilder.java @@ -11,7 +11,7 @@ import com.yahoo.vespa.model.container.search.searchchain.SearchChain; import com.yahoo.vespa.model.container.search.searchchain.Searcher; import org.w3c.dom.Element; -import java.util.Arrays; +import java.util.List; import java.util.Map; /** @@ -21,7 +21,7 @@ import java.util.Map; public class DomSearchChainBuilder extends DomChainBuilderBase<Searcher<?>, SearchChain> { public DomSearchChainBuilder(Map<String, ComponentsBuilder.ComponentType<?>> outerSearcherTypeByComponentName) { - super(Arrays.asList(ComponentsBuilder.ComponentType.searcher, ComponentsBuilder.ComponentType.federation), + super(List.of(ComponentsBuilder.ComponentType.searcher, ComponentsBuilder.ComponentType.federation), outerSearcherTypeByComponentName); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainsBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainsBuilder.java index e05d762d7bc..b48df948358 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainsBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSearchChainsBuilder.java @@ -11,7 +11,6 @@ import com.yahoo.vespa.model.container.search.searchchain.SearchChains; import com.yahoo.vespa.model.container.search.searchchain.Searcher; import org.w3c.dom.Element; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -23,7 +22,7 @@ import java.util.Map; public class DomSearchChainsBuilder extends DomChainsBuilder<Searcher<?>, SearchChain, SearchChains> { public DomSearchChainsBuilder() { - super(Arrays.asList(ComponentType.searcher, ComponentType.federation)); + super(List.of(ComponentType.searcher, ComponentType.federation)); } @Override diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/PlatformBundles.java b/config-model/src/main/java/com/yahoo/vespa/model/container/PlatformBundles.java index 1400a630e56..e801884a73a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/PlatformBundles.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/PlatformBundles.java @@ -71,7 +71,7 @@ public class PlatformBundles { private static Set<Path> toBundlePaths(String... bundleNames) { return Stream.of(bundleNames) .map(PlatformBundles::absoluteBundlePath) - .collect(Collectors.toSet()); + .collect(Collectors.toUnmodifiableSet()); } public static Path absoluteBundlePath(String fileName) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java index ed626f98aa0..dafac2c1af9 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.model.container.component; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -24,9 +23,9 @@ public class DiscBindingsConfigGenerator { public static <T extends Handler> Map<String, Handlers.Builder> generate(T handler) { if (handler.getServerBindings().isEmpty() && handler.getClientBindings().isEmpty()) - return Collections.emptyMap(); + return Map.of(); - return Collections.singletonMap(handler.model.getComponentId().stringValue(), + return Map.of(handler.model.getComponentId().stringValue(), new Handlers.Builder() .serverBindings(toStrings(handler.getServerBindings())) .clientBindings(toStrings(handler.getClientBindings()))); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java index 099255975b6..0d3d8462376 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java @@ -8,7 +8,6 @@ import com.yahoo.vespa.model.container.ContainerThreadpool; import org.w3c.dom.Element; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; @@ -51,7 +50,7 @@ public class Handler extends Component<Component<?, ?>, ComponentModel> { } public void addServerBindings(BindingPattern... bindings) { - serverBindings.addAll(Arrays.asList(bindings)); + serverBindings.addAll(List.of(bindings)); } public void addServerBindings(Collection<BindingPattern> bps) { serverBindings.addAll(bps); } @@ -61,7 +60,7 @@ public class Handler extends Component<Component<?, ?>, ComponentModel> { } public void addClientBindings(BindingPattern... bindings) { - clientBindings.addAll(Arrays.asList(bindings)); + clientBindings.addAll(List.of(bindings)); } public final Collection<BindingPattern> getServerBindings() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java index 7d6285d00c1..3a8e52c92a8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java @@ -13,6 +13,7 @@ import com.yahoo.vespa.model.container.xml.ModelIdResolver; import org.w3c.dom.Element; import java.net.URI; +import java.net.URISyntaxException; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -51,11 +52,22 @@ class Model { static Model fromXml(DeployState ds, Element model, Set<String> requiredTags) { var modelId = XmlHelper.getOptionalAttribute(model, "model-id").orElse(null); - var url = XmlHelper.getOptionalAttribute(model, "url").map(URI::create).orElse(null); + var url = XmlHelper.getOptionalAttribute(model, "url").map(Model::parseUrl).orElse(null); var path = XmlHelper.getOptionalAttribute(model, "path").map(Path::fromString).orElse(null); return new Model(ds, model.getTagName(), modelId, url, path, requiredTags); } + private static URI parseUrl(String url) { + try { + var uri = new URI(url); + if ( ! uri.isAbsolute()) + throw new IllegalArgumentException("Invalid url '" + url + "': url has no 'scheme' component"); + return uri; + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid url '" + url + "':" + e.getMessage()); + } + } + /** Return tokenizer model from XML if specified, alternatively use model id for ONNX model with suffix '-vocab' appended */ static Model fromXmlOrImplicitlyFromOnnxModel( DeployState ds, Element parent, Model onnxModel, String paramName, Set<String> requiredTags) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java index 8c1b868465a..19c45bba2ef 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java @@ -48,7 +48,7 @@ public class AccessControl { private final String domain; private ClientAuthentication clientAuthentication = ClientAuthentication.need; private final Set<BindingPattern> excludeBindings = new LinkedHashSet<>(); - private Collection<Handler> handlers = Collections.emptyList(); + private Collection<Handler> handlers = List.of(); public Builder(String domain) { this.domain = domain; } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainBuilder.java index bc234546625..82a8a01871e 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainBuilder.java @@ -11,7 +11,7 @@ import com.yahoo.vespa.model.container.http.HttpFilterChain; import org.w3c.dom.Element; import java.util.Collection; -import java.util.Collections; +import java.util.List; import java.util.Map; import static com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder.ComponentType; @@ -21,7 +21,7 @@ import static com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder.Com */ public class FilterChainBuilder extends DomChainBuilderBase<Filter, HttpFilterChain> { - private static final Collection<ComponentType<Filter>> allowedComponentTypes = Collections.singleton(ComponentType.filter); + private static final Collection<ComponentType<Filter>> allowedComponentTypes = List.of(ComponentType.filter); public FilterChainBuilder(Map<String, ComponentType<?>> outerFilterTypeByComponentName) { super(allowedComponentTypes, outerFilterTypeByComponentName); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainsBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainsBuilder.java index 878859a01bf..f1cdbfb3b04 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainsBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/FilterChainsBuilder.java @@ -15,7 +15,6 @@ import com.yahoo.vespa.model.container.http.HttpFilterChain; import org.w3c.dom.Element; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -24,7 +23,7 @@ import java.util.Map; */ public class FilterChainsBuilder extends DomChainsBuilder<Filter, HttpFilterChain, FilterChains> { private static final Collection<ComponentType<Filter>> allowedComponentTypes = - Collections.singleton(ComponentType.filter); + List.of(ComponentType.filter); private static final Map<String, Class<? extends DomChainBuilderBase<? extends Filter, ? extends HttpFilterChain>>> chainType2BuilderClass = Map.of( diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/Source.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/Source.java index 29e587c6453..f589884cccd 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/Source.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/Source.java @@ -4,9 +4,8 @@ package com.yahoo.vespa.model.container.search.searchchain; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.model.ChainSpecification; import com.yahoo.search.searchchain.model.federation.FederationOptions; -import com.yahoo.config.model.producer.TreeConfigProducer; -import java.util.Arrays; +import java.util.List; /** @@ -51,7 +50,7 @@ public class Source extends GenericTarget { @Override public ChainSpecification getChainSpecification() { return super.getChainSpecification().addInherits( - Arrays.asList(getParentProvider().getComponentId().toSpecification())); + List.of(getParentProvider().getComponentId().toSpecification())); } public ComponentId getGlobalComponentId() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java index 8a15e61495b..7e14eafc2ee 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java @@ -7,7 +7,6 @@ import com.yahoo.component.ComponentSpecification; import com.yahoo.vespa.model.container.PlatformBundles; import org.w3c.dom.Element; -import java.util.Arrays; import java.util.List; import static com.yahoo.vespa.model.container.component.chain.ProcessingHandler.PROCESSING_HANDLER_CLASS; @@ -39,9 +38,7 @@ public class BundleInstantiationSpecificationBuilder { private static void validate(BundleInstantiationSpecification instSpec) { - List<String> forbiddenClasses = Arrays.asList( - SearchHandler.HANDLER_CLASSNAME, - PROCESSING_HANDLER_CLASS); + List<String> forbiddenClasses = List.of(SearchHandler.HANDLER_CLASSNAME, PROCESSING_HANDLER_CLASS); for (String forbiddenClass: forbiddenClasses) { if (forbiddenClass.equals(instSpec.getClassName())) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 456ce8fdbc2..360a02256a9 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -114,7 +114,6 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -893,7 +892,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void addStandaloneNode(ApplicationContainerCluster cluster, DeployState deployState) { ApplicationContainer container = new ApplicationContainer(cluster, "standalone", cluster.getContainers().size(), deployState); - cluster.addContainers(Collections.singleton(container)); + cluster.addContainers(List.of(container)); } private static String buildJvmGCOptions(ConfigModelContext context, String jvmGCOptions) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java b/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java index 9d15eddbef3..6d482a6d4a6 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java @@ -35,7 +35,6 @@ import org.w3c.dom.Element; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; @@ -195,7 +194,7 @@ public class Content extends ConfigModel { public static class Builder extends ConfigModelBuilder<Content> { - public static final List<ConfigModelId> configModelIds = Collections.singletonList(ConfigModelId.fromName("content")); + public static final List<ConfigModelId> configModelIds = List.of(ConfigModelId.fromName("content")); public Builder() { super(Content.class); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java index 53547a1a15b..6dd7278fde8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java @@ -3,9 +3,6 @@ package com.yahoo.vespa.model.content; import com.yahoo.documentmodel.NewDocumentType; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -13,9 +10,8 @@ import java.util.stream.Collectors; public class ReservedDocumentTypeNameValidator { - public static final List<String> ORDERED_RESERVED_NAMES = Collections.unmodifiableList( - Arrays.asList("and", "false", "id", "not", "null", "or", "true")); - public static final Set<String> RESERVED_NAMES = Collections.unmodifiableSet(new HashSet<>(ORDERED_RESERVED_NAMES)); + public static final List<String> ORDERED_RESERVED_NAMES = List.of("and", "false", "id", "not", "null", "or", "true"); + public static final Set<String> RESERVED_NAMES = Set.copyOf(ORDERED_RESERVED_NAMES); public void validate(Map<String, NewDocumentType> documentDefinitions) { List<String> conflictingNames = documentDefinitions.keySet().stream() diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java b/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java index a6f53777c51..a1b9ed67aa7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java @@ -19,7 +19,6 @@ import com.yahoo.vespa.model.content.engines.PersistenceEngine; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -349,7 +348,7 @@ public class StorageGroup { owner.getStorageCluster().getClusterName(), owner.getRoot().hostSystem(), context) : - Collections.emptyMap(); + Map.of(); Map<Optional<ClusterSpec.Group>, Map<HostResource, ClusterMembership>> hostGroups = collectAllocatedSubgroups(hostMapping); if (hostGroups.size() > 1) { @@ -475,7 +474,7 @@ public class StorageGroup { } private List<XmlNodeBuilder> collectExplicitNodes(Optional<ModelElement> groupOrNodesElement) { - if (groupOrNodesElement.isEmpty()) return Collections.emptyList(); + if (groupOrNodesElement.isEmpty()) return List.of(); List<XmlNodeBuilder> nodes = new ArrayList<>(); for (ModelElement n : groupOrNodesElement.get().subElements("node")) nodes.add(new XmlNodeBuilder(clusterElement, n)); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java index c9b6537434b..07dafda164d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.model.content.cluster; import com.yahoo.documentmodel.NewDocumentType; import com.yahoo.vespa.model.builder.xml.dom.ModelElement; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -20,19 +19,19 @@ public class GlobalDistributionBuilder { private final Map<String, NewDocumentType> documentDefinitions; public GlobalDistributionBuilder(Map<String, NewDocumentType> documentDefinitions) { - this.documentDefinitions = Collections.unmodifiableMap(documentDefinitions); + this.documentDefinitions = Map.copyOf(documentDefinitions); } public Set<NewDocumentType> build(ModelElement documentsElement) { if (documentsElement == null || documentsElement.subElements("document").isEmpty()) - return Collections.emptySet(); + return Set.of(); return documentsElement.subElements("document") .stream() .filter(GlobalDistributionBuilder::isGloballyDistributed) .map(GlobalDistributionBuilder::getDocumentName) .map(this::getDocumentType) - .collect(Collectors.toCollection(() -> new LinkedHashSet<>())); + .collect(Collectors.toCollection(LinkedHashSet::new)); } private static boolean isGloballyDistributed(ModelElement e) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java index 621377e0606..78ed10a583e 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java @@ -32,7 +32,6 @@ import java.io.StringReader; import java.io.UncheckedIOException; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -177,7 +176,7 @@ public class ConvertedModel { if (arguments.output().isEmpty()) { List<Map.Entry<String, ExpressionFunction>> entriesWithTheRightPrefix = expressions.entrySet().stream().filter(entry -> entry.getKey().startsWith(arguments.signature().get() + ".")).toList(); - if (entriesWithTheRightPrefix.size() < 1) + if (entriesWithTheRightPrefix.isEmpty()) throw new IllegalArgumentException("No expressions named '" + arguments.signature().get() + missingExpressionMessageSuffix()); if (entriesWithTheRightPrefix.size() > 1) @@ -191,7 +190,7 @@ public class ConvertedModel { private String missingExpressionMessageSuffix() { return "' in model '" + modelDescription + "'. " + - "Available expressions: " + expressions.keySet().stream().collect(Collectors.joining(", ")); + "Available expressions: " + String.join(", ", expressions.keySet()); } // ----------------------- Static model conversion/storage below here @@ -425,8 +424,7 @@ public class ConvertedModel { } private static void addFunctionNamesIn(ExpressionNode node, Set<String> names, ImportedMlModel model) { - if (node instanceof ReferenceNode) { - ReferenceNode referenceNode = (ReferenceNode)node; + if (node instanceof ReferenceNode referenceNode) { if (referenceNode.getOutput() == null) { // function references cannot specify outputs if (names.add(referenceNode.getName())) { if (model.functions().containsKey(referenceNode.getName())) { @@ -485,7 +483,7 @@ public class ConvertedModel { List<Pair<String, ExpressionFunction>> readExpressions() { List<Pair<String, ExpressionFunction>> expressions = new ArrayList<>(); ApplicationFile expressionPath = application.getFile(modelFiles.expressionsPath()); - if ( ! expressionPath.exists() || ! expressionPath.isDirectory()) return Collections.emptyList(); + if ( ! expressionPath.exists() || ! expressionPath.isDirectory()) return List.of(); for (ApplicationFile expressionFile : expressionPath.listFiles()) { try (BufferedReader reader = new BufferedReader(expressionFile.createReader())) { String name = expressionFile.getPath().getName(); @@ -525,7 +523,7 @@ public class ConvertedModel { List<Pair<String, RankingExpression>> readFunctions() { try { ApplicationFile file = application.getFile(modelFiles.functionsPath()); - if ( ! file.exists()) return Collections.emptyList(); + if ( ! file.exists()) return List.of(); List<Pair<String, RankingExpression>> functions = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(file.createReader())) { @@ -597,7 +595,7 @@ public class ConvertedModel { private List<Pair<String, Tensor>> readSmallConstants() { try { ApplicationFile file = application.getFile(modelFiles.smallConstantsPath()); - if ( ! file.exists()) return Collections.emptyList(); + if ( ! file.exists()) return List.of(); List<Pair<String, Tensor>> constants = new ArrayList<>(); BufferedReader reader = new BufferedReader(file.createReader()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/ml/OnnxModelInfo.java b/config-model/src/main/java/com/yahoo/vespa/model/ml/OnnxModelInfo.java index 502924ed31a..f47a48b09d7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/ml/OnnxModelInfo.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/ml/OnnxModelInfo.java @@ -17,7 +17,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -51,8 +50,8 @@ public class OnnxModelInfo { Map<String, OnnxTypeInfo> outputs, Set<String> initializers, String defaultOutput) { this.app = app; this.modelPath = path; - this.inputs = Collections.unmodifiableMap(inputs); - this.outputs = Collections.unmodifiableMap(outputs); + this.inputs = Map.copyOf(inputs); + this.outputs = Map.copyOf(outputs); this.defaultOutput = defaultOutput; this.initializers = Set.copyOf(initializers); } diff --git a/config-model/src/test/cfg/application/embed/services.xml b/config-model/src/test/cfg/application/embed/services.xml index e92679e3c96..089adbd7517 100644 --- a/config-model/src/test/cfg/application/embed/services.xml +++ b/config-model/src/test/cfg/application/embed/services.xml @@ -40,7 +40,7 @@ <component id="bert-embedder" type="bert-embedder"> <!-- model specifics --> - <transformer-model model-id="minilm-l6-v2" url="application-url"/> + <transformer-model model-id="minilm-l6-v2" url="https://my/url/model.onnx"/> <tokenizer-vocab path="files/vocab.txt"/> <max-tokens>512</max-tokens> <transformer-input-ids>my_input_ids</transformer-input-ids> diff --git a/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java b/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java index cb232c4f812..900799b86a1 100644 --- a/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import java.util.Collection; -import java.util.Collections; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -47,7 +46,7 @@ public class MapConfigModelRegistryTest { } @Override - public List<ConfigModelId> handlesElements() { return Collections.singletonList(ConfigModelId.fromName("modelB")); } + public List<ConfigModelId> handlesElements() { return List.of(ConfigModelId.fromName("modelB")); } @Override public void doBuild(ModelB model, Element spec, ConfigModelContext modelContext) { } } @@ -57,7 +56,7 @@ public class MapConfigModelRegistryTest { super(ModelB.class); } @Override - public List<ConfigModelId> handlesElements() { return Collections.singletonList(ConfigModelId.fromName("modelB")); } + public List<ConfigModelId> handlesElements() { return List.of(ConfigModelId.fromName("modelB")); } @Override public void doBuild(ModelB model, Element spec, ConfigModelContext modelContext) { } } @@ -73,7 +72,7 @@ public class MapConfigModelRegistryTest { super(ModelA.class); } @Override - public List<ConfigModelId> handlesElements() { return Collections.singletonList(ConfigModelId.fromName("modelA")); } + public List<ConfigModelId> handlesElements() { return List.of(ConfigModelId.fromName("modelA")); } @Override public void doBuild(ModelA model, Element spec, ConfigModelContext modelContext) { } diff --git a/config-model/src/test/java/com/yahoo/config/model/graph/GraphMock.java b/config-model/src/test/java/com/yahoo/config/model/graph/GraphMock.java index 327d48f9276..4c6a5d0e74b 100644 --- a/config-model/src/test/java/com/yahoo/config/model/graph/GraphMock.java +++ b/config-model/src/test/java/com/yahoo/config/model/graph/GraphMock.java @@ -8,7 +8,6 @@ import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; import org.w3c.dom.Element; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -20,7 +19,7 @@ public class GraphMock { public static class BA extends ConfigModelBuilder<A> { public BA() { super(A.class); } - @Override public List<ConfigModelId> handlesElements() { return Arrays.asList(); } + @Override public List<ConfigModelId> handlesElements() { return List.of(); } @Override public void doBuild(A model, Element spec, ConfigModelContext modelContext) { } } public static class A extends ConfigModel { @@ -29,7 +28,7 @@ public class GraphMock { public static class BB extends ConfigModelBuilder<B> { public BB() { super(B.class); } - @Override public List<ConfigModelId> handlesElements() { return Arrays.asList(); } + @Override public List<ConfigModelId> handlesElements() { return List.of(); } @Override public void doBuild(B model, Element spec, ConfigModelContext modelContext) { } } public static class B extends ConfigModel { @@ -40,7 +39,7 @@ public class GraphMock { public static class BC extends ConfigModelBuilder<C> { public BC() { super(C.class); } - @Override public List<ConfigModelId> handlesElements() { return Arrays.asList(); } + @Override public List<ConfigModelId> handlesElements() { return List.of(); } @Override public void doBuild(C model, Element spec, ConfigModelContext modelContext) { } } public static class C extends ConfigModel { @@ -51,7 +50,7 @@ public class GraphMock { public static class BD extends ConfigModelBuilder<D> { public BD() { super(D.class); } - @Override public List<ConfigModelId> handlesElements() { return Arrays.asList(); } + @Override public List<ConfigModelId> handlesElements() { return List.of(); } @Override public void doBuild(D model, Element spec, ConfigModelContext modelContext) { } } public static class D extends ConfigModel { @@ -60,7 +59,7 @@ public class GraphMock { public static class BE extends ConfigModelBuilder<E> { public BE() { super(E.class); } - @Override public List<ConfigModelId> handlesElements() { return Arrays.asList(); } + @Override public List<ConfigModelId> handlesElements() { return List.of(); } @Override public void doBuild(E model, Element spec, ConfigModelContext modelContext) { } } public static class E extends ConfigModel { diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java index 51574432e6d..02ca9effffb 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test; import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -22,27 +21,29 @@ import static org.junit.jupiter.api.Assertions.*; */ public class HostsXmlProvisionerTest { - private static final String oneHost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + - "<hosts>\n" + - " <host name=\"test1.yahoo.com\">\n" + - " <alias>node1</alias>\n" + - " <alias>node2</alias>\n" + - " </host>\n" + - "</hosts>"; - - private static final String threeHosts = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + - "<hosts>\n" + - " <host name=\"test1.yahoo.com\">\n" + - " <alias>node1</alias>\n" + - " </host>\n" + - " <host name=\"test2.yahoo.com\">\n" + - " <alias>node2</alias>\n" + - " <alias>node3</alias>\n" + - " </host>\n" + - " <host name=\"test3.yahoo.com\">\n" + - " <alias>node4</alias>\n" + - " </host>\n" + - "</hosts>"; + private static final String oneHost = """ + <?xml version="1.0" encoding="utf-8"?> + <hosts> + <host name="test1.yahoo.com"> + <alias>node1</alias> + <alias>node2</alias> + </host> + </hosts>"""; + + private static final String threeHosts = """ + <?xml version="1.0" encoding="utf-8"?> + <hosts> + <host name="test1.yahoo.com"> + <alias>node1</alias> + </host> + <host name="test2.yahoo.com"> + <alias>node2</alias> + <alias>node3</alias> + </host> + <host name="test3.yahoo.com"> + <alias>node4</alias> + </host> + </hosts>"""; @Test void require_basic_works() { @@ -57,7 +58,7 @@ public class HostsXmlProvisionerTest { assertTrue(map.keySet().containsAll(aliases)); // 5 services, 3 host aliases, mapping to 2 host. - aliases = createAliases(Collections.singletonList("node3")); + aliases = createAliases(List.of("node3")); map = allocate(hostProvisioner, aliases); assertCorrectNumberOfHosts(map, 2); @@ -65,7 +66,7 @@ public class HostsXmlProvisionerTest { assertTrue(map.keySet().containsAll(aliases)); // 5 services, 3 host aliases, mapping to 3 host. - aliases = createAliases(Collections.singletonList("node4")); + aliases = createAliases(List.of("node4")); map = allocate(hostProvisioner, aliases); assertEquals(3, map.size()); assertCorrectNumberOfHosts(map, 3); diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java index e5dca4e5adf..b4f586e3f2f 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java @@ -12,7 +12,6 @@ import org.xml.sax.SAXException; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -40,7 +39,7 @@ public class SingleNodeProvisionerTest { assertTrue(map.keySet().containsAll(aliases)); // 5 services, 3 host aliases, mapping to 2 host. - aliases = createAliases(Collections.singletonList("node3")); + aliases = createAliases(List.of("node3")); map = allocate(hostProvisioner, aliases); assertCorrectNumberOfHost(map, 1); @@ -48,7 +47,7 @@ public class SingleNodeProvisionerTest { assertTrue(map.keySet().containsAll(aliases)); // 5 services, 3 host aliases, mapping to 3 host. - aliases = createAliases(Collections.singletonList("node4")); + aliases = createAliases(List.of("node4")); map = allocate(hostProvisioner, aliases); assertThat(map.size(), is(3)); assertCorrectNumberOfHost(map, 1); diff --git a/config-model/src/test/java/com/yahoo/schema/AttributeUtils.java b/config-model/src/test/java/com/yahoo/schema/AttributeUtils.java index 69e7e14b3be..9ae24d6bfd4 100644 --- a/config-model/src/test/java/com/yahoo/schema/AttributeUtils.java +++ b/config-model/src/test/java/com/yahoo/schema/AttributeUtils.java @@ -8,8 +8,8 @@ import com.yahoo.schema.document.SDField; */ public class AttributeUtils { - public static void addAttributeAspect(SDField field) { - field.parseIndexingScript("{ attribute }"); + public static void addAttributeAspect(String schemaName, SDField field) { + field.parseIndexingScript(schemaName, "{ attribute }"); } } diff --git a/config-model/src/test/java/com/yahoo/schema/DocumentGraphValidatorTest.java b/config-model/src/test/java/com/yahoo/schema/DocumentGraphValidatorTest.java index defc7e59080..88761fc5d3f 100644 --- a/config-model/src/test/java/com/yahoo/schema/DocumentGraphValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/schema/DocumentGraphValidatorTest.java @@ -9,7 +9,6 @@ import com.yahoo.schema.document.TemporarySDField; import org.junit.jupiter.api.Test; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -142,14 +141,13 @@ public class DocumentGraphValidatorTest { Schema campaignSchema = new Schema(name, MockApplicationPackage.createEmpty()); SDDocumentType document = new SDDocumentType(name); campaignSchema.addDocument(document); - document.setDocumentReferences(new DocumentReferences(Collections.emptyMap())); + document.setDocumentReferences(new DocumentReferences(Map.of())); Arrays.stream(parents) .map(Schema::getDocument) .forEach(document::inherit); return campaignSchema; } - @SuppressWarnings("deprecation") private static void createDocumentReference(Schema from, Schema to, String refFieldName) { SDDocumentType fromDocument = from.getDocument(); SDField refField = new TemporarySDField(fromDocument, refFieldName, NewDocumentReferenceDataType.forDocumentName(to.getName())); diff --git a/config-model/src/test/java/com/yahoo/schema/DocumentReferenceResolverTest.java b/config-model/src/test/java/com/yahoo/schema/DocumentReferenceResolverTest.java index 76006ad28d7..99946406344 100644 --- a/config-model/src/test/java/com/yahoo/schema/DocumentReferenceResolverTest.java +++ b/config-model/src/test/java/com/yahoo/schema/DocumentReferenceResolverTest.java @@ -8,10 +8,9 @@ import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.document.SDField; import org.junit.jupiter.api.Test; +import java.util.List; import java.util.Map; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.*; /** @@ -34,13 +33,13 @@ public class DocumentReferenceResolverTest { SDDocumentType fooDocument = new SDDocumentType("foo", fooSchema); SDField fooRefToBarField = new SDField (fooDocument, "bar_ref", new NewDocumentReferenceDataType(barDocument.getDocumentType())); - AttributeUtils.addAttributeAspect(fooRefToBarField); + AttributeUtils.addAttributeAspect(fooSchema.getName(), fooRefToBarField); SDField irrelevantField = new SDField(fooDocument, "irrelevant_stuff", DataType.INT); fooDocument.addField(fooRefToBarField); fooDocument.addField(irrelevantField); fooSchema.addDocument(fooDocument); - DocumentReferenceResolver resolver = new DocumentReferenceResolver(asList(fooSchema, barSchema)); + DocumentReferenceResolver resolver = new DocumentReferenceResolver(List.of(fooSchema, barSchema)); resolver.resolveReferences(fooDocument); assertTrue(fooDocument.getDocumentReferences().isPresent()); @@ -50,7 +49,6 @@ public class DocumentReferenceResolverTest { assertSame(fooRefToBarField, fooReferenceMap.get("bar_ref").referenceField()); } - @SuppressWarnings("deprecation") @Test void throws_user_friendly_exception_if_referenced_document_does_not_exist() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> { @@ -60,11 +58,11 @@ public class DocumentReferenceResolverTest { SDField fooRefToBarField = new SDField( fooDocument, "bar_ref", NewDocumentReferenceDataType.forDocumentName("bar")); - AttributeUtils.addAttributeAspect(fooRefToBarField); + AttributeUtils.addAttributeAspect(fooSchema.getName(), fooRefToBarField); fooDocument.addField(fooRefToBarField); fooSchema.addDocument(fooDocument); - DocumentReferenceResolver resolver = new DocumentReferenceResolver(singletonList(fooSchema)); + DocumentReferenceResolver resolver = new DocumentReferenceResolver(List.of(fooSchema)); resolver.resolveReferences(fooDocument); }); assertTrue(exception.getMessage().contains("Invalid document reference 'bar_ref': Could not find document type 'bar'")); @@ -86,7 +84,7 @@ public class DocumentReferenceResolverTest { fooDocument.addField(fooRefToBarField); fooSchema.addDocument(fooDocument); - DocumentReferenceResolver resolver = new DocumentReferenceResolver(asList(fooSchema, barSchema)); + DocumentReferenceResolver resolver = new DocumentReferenceResolver(List.of(fooSchema, barSchema)); resolver.resolveReferences(fooDocument); }); assertTrue(exception.getMessage().contains("The field 'bar_ref' is an invalid document reference. The field must be an attribute.")); diff --git a/config-model/src/test/java/com/yahoo/schema/ImportedFieldsEnumeratorTest.java b/config-model/src/test/java/com/yahoo/schema/ImportedFieldsEnumeratorTest.java index 8c0b8c32d81..b96a43e9b53 100644 --- a/config-model/src/test/java/com/yahoo/schema/ImportedFieldsEnumeratorTest.java +++ b/config-model/src/test/java/com/yahoo/schema/ImportedFieldsEnumeratorTest.java @@ -22,7 +22,7 @@ public class ImportedFieldsEnumeratorTest { Schema parentSchema = new Schema(PARENT, MockApplicationPackage.createEmpty()); SDDocumentType parentDocument = new SDDocumentType(PARENT, parentSchema); var parentField = new SDField(parentDocument, "their_field", DataType.INT); - AttributeUtils.addAttributeAspect(parentField); + AttributeUtils.addAttributeAspect(parentSchema.getName(), parentField); parentDocument.addField(parentField); parentSchema.addDocument(parentDocument); diff --git a/config-model/src/test/java/com/yahoo/schema/derived/AttributeListTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/AttributeListTestCase.java index 0cfb9474365..f21999df94c 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/AttributeListTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/AttributeListTestCase.java @@ -14,6 +14,7 @@ import java.util.Iterator; import static com.yahoo.config.model.test.TestUtil.joinLines; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests attribute deriving @@ -126,4 +127,38 @@ public class AttributeListTestCase extends AbstractSchemaTestCase { assertFalse(attributes.hasNext()); } + @Test + void bad_map_attribute() throws ParseException { + run_bad_struct_or_map_attribute("map<string,string>"); + } + + @Test + void bad_array_of_struct_attribute() throws ParseException { + run_bad_struct_or_map_attribute("array<s>"); + } + + private void run_bad_struct_or_map_attribute(String type) throws ParseException { + run_bad_struct_or_map_attribute(type, false, true); + run_bad_struct_or_map_attribute(type, true, false); + run_bad_struct_or_map_attribute(type, true, true); + } + + private void run_bad_struct_or_map_attribute(String type, boolean fs, boolean ilscript) throws ParseException { + var exception = assertThrows(IllegalArgumentException.class, () -> ApplicationBuilder.createFromString( + joinLines("search test {", + " document test {", + " struct s {", + " field a type string { }", + " }", + " field metadata type " + type + " {", + " indexing: summary" + (ilscript ? "| attribute" : ""), + " " + (fs ? "attribute: fast-search" : ""), + " }", + " }", + "}")).getSchema()); + assertEquals("For schema 'test': Field 'metadata' of type '" + type + "' cannot be an attribute." + + " Instead specify the struct fields to be searchable as attribute", + exception.getMessage()); + } + } diff --git a/config-model/src/test/java/com/yahoo/schema/derived/IdTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/IdTestCase.java index 188017e0af1..60adf7cbaf0 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/IdTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/IdTestCase.java @@ -30,7 +30,7 @@ public class IdTestCase extends AbstractExportingTestCase { SDDocumentType document = new SDDocumentType("test"); schema.addDocument(document); SDField uri = new SDField(document, "URI", DataType.URI); - uri.parseIndexingScript("{ summary | index }"); + uri.parseIndexingScript(schema.getName(), "{ summary | index }"); document.addField(uri); new Processing().process(schema, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles(), diff --git a/config-model/src/test/java/com/yahoo/schema/derived/IndexSchemaTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/IndexSchemaTestCase.java index 766c19bd01c..596ea99c36d 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/IndexSchemaTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/IndexSchemaTestCase.java @@ -6,7 +6,6 @@ import com.yahoo.document.Field; import com.yahoo.document.StructDataType; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -194,7 +193,7 @@ public class IndexSchemaTestCase { private static void assertFlat(Field fieldToFlatten, Field... expectedFields) { List<Field> actual = new LinkedList<>(IndexSchema.flattenField(fieldToFlatten)); - List<Field> expected = new LinkedList<>(Arrays.asList(expectedFields)); + List<Field> expected = new LinkedList<>(List.of(expectedFields)); Collections.sort(actual); Collections.sort(expected); for (Field field : actual) { diff --git a/config-model/src/test/java/com/yahoo/schema/derived/InheritanceTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/InheritanceTestCase.java index 472fa58230e..b1dc2e66bee 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/InheritanceTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/InheritanceTestCase.java @@ -65,7 +65,7 @@ public class InheritanceTestCase extends AbstractExportingTestCase { derive("inheritdiamond", builder, builder.getSchema("child")); assertCorrectConfigFiles("inheritdiamond"); } - List<String> files = Arrays.asList("grandparent.sd", "mother.sd", "father.sd", "child.sd"); + List<String> files = List.of("grandparent.sd", "mother.sd", "father.sd", "child.sd"); File outDir = newFolder(tmpDir, "out"); for (int startIdx = 0; startIdx < files.size(); ++startIdx) { var builder = new ApplicationBuilder(new TestProperties()); @@ -159,7 +159,7 @@ public class InheritanceTestCase extends AbstractExportingTestCase { Schema parentSchema = new Schema("parent", MockApplicationPackage.createEmpty()); parentSchema.addDocument(parent); SDField prefixed = parent.addField("prefixed", DataType.STRING); - prefixed.parseIndexingScript("{ index }"); + prefixed.parseIndexingScript(parentSchema.getName(), "{ index }"); prefixed.addIndex(new Index("prefixed", true)); SDDocumentType child = new SDDocumentType("child"); @@ -175,7 +175,7 @@ public class InheritanceTestCase extends AbstractExportingTestCase { @Test void testInheritStructDiamondNew() throws IOException, ParseException { String dir = "src/test/derived/declstruct/"; - List<String> files = Arrays.asList("common.sd", "foo.sd", "bar.sd", "foobar.sd"); + List<String> files = List.of("common.sd", "foo.sd", "bar.sd", "foobar.sd"); var builder = new ApplicationBuilder(new TestProperties()); for (String fileName : files) { builder.addSchemaFile(dir + fileName); diff --git a/config-model/src/test/java/com/yahoo/schema/derived/LiteralBoostTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/LiteralBoostTestCase.java index 97a3f06ac64..505960256b8 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/LiteralBoostTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/LiteralBoostTestCase.java @@ -15,7 +15,7 @@ import com.yahoo.schema.processing.Processing; import com.yahoo.vespa.model.container.search.QueryProfiles; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.List; import java.util.Set; import static com.yahoo.schema.processing.AssertIndexingScript.assertIndexing; @@ -36,7 +36,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase { SDDocumentType document = new SDDocumentType("literalboost"); schema.addDocument(document); SDField field1 = document.addField("a", DataType.STRING); - field1.parseIndexingScript("{ index }"); + field1.parseIndexingScript(schema.getName(), "{ index }"); field1.setLiteralBoost(20); RankProfile other = new RankProfile("other", schema, rankProfileRegistry); rankProfileRegistry.add(other); @@ -50,7 +50,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase { derived.getAttributeFields(); // TODO: assert content // Check il script addition - assertIndexing(Arrays.asList("clear_state | guard { input a | tokenize normalize stem:\"BEST\" | index a; }", + assertIndexing(List.of("clear_state | guard { input a | tokenize normalize stem:\"BEST\" | index a; }", "clear_state | guard { input a | tokenize | index a_literal; }"), schema); @@ -69,7 +69,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase { SDDocumentType document = new SDDocumentType("literalboost"); schema.addDocument(document); SDField field1 = document.addField("a", DataType.STRING); - field1.parseIndexingScript("{ index }"); + field1.parseIndexingScript(schema.getName(), "{ index }"); RankProfile other = new RankProfile("other", schema, rankProfileRegistry); rankProfileRegistry.add(other); other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333)); @@ -78,7 +78,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase { DerivedConfiguration derived = new DerivedConfiguration(schema, rankProfileRegistry); // Check il script addition - assertIndexing(Arrays.asList("clear_state | guard { input a | tokenize normalize stem:\"BEST\" | index a; }", + assertIndexing(List.of("clear_state | guard { input a | tokenize normalize stem:\"BEST\" | index a; }", "clear_state | guard { input a | tokenize | index a_literal; }"), schema); @@ -95,15 +95,15 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase { SDDocumentType document = new SDDocumentType("msb"); schema.addDocument(document); SDField field1 = document.addField("title", DataType.STRING); - field1.parseIndexingScript("{ summary | index }"); + field1.parseIndexingScript(schema.getName(), "{ summary | index }"); field1.setLiteralBoost(20); SDField field2 = document.addField("body", DataType.STRING); - field2.parseIndexingScript("{ summary | index }"); + field2.parseIndexingScript(schema.getName(), "{ summary | index }"); field2.setLiteralBoost(20); schema = ApplicationBuilder.buildFromRawSchema(schema, rankProfileRegistry, new QueryProfileRegistry()); new DerivedConfiguration(schema, rankProfileRegistry); - assertIndexing(Arrays.asList("clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }", + assertIndexing(List.of("clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }", "clear_state | guard { input body | tokenize normalize stem:\"BEST\" | summary body | index body; }", "clear_state | guard { input title | tokenize | index title_literal; }", "clear_state | guard { input body | tokenize | index body_literal; }"), diff --git a/config-model/src/test/java/com/yahoo/schema/derived/SchemaOrdererTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/SchemaOrdererTestCase.java index 593f26eb074..8ae6ada7a63 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/SchemaOrdererTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/SchemaOrdererTestCase.java @@ -12,13 +12,11 @@ import com.yahoo.schema.document.SDField; import com.yahoo.schema.document.TemporarySDField; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import static java.util.Collections.emptyMap; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -63,7 +61,7 @@ public class SchemaOrdererTestCase extends AbstractSchemaTestCase { private static Schema createSchema(String name, Map<String, Schema> schemas) { Schema schema = new Schema(name, MockApplicationPackage.createEmpty()); SDDocumentType document = new SDDocumentType(name); - document.setDocumentReferences(new DocumentReferences(emptyMap())); + document.setDocumentReferences(new DocumentReferences(Map.of())); schema.addDocument(document); schemas.put(schema.getName(), schema); return schema; @@ -74,9 +72,8 @@ public class SchemaOrdererTestCase extends AbstractSchemaTestCase { } private static void assertOrder(List<String> expectedSearchOrder, List<String> inputNames) { - inputNames.sort((a, b) -> a.compareTo(b)); Map<String, Schema> schemas = createSchemas(); - List<Schema> inputSchemas = inputNames.stream() + List<Schema> inputSchemas = inputNames.stream().sorted() .map(schemas::get) .map(Objects::requireNonNull) .toList(); @@ -88,7 +85,6 @@ public class SchemaOrdererTestCase extends AbstractSchemaTestCase { assertEquals(expectedSearchOrder, actualSearchOrder); } - @SuppressWarnings("deprecation") private static void createDocumentReference(Schema from, Schema to, String refFieldName) { SDDocumentType fromDocument = from.getDocument(); SDField refField = new TemporarySDField(fromDocument, refFieldName, NewDocumentReferenceDataType.forDocumentName(to.getName())); @@ -102,44 +98,44 @@ public class SchemaOrdererTestCase extends AbstractSchemaTestCase { @Test void testPerfectOrderingIsKept() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("grandParent", "mother", "father", "daughter", "son", "product", "pc", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("grandParent", "mother", "father", "daughter", "son", "product", "pc", "alone")); } @Test void testOneLevelReordering() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("grandParent", "daughter", "son", "mother", "father", "pc", "product", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("grandParent", "daughter", "son", "mother", "father", "pc", "product", "alone")); } @Test void testMultiLevelReordering() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("daughter", "son", "mother", "father", "grandParent", "pc", "product", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("daughter", "son", "mother", "father", "grandParent", "pc", "product", "alone")); } @Test void testAloneIsKeptInPlaceWithMultiLevelReordering() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("alone", "daughter", "son", "mother", "father", "grandParent", "pc", "product")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("alone", "daughter", "son", "mother", "father", "grandParent", "pc", "product")); } @Test void testPartialMultiLevelReordering() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("daughter", "grandParent", "mother", "son", "father", "product", "pc", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("daughter", "grandParent", "mother", "son", "father", "product", "pc", "alone")); } @Test void testMultilevelReorderingAccrossHierarchies() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), - Arrays.asList("daughter", "pc", "son", "mother", "grandParent", "father", "product", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "son"), + List.of("daughter", "pc", "son", "mother", "grandParent", "father", "product", "alone")); } @Test void referees_are_ordered_before_referrer() { - assertOrder(Arrays.asList("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "accessory-pc", "son"), - Arrays.asList("accessory-pc", "daughter", "pc", "son", "mother", "grandParent", "father", "product", "alone")); + assertOrder(List.of("alone", "grandParent", "mother", "father", "daughter", "product", "pc", "accessory-pc", "son"), + List.of("accessory-pc", "daughter", "pc", "son", "mother", "grandParent", "father", "product", "alone")); } diff --git a/config-model/src/test/java/com/yahoo/schema/derived/SummaryTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/SummaryTestCase.java index a27bc824b45..63510785ca5 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/SummaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/SummaryTestCase.java @@ -172,7 +172,7 @@ public class SummaryTestCase extends AbstractSchemaTestCase { schema.addDocument(document); String fieldName = "location"; SDField field = document.addField(fieldName, PositionDataType.INSTANCE); - field.parseIndexingScript("{ attribute | summary }"); + field.parseIndexingScript(schema.getName(), "{ attribute | summary }"); new Processing().process(schema, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles(), true, false, Set.of()); diff --git a/config-model/src/test/java/com/yahoo/schema/derived/TypeConversionTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/TypeConversionTestCase.java index d2b3acc9a1e..cdfe376416b 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/TypeConversionTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/TypeConversionTestCase.java @@ -32,7 +32,7 @@ public class TypeConversionTestCase extends AbstractSchemaTestCase { SDDocumentType document = new SDDocumentType("test"); schema.addDocument(document); SDField a = new SDField(document, "a", DataType.STRING); - a.parseIndexingScript("{ index }"); + a.parseIndexingScript(schema.getName(), "{ index }"); document.addField(a); new Processing().process(schema, new BaseDeployLogger(), rankProfileRegistry, new QueryProfiles(), diff --git a/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java index 852f567ccfa..a90b4fa8d9f 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java @@ -46,7 +46,7 @@ public class VsmFieldsTestCase { void reference_type_field_is_unsearchable() { Schema schema = createSchema(); SDField field = new TemporarySDField(schema.getDocument(), "ref_field", NewDocumentReferenceDataType.forDocumentName("parent_type")); - field.parseIndexingScript("{ summary }"); + field.parseIndexingScript(schema.getName(), "{ summary }"); schema.getDocument().addField(field); VsmfieldsConfig cfg = vsmfieldsConfig(schema); @@ -59,7 +59,7 @@ public class VsmFieldsTestCase { private void testIndexMatching(Matching matching, VsmfieldsConfig.Fieldspec.Normalize.Enum normalize, String arg1) { Schema schema = createSchema(); SDField field = new TemporarySDField(schema.getDocument(), "f", DataType.STRING); - field.parseIndexingScript("{ index }"); + field.parseIndexingScript(schema.getName(), "{ index }"); field.setMatching(matching); schema.getDocument().addField(field); VsmfieldsConfig cfg = vsmfieldsConfig(schema); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AddDataTypeAndTransformToSummaryOfImportedFieldsTest.java b/config-model/src/test/java/com/yahoo/schema/processing/AddDataTypeAndTransformToSummaryOfImportedFieldsTest.java index f09a95b89a0..3da6f250853 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AddDataTypeAndTransformToSummaryOfImportedFieldsTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AddDataTypeAndTransformToSummaryOfImportedFieldsTest.java @@ -19,7 +19,7 @@ import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; import org.junit.jupiter.api.Test; -import java.util.Collections; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -63,7 +63,7 @@ public class AddDataTypeAndTransformToSummaryOfImportedFieldsTest { SDField targetField = new SDField(doc, "target_field", DataType.INT); DocumentReference documentReference = new DocumentReference(new Field("reference_field"), targetSchema); ImportedField importedField = new ImportedSimpleField(fieldName, documentReference, targetField); - return new ImportedFields(Collections.singletonMap(fieldName, importedField)); + return new ImportedFields(Map.of(fieldName, importedField)); } private static DocumentSummary createDocumentSummary(String fieldName, Schema schema) { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java index c2cc28ea6b3..310706cb0d1 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java @@ -18,7 +18,7 @@ import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; import com.yahoo.vespa.model.container.search.QueryProfiles; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.List; import java.util.OptionalDouble; import java.util.OptionalInt; import java.util.OptionalLong; @@ -105,7 +105,7 @@ public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { @Test void testDerivingFromSimple() throws Exception { - assertIndexing(Arrays.asList("clear_state | guard { input access | attribute access; }", + assertIndexing(List.of("clear_state | guard { input access | attribute access; }", "clear_state | guard { input category | split \";\" | attribute category_arr; }", "clear_state | guard { input category | tokenize | index category; }", "clear_state | guard { input categories_src | lowercase | normalize | tokenize normalize stem:\"BEST\" | index categories; }", @@ -127,8 +127,7 @@ public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { @Test void testIndexRewrite() throws Exception { assertIndexing( - Arrays.asList("clear_state | guard { input title_src | lowercase | normalize | " + - " tokenize | index title; }", + List.of("clear_state | guard { input title_src | lowercase | normalize | tokenize | index title; }", "clear_state | guard { input title_src | summary title_s; }"), ApplicationBuilder.buildFromFile("src/test/examples/indexrewrite.sd")); } @@ -151,7 +150,7 @@ public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { void requireThatMaxTermOccurrencesIsPropagated() { var field = new SDField("test", DataType.STRING); field.getMatching().maxTermOccurrences(10); - field.parseIndexingScript("{ summary | index }"); + field.parseIndexingScript("test", "{ summary | index }"); assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" max-occurrences:10 | summary test | index test; }", field); } @@ -173,14 +172,14 @@ public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { private static SDField createField(String name, DataType type, String script) { SDField field = new SDField(null, name, type); - field.parseIndexingScript(script); + field.parseIndexingScript("test", script); return field; } private static SDField createPredicateField( String name, DataType type, String script, int arity, OptionalLong lower_bound, OptionalLong upper_bound) { SDField field = new SDField(null, name, type); - field.parseIndexingScript(script); + field.parseIndexingScript("test", script); Index index = new Index("foo"); index.setBooleanIndexDefiniton(new BooleanIndexDefinition( OptionalInt.of(arity), lower_bound, upper_bound, OptionalDouble.empty())); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java index 71c91533f54..4053834784f 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java @@ -8,7 +8,7 @@ import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.util.Arrays; +import java.util.List; import static com.yahoo.schema.processing.AssertIndexingScript.assertIndexing; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -154,7 +154,7 @@ public class IndexingValidationTestCase extends AbstractExportingTestCase { @Test void testExtraField() throws IOException, ParseException { assertIndexing( - Arrays.asList("clear_state | guard { input my_index | tokenize normalize stem:\"BEST\" | index my_index | summary my_index }", + List.of("clear_state | guard { input my_index | tokenize normalize stem:\"BEST\" | index my_index | summary my_index }", "clear_state | guard { input my_input | tokenize normalize stem:\"BEST\" | index my_extra | summary my_extra }"), ApplicationBuilder.buildFromFile("src/test/examples/indexing_extra.sd")); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ParentChildSearchModel.java b/config-model/src/test/java/com/yahoo/schema/processing/ParentChildSearchModel.java index af275feffed..129d65584ba 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ParentChildSearchModel.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ParentChildSearchModel.java @@ -36,8 +36,11 @@ public class ParentChildSearchModel { } protected static TemporarySDField createField(SDDocumentType repo, String name, DataType dataType, String indexingScript) { + return createField(repo, repo.getName(), name, dataType, indexingScript); + } + protected static TemporarySDField createField(SDDocumentType repo, String schemaName, String name, DataType dataType, String indexingScript) { TemporarySDField result = new TemporarySDField(repo, name, dataType); - result.parseIndexingScript(indexingScript); + result.parseIndexingScript(schemaName, indexingScript); return result; } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java index 007006bf6d3..87a66046fe5 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java @@ -13,8 +13,8 @@ import com.yahoo.vespa.documentmodel.SummaryTransform; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Iterator; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -27,7 +27,7 @@ public class PositionTestCase { @Test void inherited_position_zcurve_field_is_not_added_to_document_fieldset() throws Exception { - ApplicationBuilder sb = ApplicationBuilder.createFromFiles(Arrays.asList( + ApplicationBuilder sb = ApplicationBuilder.createFromFiles(List.of( "src/test/examples/position_base.sd", "src/test/examples/position_inherited.sd")); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java index 9213f97fd9f..6cbd8faf3b0 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java @@ -19,7 +19,7 @@ import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; import com.yahoo.tensor.Tensor; import org.junit.jupiter.api.Test; -import java.util.Collections; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -94,16 +94,17 @@ public class RankingExpressionWithTransformerTokensTestCase { MockApplicationPackage application = (MockApplicationPackage) MockApplicationPackage.createEmpty(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); QueryProfileRegistry queryProfileRegistry = application.getQueryProfiles(); - String sdContent = "search test {\n" + - " document test {}\n" + - " rank-profile my_profile inherits default {}\n" + - "}"; + String sdContent = """ + search test { + document test {} + rank-profile my_profile inherits default {} + }"""; ApplicationBuilder schemaBuilder = new ApplicationBuilder(application, new MockFileRegistry(), new BaseDeployLogger(), new TestProperties(), rankProfileRegistry, queryProfileRegistry); schemaBuilder.addSchema(sdContent); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); RankProfile rp = rankProfileRegistry.get(schema, "my_profile"); - return new RankProfileTransformContext(rp, queryProfileRegistry, Collections.emptyMap(), null, Collections.emptyMap(), Collections.emptyMap()); + return new RankProfileTransformContext(rp, queryProfileRegistry, Map.of(), null, Map.of(), Map.of()); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java index 0f16330ce11..a602503a71c 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java @@ -21,7 +21,6 @@ import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -102,12 +101,12 @@ public class RankingExpressionsTestCase extends AbstractSchemaTestCase { { AttributeFields attributes = new AttributeFields(schema); - verifyProfile(rankProfileRegistry.get(schema, "base"), Arrays.asList("large_f", "large_m"), - Arrays.asList(new Pair<>("rankingExpression(large_f).expressionName", "base.large_f"), new Pair<>("rankingExpression(large_m).expressionName", "base.large_m")), + verifyProfile(rankProfileRegistry.get(schema, "base"), List.of("large_f", "large_m"), + List.of(new Pair<>("rankingExpression(large_f).expressionName", "base.large_f"), new Pair<>("rankingExpression(large_m).expressionName", "base.large_m")), largeExpressions, queryProfiles, models, attributes, properties); - for (String child : Arrays.asList("child_a", "child_b")) { - verifyProfile(rankProfileRegistry.get(schema, child), Arrays.asList("large_f", "large_m", "large_local_f", "large_local_m"), - Arrays.asList(new Pair<>("rankingExpression(large_f).expressionName", child + ".large_f"), new Pair<>("rankingExpression(large_m).expressionName", child + ".large_m"), + for (String child : List.of("child_a", "child_b")) { + verifyProfile(rankProfileRegistry.get(schema, child), List.of("large_f", "large_m", "large_local_f", "large_local_m"), + List.of(new Pair<>("rankingExpression(large_f).expressionName", child + ".large_f"), new Pair<>("rankingExpression(large_m).expressionName", child + ".large_m"), new Pair<>("rankingExpression(large_local_f).expressionName", child + ".large_local_f"), new Pair<>("rankingExpression(large_local_m).expressionName", child + ".large_local_m"), new Pair<>("vespa.rank.firstphase", "rankingExpression(firstphase)"), new Pair<>("rankingExpression(firstphase).expressionName", child + ".firstphase")), largeExpressions, queryProfiles, models, attributes, properties); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java b/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java index be72d2b12fa..8585a206d77 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java @@ -18,7 +18,7 @@ import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; import org.junit.jupiter.api.Test; -import java.util.Collections; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -65,7 +65,7 @@ public class ValidateFieldTypesTest { SDField targetField = new SDField(targetSchema.getDocument(), "target_field", dataType); DocumentReference documentReference = new DocumentReference(new Field("reference_field"), targetSchema); ImportedField importedField = new ImportedSimpleField(fieldName, documentReference, targetField); - return new ImportedFields(Collections.singletonMap(fieldName, importedField)); + return new ImportedFields(Map.of(fieldName, importedField)); } private static DocumentSummary createDocumentSummary(String fieldName, DataType dataType, Schema schema) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsConsumersTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsConsumersTest.java index 88e1ba7a1a6..94dd0f367a3 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsConsumersTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsConsumersTest.java @@ -8,6 +8,8 @@ import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.admin.monitoring.MetricsConsumer; import org.junit.jupiter.api.Test; +import java.util.List; + import static ai.vespa.metrics.set.DefaultMetrics.defaultMetricSet; import static ai.vespa.metrics.set.DefaultVespaMetrics.defaultVespaMetricSet; import static ai.vespa.metrics.set.NetworkMetrics.networkMetricSet; @@ -21,7 +23,6 @@ import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.c import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.getCustomConsumer; import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.getModel; import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.servicesWithAdminOnly; -import static java.util.Collections.singleton; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -72,7 +73,7 @@ public class MetricsConsumersTest { void vespa_consumer_can_be_amended_via_admin_object() { VespaModel model = getModel(servicesWithAdminOnly(), hosted); var additionalMetric = new Metric("additional-metric"); - model.getAdmin().setAdditionalDefaultMetrics(new MetricSet("amender-metrics", singleton(additionalMetric))); + model.getAdmin().setAdditionalDefaultMetrics(new MetricSet("amender-metrics", List.of(additionalMetric))); ConsumersConfig config = consumersConfigFromModel(model); assertEquals(numMetricsForVespaConsumer + 1, config.consumer(0).metric().size()); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java index b2291099b44..ae1db366c9f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.logging.Level; import static com.yahoo.config.model.test.TestUtil.joinLines; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -67,7 +68,9 @@ public class ComplexFieldsValidatorTestCase { "}", "}")); }); - assertTrue(exception.getMessage().contains(getExpectedMessage("docTopics (docTopics.topics, docTopics.topics.id, docTopics.topics.label)"))); + assertEquals("For schema 'test': Field 'docTopics.topics' of type 'array<topic>' cannot be an attribute." + + " Instead specify the struct fields to be searchable as attribute", + exception.getMessage()); } @Test diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidatorTest.java index 19be886d3e5..c5ef2238f9b 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/PublicApiBundleValidatorTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,7 +41,7 @@ public class PublicApiBundleValidatorTest { assertThat(output, containsString("uses non-public Vespa APIs: [")); // List of packages should be sorted - List<String> packages = Arrays.asList(output.substring(output.indexOf("[") + 1, output.indexOf("]")).split(", ")); + List<String> packages = List.of(output.substring(output.indexOf("[") + 1, output.indexOf("]")).split(", ")); assertThat(packages, hasSize(2)); assertThat(packages, contains("ai.vespa.lib.non_public", "com.yahoo.lib.non_public")); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/StartupCommandChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/StartupCommandChangeValidatorTest.java index e4b9b45489d..829bd6148a6 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/StartupCommandChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/StartupCommandChangeValidatorTest.java @@ -54,7 +54,7 @@ public class StartupCommandChangeValidatorTest { private static MockRoot createRootWithChildren(TreeConfigProducer<?>... children) { MockRoot root = new MockRoot(); - Arrays.asList(children).forEach(root::addChild); + List.of(children).forEach(root::addChild); root.freezeModelTopology(); return root; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/ContentClusterFixture.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/ContentClusterFixture.java index 91ba97817d6..8778f0c26c0 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/ContentClusterFixture.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/ContentClusterFixture.java @@ -9,7 +9,6 @@ import com.yahoo.vespa.model.content.utils.ContentClusterUtils; import com.yahoo.vespa.model.content.utils.SchemaBuilder; import com.yahoo.vespa.model.search.DocumentDatabase; -import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -32,15 +31,15 @@ public abstract class ContentClusterFixture { public ContentClusterFixture(String entireSd) throws Exception { currentCluster = new ContentClusterBuilder().build( - ContentClusterUtils.createMockRoot(Arrays.asList(entireSd))); + ContentClusterUtils.createMockRoot(List.of(entireSd))); nextCluster = new ContentClusterBuilder().build( - ContentClusterUtils.createMockRoot(Arrays.asList(entireSd))); + ContentClusterUtils.createMockRoot(List.of(entireSd))); } private static ContentCluster createCluster(String sdContent) throws Exception { return new ContentClusterBuilder().build( ContentClusterUtils.createMockRoot( - Arrays.asList(new SchemaBuilder().content(sdContent).build()))); + List.of(new SchemaBuilder().content(sdContent).build()))); } protected DocumentDatabase currentDb() { @@ -65,7 +64,7 @@ public abstract class ContentClusterFixture { } public void assertValidation(VespaConfigChangeAction exp) { - assertValidation(Arrays.asList(exp)); + assertValidation(List.of(exp)); } public void assertValidation(List<VespaConfigChangeAction> exp) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidatorTest.java index 684bd619ba1..129649ae1fb 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidatorTest.java @@ -8,7 +8,6 @@ import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeActi import org.junit.jupiter.api.Test; import java.time.Instant; -import java.util.Arrays; import java.util.List; import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction; @@ -50,7 +49,7 @@ public class DocumentDatabaseChangeValidatorTest { "field f3 type string { indexing: summary } " + "field f4 type array<s> { struct-field s1 { indexing: attribute } }"); Instant.now(); - f.assertValidation(Arrays.asList( + f.assertValidation(List.of( newRestartAction(ClusterSpec.Id.from("test"), "Field 'f1' changed: add attribute aspect"), newRestartAction(ClusterSpec.Id.from("test"), diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java index 44743c4fa3e..26a4f532362 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java @@ -14,10 +14,9 @@ import com.yahoo.vespa.model.application.validation.change.VespaRefeedAction; import org.junit.jupiter.api.Test; import java.time.Instant; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -108,7 +107,7 @@ public class DocumentTypeChangeValidatorTest { "field f2 type string { indexing: summary } field f1 type int { indexing: summary }"); Instant.now(); Instant.now(); - f.assertValidation(Arrays.asList(newRefeedAction(ClusterSpec.Id.from("test"), ValidationId.fieldTypeChange, "Field 'f1' changed: data type: 'string' -> 'int'"), + f.assertValidation(List.of(newRefeedAction(ClusterSpec.Id.from("test"), ValidationId.fieldTypeChange, "Field 'f1' changed: data type: 'string' -> 'int'"), newRefeedAction(ClusterSpec.Id.from("test"), ValidationId.fieldTypeChange, "Field 'f2' changed: data type: 'int' -> 'string'"))); } @@ -210,8 +209,8 @@ public class DocumentTypeChangeValidatorTest { new NewDocumentType.Name("mydoc"), headerfields, new FieldSets(Optional.empty()), - Collections.emptySet(), - Collections.emptySet()); + Set.of(), + Set.of()); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/IndexingScriptChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/IndexingScriptChangeValidatorTest.java index 6b58cac3f6c..cd54a20523f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/IndexingScriptChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/IndexingScriptChangeValidatorTest.java @@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.List; public class IndexingScriptChangeValidatorTest { @@ -126,7 +125,7 @@ public class IndexingScriptChangeValidatorTest { void requireThatMultipleChangesRequireReindexing() throws Exception { new Fixture(FIELD + " { indexing: index } " + FIELD_F2 + " { indexing: index }", FIELD + " { indexing: index \n stemming: none } " + FIELD_F2 + " { indexing: index \n normalizing: none }"). - assertValidation(Arrays.asList(expectedReindexingAction("f1", "stemming: 'best' -> 'none'", + assertValidation(List.of(expectedReindexingAction("f1", "stemming: 'best' -> 'none'", "{ input f1 | tokenize normalize stem:\"BEST\" | index f1; }", "{ input f1 | tokenize normalize | index f1; }"), expectedReindexingAction("f2", "normalizing: 'ACCENT' -> 'NONE'", diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java index fac82f3e675..924419daeae 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java @@ -26,7 +26,6 @@ import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.List; import java.util.Set; @@ -876,8 +875,8 @@ public class ContentBuilderTest extends DomBuilderTest { VespaModel m = new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() .withHosts(getHosts()) .withServices(combined) - .withSchemas(Arrays.asList(MockApplicationPackage.MUSIC_SCHEMA, - MockApplicationPackage.BOOK_SCHEMA)) + .withSchemas(List.of(MockApplicationPackage.MUSIC_SCHEMA, + MockApplicationPackage.BOOK_SCHEMA)) .build()) .create(); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV2BuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV2BuilderTest.java index 853cfdd9429..0e616661191 100755 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV2BuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV2BuilderTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -112,7 +111,7 @@ public class DomAdminV2BuilderTest extends DomBuilderTest { @Test void multitenant() { - List<ConfigServerSpec> configServerSpecs = Arrays.asList( + List<ConfigServerSpec> configServerSpecs = List.of( new TestProperties.Spec("test1", 19070, 2181), new TestProperties.Spec("test2", 19070, 2181), new TestProperties.Spec("test3", 19070, 2181)); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSchemaTuningBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSchemaTuningBuilderTest.java index 764e31fe13a..c7525dec6a3 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSchemaTuningBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSchemaTuningBuilderTest.java @@ -8,7 +8,7 @@ import com.yahoo.vespa.model.search.Tuning; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; -import java.util.Arrays; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -22,7 +22,7 @@ public class DomSchemaTuningBuilderTest extends DomBuilderTest { private static Element parseXml(String... xmlLines) { return parse("<tuning>", "<searchnode>", - CollectionUtil.mkString(Arrays.asList(xmlLines), "\n"), + CollectionUtil.mkString(List.of(xmlLines), "\n"), "</searchnode>", "</tuning>"); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSchemaChainsBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSchemaChainsBuilderTest.java index 6b384269910..56f492f3fca 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSchemaChainsBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomSchemaChainsBuilderTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -98,7 +97,7 @@ public class DomSchemaChainsBuilderTest extends DomBuilderTest { @Test void ensureSearchChainsExists() { - for (String id : Arrays.asList("provider:1", "source:1@provider:1", "default")) { + for (String id : List.of("provider:1", "source:1@provider:1", "default")) { assertNotNull(getSearchChain(id), "Missing search chain " + id); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/component/ModelTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/component/ModelTest.java new file mode 100644 index 00000000000..7660ae45c3a --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/component/ModelTest.java @@ -0,0 +1,33 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.component; + +import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.text.XML; +import org.junit.jupiter.api.Test; + +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author hmusum + */ +public class ModelTest { + + @Test + void invalid_url(){ + var xml = """ + <component id="bert-embedder" type="bert-embedder"> + <transformer-model url="models/e5-base-v2.onnx" /> + <tokenizer-vocab path="models/vocab.txt"/> + </component> + """; + + var state = new DeployState.Builder().build(); + var element = XML.getDocument(xml).getDocumentElement(); +var exception = assertThrows(IllegalArgumentException.class, + () -> Model.fromXml(state, element, "transformer-model", Set.of())); +org.junit.jupiter.api.Assertions.assertEquals("Invalid url 'models/e5-base-v2.onnx': url has no 'scheme' component", exception.getMessage()); + } + +} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java index b933d86655e..4e14fbcd671 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java @@ -21,12 +21,9 @@ import com.yahoo.vespa.model.container.configserver.option.CloudConfigOptions; import com.yahoo.vespa.model.container.xml.ConfigServerContainerModelBuilder; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Function; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -46,7 +43,7 @@ public class ConfigserverClusterTest { @Test void zookeeperConfig_only_config_servers_set_hosted() { - TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Collections.emptyList()); + TestOptions testOptions = createTestOptions(List.of("cfg1", "localhost", "cfg3"), List.of()); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 0, 1, 2); @@ -57,7 +54,7 @@ public class ConfigserverClusterTest { @Test void zookeeperConfig_with_config_servers_and_zk_ids_hosted() { - TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(4, 2, 3)); + TestOptions testOptions = createTestOptions(List.of("cfg1", "localhost", "cfg3"), List.of(4, 2, 3)); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 4, 2, 3); @@ -68,7 +65,7 @@ public class ConfigserverClusterTest { @Test void zookeeperConfig_self_hosted() { final boolean hostedVespa = false; - TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(4, 2, 3), hostedVespa); + TestOptions testOptions = createTestOptions(List.of("cfg1", "localhost", "cfg3"), List.of(4, 2, 3), hostedVespa); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 4, 2, 3); @@ -80,7 +77,7 @@ public class ConfigserverClusterTest { @Test void zookeeperConfig_uneven_number_of_config_servers_and_zk_ids() { assertThrows(IllegalArgumentException.class, () -> { - TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Collections.singletonList(1)); + TestOptions testOptions = createTestOptions(List.of("cfg1", "localhost", "cfg3"), List.of(1)); getConfig(ZookeeperServerConfig.class, testOptions); }); } @@ -88,7 +85,7 @@ public class ConfigserverClusterTest { @Test void zookeeperConfig_negative_zk_id() { assertThrows(IllegalArgumentException.class, () -> { - TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(1, 2, -1)); + TestOptions testOptions = createTestOptions(List.of("cfg1", "localhost", "cfg3"), List.of(1, 2, -1)); getConfig(ZookeeperServerConfig.class, testOptions); }); } @@ -137,7 +134,7 @@ public class ConfigserverClusterTest { private static <T> void assertZookeeperServerProperty( List<ZookeeperServerConfig.Server> zkServers, Function<ZookeeperServerConfig.Server, T> propertyMapper, T... expectedProperties) { List<T> actualPropertyValues = zkServers.stream().map(propertyMapper).toList(); - List<T> expectedPropertyValues = Arrays.asList(expectedProperties); + List<T> expectedPropertyValues = List.of(expectedProperties); assertEquals(expectedPropertyValues, actualPropertyValues); } @@ -169,7 +166,7 @@ public class ConfigserverClusterTest { } private static <CONFIGTYPE extends ConfigInstance> CONFIGTYPE getConfig(Class<CONFIGTYPE> clazz) { - return getConfig(clazz, createTestOptions(Collections.emptyList(), Collections.emptyList())); + return getConfig(clazz, createTestOptions(List.of(), List.of())); } private static <CONFIGTYPE extends ConfigInstance> CONFIGTYPE getConfig(Class<CONFIGTYPE> clazz, TestOptions testOptions) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java index 73c4075a182..3345f935e1d 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java @@ -7,7 +7,6 @@ import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.vespa.config.jdisc.http.filter.RuleBasedFilterConfig; import org.junit.jupiter.api.Test; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -29,7 +28,7 @@ public class BlockFeedGlobalEndpointsFilterTest { @Test void does_not_setup_blocking_rule_when_endpoints_empty() { - var filter = new BlockFeedGlobalEndpointsFilter(Collections.emptySet(), true); + var filter = new BlockFeedGlobalEndpointsFilter(Set.of(), true); var config = getConfig(filter); assertEquals(0, config.rule().size()); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java index a066308b426..a832c54021f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java @@ -19,8 +19,8 @@ import org.junit.jupiter.api.BeforeEach; import org.w3c.dom.Element; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.logging.Level; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -88,7 +88,7 @@ public abstract class ContainerModelBuilderTestBase { private static void generateDefaultSearchChains(ContainerCluster<?> cluster) { ContainerSearch search = cluster.getSearch(); if (search != null) - search.initializeSearchChains(Collections.emptyMap()); + search.initializeSearchChains(Map.of()); } protected ComponentsConfig componentsConfig() { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java index 4efffc8310a..fb1e176f707 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java @@ -158,7 +158,7 @@ public class EmbedderTestCase { var model = loadModel(Path.fromString("src/test/cfg/application/embed/"), false); var cluster = model.getContainerClusters().get("container"); var embedderCfg = assertBertEmbedderComponentPresent(cluster); - assertEquals("application-url", modelReference(embedderCfg, "transformerModel").url().orElseThrow().value()); + assertEquals("https://my/url/model.onnx", modelReference(embedderCfg, "transformerModel").url().orElseThrow().value()); assertEquals("files/vocab.txt", modelReference(embedderCfg, "tokenizerVocab").path().orElseThrow().value()); assertEquals("", embedderCfg.transformerTokenTypeIds()); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/JvmOptionsTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/JvmOptionsTest.java index 10adca12f91..46097da434e 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/JvmOptionsTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/JvmOptionsTest.java @@ -19,13 +19,12 @@ import org.w3c.dom.Element; import org.xml.sax.SAXException; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.logging.Level; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -218,18 +217,17 @@ public class JvmOptionsTest extends ContainerModelBuilderTestBase { } private String verifyLogMessage(TestLogger logger, String... invalidOptions) { - List<String> strings = Arrays.asList(invalidOptions.clone()); + List<String> strings = List.of(invalidOptions); // Verify that nothing is logged if there are no invalid options if (strings.isEmpty()) { - assertEquals(0, logger.msgs.size(), logger.msgs.size() > 0 ? logger.msgs.get(0).getSecond() : ""); + assertEquals(0, logger.msgs.size(), !logger.msgs.isEmpty() ? logger.msgs.get(0).getSecond() : ""); return null; } - assertTrue(logger.msgs.size() > 0, "Expected 1 or more log messages for invalid JM options, got none"); + assertFalse(logger.msgs.isEmpty(), "Expected 1 or more log messages for invalid JM options, got none"); Pair<Level, String> firstOption = logger.msgs.get(0); assertEquals(Level.WARNING, firstOption.getFirst()); - Collections.sort(strings); return firstOption.getSecond(); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java index 1ba5bebea7e..96e1f2edf76 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java @@ -22,7 +22,6 @@ import com.yahoo.vespa.config.content.AllClustersBucketSpacesConfig; import com.yahoo.vespa.config.content.DistributionConfig; import com.yahoo.vespa.config.content.FleetcontrollerConfig; import com.yahoo.vespa.config.content.StorDistributionConfig; -import com.yahoo.vespa.config.content.StorFilestorConfig; import com.yahoo.vespa.config.content.core.StorDistributormanagerConfig; import com.yahoo.vespa.config.content.core.StorServerConfig; import com.yahoo.vespa.config.search.DispatchConfig; @@ -43,8 +42,6 @@ import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; @@ -72,7 +69,7 @@ public class ContentClusterTest extends ContentBaseTest { @Test void testHierarchicRedundancy() { - ContentCluster cc = parse("" + + ContentCluster cc = parse( "<content version=\"1.0\" id=\"storage\">\n" + " <documents/>" + " <engine>" + @@ -947,8 +944,8 @@ public class ContentClusterTest extends ContentBaseTest { .properties(props); MockRoot root = flavor.isPresent() ? ContentClusterUtils.createMockRoot(new SingleNodeProvisioner(flavor.get()), - Collections.emptyList(), deployStateBuilder) : - ContentClusterUtils.createMockRoot(Collections.emptyList(), deployStateBuilder); + List.of(), deployStateBuilder) : + ContentClusterUtils.createMockRoot(List.of(), deployStateBuilder); ContentCluster cluster = ContentClusterUtils.createCluster(clusterXml, root); root.freezeModelTopology(); cluster.validate(); @@ -1104,8 +1101,8 @@ public class ContentClusterTest extends ContentBaseTest { assertEquals(2, config.cluster().size()); - assertClusterHasBucketSpaceMappings(config, "foo_c", Arrays.asList("bunnies", "hares"), Collections.emptyList()); - assertClusterHasBucketSpaceMappings(config, "bar_c", Collections.emptyList(), Collections.singletonList("rabbits")); + assertClusterHasBucketSpaceMappings(config, "foo_c", List.of("bunnies", "hares"), List.of()); + assertClusterHasBucketSpaceMappings(config, "bar_c", List.of(), List.of("rabbits")); } @Test diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSchemaClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSchemaClusterTest.java index 55ec9f4efe2..8c08b9054a4 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSchemaClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSchemaClusterTest.java @@ -12,7 +12,6 @@ import com.yahoo.vespa.model.content.utils.DocType; import com.yahoo.vespa.model.content.utils.SchemaBuilder; import org.junit.jupiter.api.Test; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static com.yahoo.config.model.test.TestUtil.joinLines; @@ -60,12 +59,12 @@ public class ContentSchemaClusterTest { private static ContentClusterBuilder createClusterBuilderWithGlobalType() { return new ContentClusterBuilder() - .docTypes(Arrays.asList(DocType.indexGlobal("global"), DocType.index("regular"))); + .docTypes(List.of(DocType.indexGlobal("global"), DocType.index("regular"))); } private static ContentClusterBuilder createClusterBuilderWithOnlyDefaultTypes() { return new ContentClusterBuilder() - .docTypes(Arrays.asList(DocType.index("marve"), DocType.index("fleksnes"))); + .docTypes(List.of(DocType.index("marve"), DocType.index("fleksnes"))); } private static ProtonConfig getProtonConfig(ContentCluster cluster) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/GlobalDistributionValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/GlobalDistributionValidatorTest.java index 6066a27cff5..e671a47b36c 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/GlobalDistributionValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/GlobalDistributionValidatorTest.java @@ -11,8 +11,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import static java.util.Collections.emptyMap; -import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toSet; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -25,7 +23,7 @@ public class GlobalDistributionValidatorTest { @Test void validation_succeeds_on_no_documents() { new GlobalDistributionValidator() - .validate(emptyMap(), emptySet()); + .validate(Map.of(), Set.of()); } @Test diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/IndexingAndDocprocRoutingTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/IndexingAndDocprocRoutingTest.java index b41d92bd63f..901c307723e 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/IndexingAndDocprocRoutingTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/IndexingAndDocprocRoutingTest.java @@ -21,7 +21,6 @@ import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import org.junit.jupiter.api.Test; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -489,7 +488,7 @@ public class IndexingAndDocprocRoutingTest extends ContentBaseTest { private DocprocClusterSpec(String name, DocprocChainSpec ... chains) { this.name = name; - this.chains.addAll(Arrays.asList(chains)); + this.chains.addAll(List.of(chains)); } } @@ -500,7 +499,7 @@ public class IndexingAndDocprocRoutingTest extends ContentBaseTest { private DocprocChainSpec(String name, String ... inherits) { this.name = name; - this.inherits.addAll(Arrays.asList(inherits)); + this.inherits.addAll(List.of(inherits)); } } @@ -542,7 +541,7 @@ public class IndexingAndDocprocRoutingTest extends ContentBaseTest { } public static List<String> generateSchemas(String ... sdNames) { - return generateSchemas(Arrays.asList(sdNames)); + return generateSchemas(List.of(sdNames)); } public static List<String> generateSchemas(List<String> sdNames) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java index a6fa0334668..2fb9a67a9ae 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java @@ -4,8 +4,6 @@ package com.yahoo.vespa.model.content; import com.yahoo.documentmodel.NewDocumentType; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -40,13 +38,13 @@ public class ReservedDocumentTypeNameValidatorTest { @Test void exception_is_not_thrown_on_unreserved_name() { ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); - validator.validate(asDocTypeMapping(Collections.singletonList("foo"))); + validator.validate(asDocTypeMapping(List.of("foo"))); } @Test void validation_is_case_insensitive() { ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); - Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(Arrays.asList("NULL", "True", "anD"))); + Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(List.of("NULL", "True", "anD"))); try { validator.validate(orderedDocTypes); fail(); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/TopologicalDocumentTypeSorterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/TopologicalDocumentTypeSorterTest.java index c5a645bd863..06794a3c1f3 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/TopologicalDocumentTypeSorterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/TopologicalDocumentTypeSorterTest.java @@ -5,8 +5,6 @@ import com.yahoo.documentmodel.NewDocumentType; import org.junit.jupiter.api.Test; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -20,24 +18,24 @@ public class TopologicalDocumentTypeSorterTest { @Test void require_that_types_without_references_are_returned_in_input_order() { - assertOrder(Arrays.asList("a"), new DocumentTypesBuilder().add("a")); - assertOrder(Arrays.asList("a", "c", "b"), + assertOrder(List.of("a"), new DocumentTypesBuilder().add("a")); + assertOrder(List.of("a", "c", "b"), new DocumentTypesBuilder().add("a").add("c").add("b")); } @Test void require_that_types_with_references_are_sorted_in_topological_order() { - assertOrder(Arrays.asList("b", "a"), new DocumentTypesBuilder() - .add("a", Arrays.asList("b")) + assertOrder(List.of("b", "a"), new DocumentTypesBuilder() + .add("a", List.of("b")) .add("b")); - assertOrder(Arrays.asList("c", "b", "a"), new DocumentTypesBuilder() - .add("a", Arrays.asList("b", "c")) - .add("b", Arrays.asList("c")) + assertOrder(List.of("c", "b", "a"), new DocumentTypesBuilder() + .add("a", List.of("b", "c")) + .add("b", List.of("c")) .add("c")); - assertOrder(Arrays.asList("b", "a", "d", "c"), new DocumentTypesBuilder() - .add("a", Arrays.asList("b")) + assertOrder(List.of("b", "a", "d", "c"), new DocumentTypesBuilder() + .add("a", List.of("b")) .add("b") - .add("c", Arrays.asList("d")) + .add("c", List.of("d")) .add("d")); } @@ -52,7 +50,7 @@ public class TopologicalDocumentTypeSorterTest { private final List<NewDocumentType> result = new ArrayList<>(); public DocumentTypesBuilder add(String docTypeName) { - return add(docTypeName, Collections.emptyList()); + return add(docTypeName, List.of()); } public DocumentTypesBuilder add(String docTypeName, List<String> docTypeNameReferences) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java index 3bd7b7a4c1a..1043ddd2c0b 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java @@ -6,9 +6,7 @@ import com.yahoo.text.XML; import com.yahoo.vespa.model.builder.xml.dom.ModelElement; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -35,7 +33,7 @@ public class GlobalDistributionBuilderTest { " <document type=\"" + GLOBAL_2.getName() + "\" global=\"true\"/>" + "</documents>"; - Set<NewDocumentType> expectedResult = new HashSet<>(Arrays.asList(GLOBAL_1, GLOBAL_2)); + Set<NewDocumentType> expectedResult = Set.of(GLOBAL_1, GLOBAL_2); Set<NewDocumentType> actualResult = builder.build(new ModelElement(XML.getDocument(documentsElement).getDocumentElement())); assertEquals(expectedResult, actualResult); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java index 61ce5172ceb..277b07023e6 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java @@ -7,7 +7,6 @@ import com.yahoo.vespa.model.content.cluster.ContentCluster; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import static com.yahoo.config.model.test.TestUtil.joinLines; @@ -21,7 +20,7 @@ public class ContentClusterBuilder { private String name = "mycluster"; private int redundancy = 1; private int searchableCopies = 1; - private List<DocType> docTypes = Arrays.asList(DocType.index("test")); + private List<DocType> docTypes = List.of(DocType.index("test")); private String groupXml = getSimpleGroupXml(); private Optional<String> dispatchXml = Optional.empty(); private Optional<Double> protonDiskLimit = Optional.empty(); @@ -54,8 +53,8 @@ public class ContentClusterBuilder { } public ContentClusterBuilder docTypes(String ... docTypes) { - this.docTypes = Arrays.asList(docTypes).stream(). - map(type -> DocType.index(type)). + this.docTypes = Arrays.stream(docTypes). + map(DocType::index). toList(); return this; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java index a8c67ebf0a3..360ad19b710 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java @@ -16,7 +16,6 @@ import com.yahoo.vespa.model.admin.monitoring.builder.Metrics; import com.yahoo.vespa.model.content.cluster.ContentCluster; import org.w3c.dom.Document; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -67,7 +66,7 @@ public class ContentClusterUtils { ConfigModelContext context = ConfigModelContext.create(applicationType, root.getDeployState(), null,null, root, null); - return new ContentCluster.Builder(admin).build(Collections.emptyList(), context, doc.getDocumentElement()); + return new ContentCluster.Builder(admin).build(List.of(), context, doc.getDocumentElement()); } public static ContentCluster createCluster(String clusterXml, List<String> schemas, DeployState.Builder deployStateBuilder) throws Exception { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java index 3ffb33a47c8..ce05fa27e2e 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.content.utils; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -46,7 +45,7 @@ public class DocType { } public static String listToXml(DocType... docTypes) { - return listToXml(Arrays.asList(docTypes)); + return listToXml(List.of(docTypes)); } public static String listToXml(List<DocType> docTypes) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/SchemaBuilder.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/SchemaBuilder.java index 304f3dc426f..55ad9149a17 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/SchemaBuilder.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/SchemaBuilder.java @@ -38,8 +38,7 @@ public class SchemaBuilder { } public static List<String> createSchemas(String ... docTypes) { - return Arrays.asList(docTypes) - .stream() + return Arrays.stream(docTypes) .map(type -> new SchemaBuilder().name(type).build()) .toList(); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaClusterTest.java index f9999a30869..7809a97f85c 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaClusterTest.java @@ -41,8 +41,8 @@ public class SchemaClusterTest { SDDocumentType sdt1 = new SDDocumentType("s1"); Schema schema1 = new Schema("s1", MockApplicationPackage.createEmpty()); SDField f1 = new SDField(sdt1, "f1", DataType.STRING); - f1.addAttribute(new Attribute("f1", DataType.STRING)); - f1.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f1")))); + f1.addAttribute(new Attribute(schema1.getName(), f1.getName(), "f1", DataType.STRING)); + f1.setIndexingScript("s1", new ScriptExpression(new StatementExpression(new AttributeExpression("f1")))); sdt1.addField(f1); schema1.addDocument(sdt1); @@ -50,8 +50,8 @@ public class SchemaClusterTest { SDDocumentType sdt2 = new SDDocumentType("s2"); Schema schema2 = new Schema("s2", MockApplicationPackage.createEmpty()); SDField f2 = new SDField(sdt2, "f2", DataType.STRING); - f2.addAttribute(new Attribute("f2", DataType.STRING)); - f2.setIndexingScript(new ScriptExpression(new StatementExpression(new AttributeExpression("f2")))); + f2.addAttribute(new Attribute(schema2.getName(), f2.getName(), "f2", DataType.STRING)); + f2.setIndexingScript("s2", new ScriptExpression(new StatementExpression(new AttributeExpression("f2")))); sdt2.addField(f2); schema2.addDocument(sdt2); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java index 8502bfa92f4..672bba83e87 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java @@ -102,7 +102,7 @@ public class SchemaInfoTestCase { var schemaInfoTester = new SchemaInfoTester(); var schema = schemaInfoTester.createSchema("test"); var field = (SDField)schema.getDocument().addField(new SDField("f1", DataType.STRING)); - var attribute = field.addAttribute(new Attribute("f1Attribute", field.getDataType())); + var attribute = field.addAttribute(new Attribute(schema.getName(), field.getName(), "f1Attribute", field.getDataType())); attribute.getAliases().add("a1"); attribute.getAliases().add("a2"); assertEquals(""" diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaTester.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaTester.java index 7efacd6b5ad..e17db551798 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaTester.java @@ -12,7 +12,6 @@ import com.yahoo.vespa.model.search.SearchCluster; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -181,7 +180,7 @@ public class SchemaTester { } public static List<String> generateSchemas(String schemaContent, String rankProfile, String ... schemaNames) { - return generateSchemas(schemaContent, rankProfile, Arrays.asList(schemaNames)); + return generateSchemas(schemaContent, rankProfile, List.of(schemaNames)); } public static List<String> generateSchemas(String schemaContent, String rankProfile, List<String> schemaNames) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/test/ApiConfigModel.java b/config-model/src/test/java/com/yahoo/vespa/model/test/ApiConfigModel.java index 41003f03c0d..b9be56d8d69 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/test/ApiConfigModel.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/test/ApiConfigModel.java @@ -10,7 +10,6 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -50,7 +49,7 @@ public class ApiConfigModel extends ConfigModel { @Override public List<ConfigModelId> handlesElements() { - return Arrays.asList(ConfigModelId.fromName("api")); + return List.of(ConfigModelId.fromName("api")); } @Override diff --git a/config-model/src/test/java/com/yahoo/vespa/model/test/SimpleConfigModel.java b/config-model/src/test/java/com/yahoo/vespa/model/test/SimpleConfigModel.java index 61bd3d885f5..d9be865bc7d 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/test/SimpleConfigModel.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/test/SimpleConfigModel.java @@ -10,7 +10,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -20,8 +19,8 @@ import java.util.List; */ public class SimpleConfigModel extends ConfigModel implements TestApi { - private List<SimpleService> simpleServices = new ArrayList<>(); - private List<ParentService> parentServices = new ArrayList<>(); + private final List<SimpleService> simpleServices = new ArrayList<>(); + private final List<ParentService> parentServices = new ArrayList<>(); public SimpleConfigModel(ConfigModelContext modelContext) { super(modelContext); @@ -43,7 +42,7 @@ public class SimpleConfigModel extends ConfigModel implements TestApi { @Override public List<ConfigModelId> handlesElements() { - return Arrays.asList(ConfigModelId.fromName("simple")); + return List.of(ConfigModelId.fromName("simple")); } @Override @@ -54,11 +53,10 @@ public class SimpleConfigModel extends ConfigModel implements TestApi { NodeList childNodes = spec.getChildNodes(); for (int i=0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); - if (! (child instanceof Element)) { + if (! (child instanceof Element e)) { // skip #text and #comment nodes continue; } - Element e = (Element)child; String service = e.getTagName(); if (service.equals("simpleservice")) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/test/utils/ApplicationPackageUtils.java b/config-model/src/test/java/com/yahoo/vespa/model/test/utils/ApplicationPackageUtils.java index b9bc34688b7..ce373e558ef 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/test/utils/ApplicationPackageUtils.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/test/utils/ApplicationPackageUtils.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.model.test.utils; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -50,7 +49,7 @@ public class ApplicationPackageUtils { } public static List<String> generateSchemas(String ... sdNames) { - return generateSchemas(Arrays.asList(sdNames)); + return generateSchemas(List.of(sdNames)); } public static List<String> generateSchemas(List<String> sdNames) { |