From 9c0da14e5d2dec8805bd1d402931a9e5127c1c31 Mon Sep 17 00:00:00 2001 From: Scott Dugas Date: Fri, 14 Mar 2025 15:39:07 -0400 Subject: [PATCH 1/3] Remove yaml-tests dependency on core test code By removing this dependency we make it easier for others to use the yaml testing framework. --- .../yamltests/command/QueryCommand.java | 36 ++----------------- .../yamltests/server/SemanticVersionTest.java | 2 +- yaml-tests/yaml-tests.gradle | 1 - 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryCommand.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryCommand.java index 1a474aa6cf..12208926df 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryCommand.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryCommand.java @@ -20,14 +20,10 @@ package com.apple.foundationdb.relational.yamltests.command; -import com.apple.foundationdb.record.TestHelpers; import com.apple.foundationdb.record.query.plan.cascades.debug.Debugger; -import com.apple.foundationdb.record.query.plan.debug.DebuggerWithSymbolTables; import com.apple.foundationdb.relational.api.Continuation; import com.apple.foundationdb.relational.api.exceptions.RelationalException; -import com.apple.foundationdb.relational.recordlayer.util.ExceptionUtil; import com.apple.foundationdb.relational.util.Assert; -import com.apple.foundationdb.relational.util.Environment; import com.apple.foundationdb.relational.yamltests.CustomYamlConstructor; import com.apple.foundationdb.relational.yamltests.Matchers; import com.apple.foundationdb.relational.yamltests.YamlConnection; @@ -151,7 +147,6 @@ void executeInternal(@Nonnull final YamlConnection connection) throws SQLExcepti private void executeInternal(@Nonnull final YamlConnection connection, boolean checkCache, @Nonnull QueryExecutor executor) throws SQLException, RelationalException { - enableCascadesDebugger(); boolean shouldExecute = true; boolean queryIsRunning = false; Continuation continuation = null; @@ -179,13 +174,13 @@ private void executeInternal(@Nonnull final YamlConnection connection, boolean c // can result in the explain plan being put into the plan cache, so running without the debugger // can pollute cache and thus interfere with the explain's results Integer finalMaxRows = maxRows; - runWithDebugger(() -> executor.execute(connection, null, queryConfig, checkCache, finalMaxRows)); + executor.execute(connection, null, queryConfig, checkCache, finalMaxRows); } else if (QueryConfig.QUERY_CONFIG_EXPLAIN.equals(queryConfig.getConfigName()) || QueryConfig.QUERY_CONFIG_EXPLAIN_CONTAINS.equals(queryConfig.getConfigName())) { Assert.that(!queryIsRunning, "Explain test should not be intermingled with query result tests"); // ignore debugger configuration, always set the debugger for explain, so we can always get consistent // results Integer finalMaxRows1 = maxRows; - runWithDebugger(() -> executor.execute(connection, null, queryConfig, checkCache, finalMaxRows1)); + executor.execute(connection, null, queryConfig, checkCache, finalMaxRows1); } else if (QueryConfig.QUERY_CONFIG_NO_OP.equals(queryConfig.getConfigName())) { // Do nothing for noop execution. continue; @@ -233,31 +228,4 @@ static void reportTestFailure(@Nonnull String message, @Nullable Throwable throw Assertions.fail(message, throwable); } } - - private static void runWithDebugger(@Nonnull TestHelpers.DangerousRunnable r) throws SQLException { - final var savedDebugger = Debugger.getDebugger(); - try { - Debugger.setDebugger(DebuggerWithSymbolTables.withoutSanityChecks()); - Debugger.setup(); - r.run(); - } catch (Exception t) { - throw ExceptionUtil.toRelationalException(t).toSqlException(); - } finally { - Debugger.setDebugger(savedDebugger); - } - } - - /** - * Enables internal Cascades debugger which, among other things, sets plan identifiers in a stable fashion making - * it easier to view plans and reproduce planning steps. - * - * @implNote - * This is copied from fdb-relational-core:test subproject to avoid having a dependency just for getting access to it. - */ - private static void enableCascadesDebugger() { - if (Debugger.getDebugger() == null && Environment.isDebug()) { - Debugger.setDebugger(DebuggerWithSymbolTables.withoutSanityChecks()); - } - Debugger.setup(); - } } diff --git a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersionTest.java b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersionTest.java index 9c6e20638b..ed5a67fbe7 100644 --- a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersionTest.java +++ b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersionTest.java @@ -38,9 +38,9 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static com.apple.foundationdb.record.TestHelpers.assertThrows; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class SemanticVersionTest { diff --git a/yaml-tests/yaml-tests.gradle b/yaml-tests/yaml-tests.gradle index 4486d88d8f..15c5184f7f 100644 --- a/yaml-tests/yaml-tests.gradle +++ b/yaml-tests/yaml-tests.gradle @@ -53,7 +53,6 @@ configurations { def coreProject = ":${ext.coreProjectName}" dependencies { implementation project(coreProject) - implementation project(path: coreProject, configuration: 'tests') implementation project(":fdb-relational-api") implementation project(":fdb-relational-core") implementation project(":fdb-relational-jdbc") From e498e80f6f0aa002c811fc8fc9147935f36a3f35 Mon Sep 17 00:00:00 2001 From: Scott Dugas Date: Fri, 14 Mar 2025 16:14:10 -0400 Subject: [PATCH 2/3] Move @YamlTest annotation to the test part of the code, rather than main If someone wants to use YamlTestExtension, they'll have to add it with @ExtendWith --- .../yamltests/ExcludeYamlTestConfig.java | 2 +- .../yamltests/MaintainYamlTestConfig.java | 2 +- .../relational/yamltests/YamlRunner.java | 34 +++---- .../relational/yamltests/YamlTest.java | 66 -------------- .../yamltests/YamlTestConfigFilters.java | 2 +- .../yamltests/YamlTestExtension.java | 37 ++++---- .../src/test/java/InitialVersionTest.java | 3 +- .../src/test/java/SupportedVersionTest.java | 3 +- .../src/test/java/YamlIntegrationTests.java | 89 ++++++++++--------- .../relational/yamltests/YamlTest.java | 38 ++++++++ 10 files changed, 124 insertions(+), 152 deletions(-) delete mode 100644 yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTest.java create mode 100644 yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/ExcludeYamlTestConfig.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/ExcludeYamlTestConfig.java index 32074aebbf..d23a896d69 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/ExcludeYamlTestConfig.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/ExcludeYamlTestConfig.java @@ -26,7 +26,7 @@ import java.lang.annotation.RetentionPolicy; /** - * Mark specific {@link YamlTestConfig} as disabled for the current test in an {@link YamlTest} test class. + * Mark specific {@link YamlTestConfig} as disabled for the current test in an {@link YamlTestExtension} test class. *

* Any config in {@link #value()} will be skipped for the annotated test. *

diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/MaintainYamlTestConfig.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/MaintainYamlTestConfig.java index ad79ee6fa7..9a1be0c44b 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/MaintainYamlTestConfig.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/MaintainYamlTestConfig.java @@ -27,7 +27,7 @@ /** * Mark specific {@link YamlTestConfig} that are designated test maintenance helper configs as enabled for the current - * test in an {@link YamlTest} test class. + * test in an {@link YamlTestExtension} test class. *

* Any config in {@link #value()} will be included for the annotated test. Any config not included will be skipped. *

diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlRunner.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlRunner.java index af5ad3f1d3..635373bdb8 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlRunner.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlRunner.java @@ -56,18 +56,18 @@ public final class YamlRunner { static final String TEST_NIGHTLY_REPETITION = "tests.yaml.iterations"; @Nonnull - private final String resourcePath; - + private final YamlConnectionFactory factory; @Nonnull - private final YamlExecutionContext executionContext; + private final YamlExecutionContext.ContextOptions additionalOptions; - public YamlRunner(@Nonnull String resourcePath, @Nonnull YamlConnectionFactory factory, - @Nonnull final YamlExecutionContext.ContextOptions additionalOptions) throws RelationalException { - this.resourcePath = resourcePath; - this.executionContext = new YamlExecutionContext(resourcePath, factory, additionalOptions); + public YamlRunner(@Nonnull YamlConnectionFactory factory, + @Nonnull final YamlExecutionContext.ContextOptions additionalOptions) { + this.factory = factory; + this.additionalOptions = additionalOptions; } - public void run() throws Exception { + public void runYamsql(@Nonnull String resourcePath) throws Exception { + YamlExecutionContext executionContext = new YamlExecutionContext(resourcePath, factory, additionalOptions); try { LoaderOptions loaderOptions = new LoaderOptions(); loaderOptions.setAllowDuplicateKeys(true); @@ -92,16 +92,16 @@ public void run() throws Exception { block.execute(); } - evaluateTestBlockResults(testBlocks); - replaceTestFileIfRequired(); - replaceMetricsFileIfRequired(); + evaluateTestBlockResults(testBlocks, resourcePath); + replaceTestFileIfRequired(executionContext); + replaceMetricsFileIfRequired(executionContext); } catch (RelationalException | IOException e) { logger.error("‼️ running test file '{}' was not successful", resourcePath, e); throw e; } } - private void evaluateTestBlockResults(List testBlocks) { + private void evaluateTestBlockResults(List testBlocks, final String resourcePath) { logger.info(""); logger.info(""); logger.info("--------------------------------------------------------------------------------------------------------------"); @@ -140,24 +140,24 @@ private static InputStream getInputStream(@Nonnull final String resourcePath) th return inputStream; } - private void replaceTestFileIfRequired() { + private void replaceTestFileIfRequired(final YamlExecutionContext executionContext) { if (executionContext.getEditedFileStream() == null || !executionContext.isDirty()) { return; } try { - try (var writer = new PrintWriter(new FileWriter(Path.of(System.getProperty("user.dir")).resolve(Path.of("src", "test", "resources", resourcePath)).toAbsolutePath().toString(), StandardCharsets.UTF_8))) { + try (var writer = new PrintWriter(new FileWriter(Path.of(System.getProperty("user.dir")).resolve(Path.of("src", "test", "resources", executionContext.resourcePath)).toAbsolutePath().toString(), StandardCharsets.UTF_8))) { for (var line : executionContext.getEditedFileStream()) { writer.println(line); } } - logger.info("🟢 Source file {} replaced.", resourcePath); + logger.info("🟢 Source file {} replaced.", executionContext.resourcePath); } catch (IOException e) { - logger.error("⚠️ Source file {} could not be replaced with corrected file.", resourcePath); + logger.error("⚠️ Source file {} could not be replaced with corrected file.", executionContext.resourcePath); Assertions.fail(e); } } - private void replaceMetricsFileIfRequired() throws RelationalException { + private void replaceMetricsFileIfRequired(final YamlExecutionContext executionContext) throws RelationalException { if (!executionContext.isDirtyMetrics()) { return; } diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTest.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTest.java deleted file mode 100644 index fe186d0c90..0000000000 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * YamlTest.java - * - * This source file is part of the FoundationDB open source project - * - * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.apple.foundationdb.relational.yamltests; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * An annotation for test classes that run {@code .yamsql} files. - *

- * Test classes annotated with this should have all their tests annotated with - * {@link org.junit.jupiter.api.TestTemplate}, instead of {@link org.junit.jupiter.api.Test}. - * Note: This doesn't work with {@link org.junit.jupiter.params.ParameterizedTest}. - * Each {@link org.junit.jupiter.api.TestTemplate} will be run with each of the varying - * {@link com.apple.foundationdb.relational.yamltests.configs.YamlTestConfig}, and passed in a parameter: - * {@link YamlTest.Runner} to run the {@code .yamsql} file. - *

- *

- * If a specific test cannot be run with a specific config due to a bug, it can be ignored by adding the - * annotation {@link ExcludeYamlTestConfig}. Ideally, these are short lived, primarily to support adding a config, - * and then fixing some tests that may fail with that config. - *

- */ -@Retention(RetentionPolicy.RUNTIME) -@ExtendWith(YamlTestExtension.class) -// Right now these are the only tests that have the capability to run in mixed mode, but if we create other tests, this -// should be moved to a shared static location -@Tag("MixedMode") -public @interface YamlTest { - /** - * Simple interface to run a {@code .yamsql} file, based on the config. - *

- * This is primarily a nested class because I couldn't figure out a better way to avoid a naming conflict with - * the existing {@link YamlRunner}. - *

- */ - interface Runner { - /** - * Run a {@code .yamsql} test. - * @param fileName the filename of the {@code .yamsql} resource - * @throws Exception if the test has issues - */ - void runYamsql(String fileName) throws Exception; - } -} diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestConfigFilters.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestConfigFilters.java index 0bdf4db75b..2fe1c72ec3 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestConfigFilters.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestConfigFilters.java @@ -25,7 +25,7 @@ import com.apple.foundationdb.relational.yamltests.configs.YamlTestConfig; /** - * An enum of reasons to disable a {@link YamlTest} test for a given {@link YamlTestConfig}. + * An enum of reasons to disable a {@link YamlTestExtension} test for a given {@link YamlTestConfig}. *

* Note: Part of the reason this exists as an enum, is that fields on annotations can only be certain types, and * enum seemed like the cleanest. diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java index b715341509..a40cba40af 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java @@ -35,7 +35,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.Extension; @@ -57,7 +56,20 @@ import java.util.stream.Stream; /** - * Extension that backs {@link YamlTest}. + * An extension for test classes that run {@code .yamsql} files. + *

+ * Test classes extended with this should have all their tests annotated with + * {@link org.junit.jupiter.api.TestTemplate}, instead of {@link org.junit.jupiter.api.Test}. + * Note: This doesn't work with {@link org.junit.jupiter.params.ParameterizedTest}. + * Each {@link org.junit.jupiter.api.TestTemplate} will be run with each of the varying + * {@link com.apple.foundationdb.relational.yamltests.configs.YamlTestConfig}, and passed in a parameter: + * {@link YamlRunner} to run the {@code .yamsql} file. + *

+ *

+ * If a specific test cannot be run with a specific config due to a bug, it can be ignored by adding the + * annotation {@link ExcludeYamlTestConfig}. Ideally, these are short lived, primarily to support adding a config, + * and then fixing some tests that may fail with that config. + *

*/ public class YamlTestExtension implements TestTemplateInvocationContextProvider, BeforeAllCallback, AfterAllCallback { private static final Logger logger = LogManager.getLogger(YamlTestExtension.class); @@ -233,7 +245,7 @@ public List getAdditionalExtensions() { } /** - * Parameter resolver for the class when injecting the {@link YamlTest.Runner}. + * Parameter resolver for the class when injecting the {@link YamlRunner}. */ private static final class ClassParameterResolver implements ParameterResolver { @@ -254,27 +266,12 @@ public ClassParameterResolver(@Nonnull final YamlTestConfig config, @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return parameterContext.getParameter().getType().equals(YamlTest.Runner.class); + return parameterContext.getParameter().getType().equals(YamlRunner.class); } @Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return new YamlTest.Runner() { - @Override - public void runYamsql(final String fileName) throws Exception { - if (filters != null) { - Assumptions.assumeTrue(filters.filter(config), excludedReason); - } - var yamlRunner = new YamlRunner(fileName, config.createConnectionFactory(), - config.getRunnerOptions()); - try { - yamlRunner.run(); - } catch (Exception e) { - logger.error("‼️ running test file '{}' was not successful", fileName, e); - throw e; - } - } - }; + return new YamlRunner(config.createConnectionFactory(), config.getRunnerOptions()); } } } diff --git a/yaml-tests/src/test/java/InitialVersionTest.java b/yaml-tests/src/test/java/InitialVersionTest.java index af247c76aa..176d031529 100644 --- a/yaml-tests/src/test/java/InitialVersionTest.java +++ b/yaml-tests/src/test/java/InitialVersionTest.java @@ -65,7 +65,8 @@ private void doRunCurrentVersion(String testName) throws Exception { } private void doRun(String testName, YamlConnectionFactory connectionFactory) throws Exception { - new YamlRunner("initial-version/" + testName + ".yamsql", connectionFactory, YamlExecutionContext.ContextOptions.EMPTY_OPTIONS).run(); + new YamlRunner(connectionFactory, YamlExecutionContext.ContextOptions.EMPTY_OPTIONS) + .runYamsql("initial-version/" + testName + ".yamsql"); } YamlConnectionFactory createConnectionFactory() { diff --git a/yaml-tests/src/test/java/SupportedVersionTest.java b/yaml-tests/src/test/java/SupportedVersionTest.java index 154ebd0def..00f45d743e 100644 --- a/yaml-tests/src/test/java/SupportedVersionTest.java +++ b/yaml-tests/src/test/java/SupportedVersionTest.java @@ -58,7 +58,8 @@ static void afterAll() throws Exception { } private void doRun(String fileName) throws Exception { - new YamlRunner(fileName, createConnectionFactory(), YamlExecutionContext.ContextOptions.EMPTY_OPTIONS).run(); + new YamlRunner(createConnectionFactory(), YamlExecutionContext.ContextOptions.EMPTY_OPTIONS) + .runYamsql(fileName); } YamlConnectionFactory createConnectionFactory() { diff --git a/yaml-tests/src/test/java/YamlIntegrationTests.java b/yaml-tests/src/test/java/YamlIntegrationTests.java index 83859adcf4..821102511b 100644 --- a/yaml-tests/src/test/java/YamlIntegrationTests.java +++ b/yaml-tests/src/test/java/YamlIntegrationTests.java @@ -19,6 +19,7 @@ */ import com.apple.foundationdb.relational.yamltests.MaintainYamlTestConfig; +import com.apple.foundationdb.relational.yamltests.YamlRunner; import com.apple.foundationdb.relational.yamltests.YamlTest; import com.apple.foundationdb.relational.yamltests.YamlTestConfigFilters; import org.junit.jupiter.api.Disabled; @@ -33,224 +34,224 @@ @YamlTest public class YamlIntegrationTests { @TestTemplate - public void showcasingTests(YamlTest.Runner runner) throws Exception { + public void showcasingTests(YamlRunner runner) throws Exception { runner.runYamsql("showcasing-tests.yamsql"); } @TestTemplate - public void groupByTests(YamlTest.Runner runner) throws Exception { + public void groupByTests(YamlRunner runner) throws Exception { runner.runYamsql("groupby-tests.yamsql"); } @TestTemplate - public void standardTests(YamlTest.Runner runner) throws Exception { + public void standardTests(YamlRunner runner) throws Exception { runner.runYamsql("standard-tests.yamsql"); } @TestTemplate - public void standardTestsWithProto(YamlTest.Runner runner) throws Exception { + public void standardTestsWithProto(YamlRunner runner) throws Exception { runner.runYamsql("standard-tests-proto.yamsql"); } @TestTemplate - public void fieldIndexTestsProto(YamlTest.Runner runner) throws Exception { + public void fieldIndexTestsProto(YamlRunner runner) throws Exception { runner.runYamsql("field-index-tests-proto.yamsql"); } @TestTemplate - public void standardTestsWithMetaData(YamlTest.Runner runner) throws Exception { + public void standardTestsWithMetaData(YamlRunner runner) throws Exception { runner.runYamsql("standard-tests-metadata.yamsql"); } @TestTemplate - public void nullOperator(YamlTest.Runner runner) throws Exception { + public void nullOperator(YamlRunner runner) throws Exception { runner.runYamsql("null-operator-tests.yamsql"); } @TestTemplate @Disabled // TODO ([Wave 1] Relational returns deprecated fields for SELECT *) - public void deprecatedFieldsTestsWithProto(YamlTest.Runner runner) throws Exception { + public void deprecatedFieldsTestsWithProto(YamlRunner runner) throws Exception { runner.runYamsql("deprecated-fields-tests-proto.yamsql"); } @TestTemplate - public void versionsTests(YamlTest.Runner runner) throws Exception { + public void versionsTests(YamlRunner runner) throws Exception { runner.runYamsql("versions-tests.yamsql"); } @TestTemplate - public void scenarioTests(YamlTest.Runner runner) throws Exception { + public void scenarioTests(YamlRunner runner) throws Exception { runner.runYamsql("scenario-tests.yamsql"); } @TestTemplate - public void joinTests(YamlTest.Runner runner) throws Exception { + public void joinTests(YamlRunner runner) throws Exception { runner.runYamsql("join-tests.yamsql"); } @TestTemplate - public void subqueryTests(YamlTest.Runner runner) throws Exception { + public void subqueryTests(YamlRunner runner) throws Exception { runner.runYamsql("subquery-tests.yamsql"); } @TestTemplate - public void selectAStar(YamlTest.Runner runner) throws Exception { + public void selectAStar(YamlRunner runner) throws Exception { runner.runYamsql("select-a-star.yamsql"); } @TestTemplate - public void insertsUpdatesDeletes(YamlTest.Runner runner) throws Exception { + public void insertsUpdatesDeletes(YamlRunner runner) throws Exception { runner.runYamsql("inserts-updates-deletes.yamsql"); } @TestTemplate @Disabled("TODO (Cannot insert into table after dropping and recreating schema template when using EmbeddedJDBCDriver)") - public void createDropCreateTemplate(YamlTest.Runner runner) throws Exception { + public void createDropCreateTemplate(YamlRunner runner) throws Exception { runner.runYamsql("create-drop-create-template.yamsql"); } @TestTemplate - public void aggregateIndexTests(YamlTest.Runner runner) throws Exception { + public void aggregateIndexTests(YamlRunner runner) throws Exception { runner.runYamsql("aggregate-index-tests.yamsql"); } @TestTemplate - public void aggregateEmptyTable(YamlTest.Runner runner) throws Exception { + public void aggregateEmptyTable(YamlRunner runner) throws Exception { runner.runYamsql("aggregate-empty-table.yamsql"); } @TestTemplate - public void aggregateIndexTestsCount(YamlTest.Runner runner) throws Exception { + public void aggregateIndexTestsCount(YamlRunner runner) throws Exception { runner.runYamsql("aggregate-index-tests-count.yamsql"); } @TestTemplate - public void aggregateIndexTestsCountEmpty(YamlTest.Runner runner) throws Exception { + public void aggregateIndexTestsCountEmpty(YamlRunner runner) throws Exception { runner.runYamsql("aggregate-index-tests-count-empty.yamsql"); } @TestTemplate - public void maxRows(YamlTest.Runner runner) throws Exception { + public void maxRows(YamlRunner runner) throws Exception { runner.runYamsql("maxRows.yamsql"); } @TestTemplate - public void nested(YamlTest.Runner runner) throws Exception { + public void nested(YamlRunner runner) throws Exception { runner.runYamsql("nested-tests.yamsql"); } @TestTemplate - public void orderBy(YamlTest.Runner runner) throws Exception { + public void orderBy(YamlRunner runner) throws Exception { runner.runYamsql("orderby.yamsql"); } @TestTemplate - public void primaryKey(YamlTest.Runner runner) throws Exception { + public void primaryKey(YamlRunner runner) throws Exception { runner.runYamsql("primary-key-tests.yamsql"); } @TestTemplate - public void sparseIndex(YamlTest.Runner runner) throws Exception { + public void sparseIndex(YamlRunner runner) throws Exception { runner.runYamsql("sparse-index-tests.yamsql"); } @TestTemplate - public void disabledIndexWithProto(YamlTest.Runner runner) throws Exception { + public void disabledIndexWithProto(YamlRunner runner) throws Exception { runner.runYamsql("disabled-index-tests-proto.yamsql"); } @TestTemplate - public void inPredicate(YamlTest.Runner runner) throws Exception { + public void inPredicate(YamlRunner runner) throws Exception { runner.runYamsql("in-predicate.yamsql"); } @TestTemplate - void booleanTypes(YamlTest.Runner runner) throws Exception { + void booleanTypes(YamlRunner runner) throws Exception { runner.runYamsql("boolean.yamsql"); } @TestTemplate - void bytes(YamlTest.Runner runner) throws Exception { + void bytes(YamlRunner runner) throws Exception { runner.runYamsql("bytes.yamsql"); } @TestTemplate - void catalog(YamlTest.Runner runner) throws Exception { + void catalog(YamlRunner runner) throws Exception { runner.runYamsql("catalog.yamsql"); } @TestTemplate - public void caseWhen(YamlTest.Runner runner) throws Exception { + public void caseWhen(YamlRunner runner) throws Exception { runner.runYamsql("case-when.yamsql"); } @TestTemplate - public void updateDeleteReturning(YamlTest.Runner runner) throws Exception { + public void updateDeleteReturning(YamlRunner runner) throws Exception { runner.runYamsql("update-delete-returning.yamsql"); } @TestTemplate - void like(YamlTest.Runner runner) throws Exception { + void like(YamlRunner runner) throws Exception { runner.runYamsql("like.yamsql"); } @TestTemplate - void functions(YamlTest.Runner runner) throws Exception { + void functions(YamlRunner runner) throws Exception { runner.runYamsql("functions.yamsql"); } @TestTemplate - void createDrop(YamlTest.Runner runner) throws Exception { + void createDrop(YamlRunner runner) throws Exception { runner.runYamsql("create-drop.yamsql"); } @TestTemplate - void arrays(YamlTest.Runner runner) throws Exception { + void arrays(YamlRunner runner) throws Exception { runner.runYamsql("arrays.yamsql"); } @TestTemplate - public void insertEnum(YamlTest.Runner runner) throws Exception { + public void insertEnum(YamlRunner runner) throws Exception { runner.runYamsql("insert-enum.yamsql"); } @TestTemplate - public void prepared(YamlTest.Runner runner) throws Exception { + public void prepared(YamlRunner runner) throws Exception { runner.runYamsql("prepared.yamsql"); } @TestTemplate - public void indexedFunctions(YamlTest.Runner runner) throws Exception { + public void indexedFunctions(YamlRunner runner) throws Exception { runner.runYamsql("indexed-functions.yamsql"); } @TestTemplate - public void union(YamlTest.Runner runner) throws Exception { + public void union(YamlRunner runner) throws Exception { runner.runYamsql("union.yamsql"); } @TestTemplate - public void unionEmptyTables(YamlTest.Runner runner) throws Exception { + public void unionEmptyTables(YamlRunner runner) throws Exception { runner.runYamsql("union-empty-tables.yamsql"); } @TestTemplate - public void cte(YamlTest.Runner runner) throws Exception { + public void cte(YamlRunner runner) throws Exception { runner.runYamsql("cte.yamsql"); } @TestTemplate - public void bitmap(YamlTest.Runner runner) throws Exception { + public void bitmap(YamlRunner runner) throws Exception { runner.runYamsql("bitmap-aggregate-index.yamsql"); } @TestTemplate - public void recursiveCte(YamlTest.Runner runner) throws Exception { + public void recursiveCte(YamlRunner runner) throws Exception { runner.runYamsql("recursive-cte.yamsql"); } @TestTemplate - public void enumTest(YamlTest.Runner runner) throws Exception { + public void enumTest(YamlRunner runner) throws Exception { runner.runYamsql("enum.yamsql"); } } diff --git a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java new file mode 100644 index 0000000000..453b1c9c27 --- /dev/null +++ b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java @@ -0,0 +1,38 @@ +/* + * YamlTest.java + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.apple.foundationdb.relational.yamltests; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * An annotation for adding the {@link YamlTestExtension} and running in Mixed Mode. + */ +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(YamlTestExtension.class) +// Right now these are the only tests that have the capability to run in mixed mode, but if we create other tests, this +// should be moved to a shared static location +@Tag("MixedMode") +public @interface YamlTest { +} From bbf42c08de90e9bbc97c50ba4c4c5da6c3c6d958 Mon Sep 17 00:00:00 2001 From: Scott Dugas Date: Fri, 14 Mar 2025 16:27:46 -0400 Subject: [PATCH 3/3] Re-Enable cascades debugger in yaml-tests This re-enables the debugger in our tests, but allows yaml-tests to be used elsewhere without bringing in a dependency on the debugger. --- .../relational/yamltests/YamlTest.java | 2 +- .../YamlTestWithDebuggingExtension.java | 38 +++++++++++++++++++ yaml-tests/yaml-tests.gradle | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTestWithDebuggingExtension.java diff --git a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java index 453b1c9c27..ddb4fb902b 100644 --- a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java +++ b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTest.java @@ -30,7 +30,7 @@ * An annotation for adding the {@link YamlTestExtension} and running in Mixed Mode. */ @Retention(RetentionPolicy.RUNTIME) -@ExtendWith(YamlTestExtension.class) +@ExtendWith(YamlTestWithDebuggingExtension.class) // Right now these are the only tests that have the capability to run in mixed mode, but if we create other tests, this // should be moved to a shared static location @Tag("MixedMode") diff --git a/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTestWithDebuggingExtension.java b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTestWithDebuggingExtension.java new file mode 100644 index 0000000000..eb8ac274ce --- /dev/null +++ b/yaml-tests/src/test/java/com/apple/foundationdb/relational/yamltests/YamlTestWithDebuggingExtension.java @@ -0,0 +1,38 @@ +/* + * YamlTestWithDebuggingExtension.java + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.apple.foundationdb.relational.yamltests; + +import com.apple.foundationdb.record.query.plan.cascades.debug.Debugger; +import com.apple.foundationdb.record.query.plan.debug.DebuggerWithSymbolTables; +import com.apple.foundationdb.relational.util.Environment; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class YamlTestWithDebuggingExtension extends YamlTestExtension { + + @Override + public void beforeAll(final ExtensionContext context) throws Exception { + if (Debugger.getDebugger() == null && Environment.isDebug()) { + Debugger.setDebugger(DebuggerWithSymbolTables.withoutSanityChecks()); + } + Debugger.setup(); + super.beforeAll(context); + } +} diff --git a/yaml-tests/yaml-tests.gradle b/yaml-tests/yaml-tests.gradle index 15c5184f7f..a427548ffb 100644 --- a/yaml-tests/yaml-tests.gradle +++ b/yaml-tests/yaml-tests.gradle @@ -67,6 +67,7 @@ dependencies { implementation(libs.snakeyaml) testImplementation(libs.bundles.test.impl) + testImplementation project(path: coreProject, configuration: 'tests') // to get the cascades debugger testRuntimeOnly(libs.bundles.test.runtime) testCompileOnly(libs.bundles.test.compileOnly) testImplementation project(":fdb-relational-server")