diff options
author | Geir Storli <geirst@yahooinc.com> | 2023-04-27 17:15:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 17:15:00 +0200 |
commit | ce388205e5323a2c94c4ea20b4c208487e3ad983 (patch) | |
tree | 2bba1e1b7cd168c37d738726cebafeac4b7fa0b1 | |
parent | 7e3adf7046f96823efbf555dddf341c3b7c4ea11 (diff) | |
parent | 103fc08d70b2612a7d8af3f3866f27f3cbedefbc (diff) |
Merge pull request #26896 from vespa-engine/geirst/schema-to-derived-config-exporter
Add util to export derived config files from a schema file.
-rw-r--r-- | config-model/src/test/java/com/yahoo/schema/derived/SchemaToDerivedConfigExporter.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/derived/SchemaToDerivedConfigExporter.java b/config-model/src/test/java/com/yahoo/schema/derived/SchemaToDerivedConfigExporter.java new file mode 100644 index 00000000000..ec3381033dc --- /dev/null +++ b/config-model/src/test/java/com/yahoo/schema/derived/SchemaToDerivedConfigExporter.java @@ -0,0 +1,52 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.schema.derived; + +import com.yahoo.config.model.application.provider.MockFileRegistry; +import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.config.model.deploy.TestProperties; +import com.yahoo.document.config.DocumenttypesConfig; +import com.yahoo.schema.ApplicationBuilder; +import com.yahoo.schema.parser.ParseException; +import com.yahoo.vespa.configmodel.producers.DocumentTypes; + +import java.io.IOException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +/** + * Utility class for deriving backend configs for a given schema and exporting them to a set of files. + * + * This can be used by e.g C++ unit tests to generate configs that are checked in as part of the test. + * Place the schema file in a directory $HOME/mydir and run the following in $HOME/git/vespa: + * mvn test -Dtest=SchemaToDerivedConfigExporter -Dschema.exporter.path=$HOME/mydir -pl config-model + * + * Note that the directory path must be absolute. + * + * @author geirst + */ +public class SchemaToDerivedConfigExporter { + + private void exportConfig(String dirPath, DerivedConfiguration config, ApplicationBuilder builder) throws IOException { + config.export(dirPath); + DerivedConfiguration.exportDocuments(new DocumentTypes().produce(builder.getModel(), new DocumenttypesConfig.Builder()), dirPath); + } + + @Test + public void deriveAndExport() throws IOException, ParseException { + var dirPath = System.getProperty("schema.exporter.path"); + // The test is marked as skipped if this is not true. + assumeTrue(dirPath != null); + + var props = new TestProperties(); + var logger = new TestableDeployLogger(); + var builder = ApplicationBuilder.createFromDirectory(dirPath, new MockFileRegistry(), logger, props); + var derived = new DerivedConfiguration(builder.getSchema(null), + new DeployState.Builder().properties(props) + .deployLogger(logger) + .rankProfileRegistry(builder.getRankProfileRegistry()) + .queryProfiles(builder.getQueryProfileRegistry()) + .build()); + exportConfig(dirPath, derived, builder); + } +} |