diff --git a/.idea/gradle.xml b/.idea/gradle.xml index b7f40adfd8..9ea5465e55 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -24,6 +24,7 @@ diff --git a/actions/gradle-test/action.yml b/actions/gradle-test/action.yml index 492d377c55..f245bd68a0 100644 --- a/actions/gradle-test/action.yml +++ b/actions/gradle-test/action.yml @@ -31,4 +31,4 @@ runs: - name: Copy Test Reports shell: bash if: always() - run: mkdir -p test-reports && for d in fdb-java-annotations fdb-extensions fdb-record-layer-core fdb-record-layer-icu fdb-record-layer-spatial fdb-record-layer-lucene fdb-record-layer-jmh examples fdb-relational-api fdb-relational-core fdb-relational-cli fdb-relational-grpc fdb-relational-jdbc fdb-relational-server yaml-tests; do ln -s ../$d/.out/reports test-reports/$d; done + run: mkdir -p test-reports && for d in fdb-java-annotations fdb-extensions fdb-test-utils fdb-record-layer-core fdb-record-layer-icu fdb-record-layer-spatial fdb-record-layer-lucene fdb-record-layer-jmh examples fdb-relational-api fdb-relational-core fdb-relational-cli fdb-relational-grpc fdb-relational-jdbc fdb-relational-server yaml-tests; do ln -s ../$d/.out/reports test-reports/$d; done diff --git a/fdb-extensions/fdb-extensions.gradle b/fdb-extensions/fdb-extensions.gradle index 6c77f13db9..137e13eb96 100644 --- a/fdb-extensions/fdb-extensions.gradle +++ b/fdb-extensions/fdb-extensions.gradle @@ -30,6 +30,7 @@ dependencies { implementation(libs.slf4j.api) compileOnly(libs.jsr305) + testImplementation project(':fdb-test-utils') testImplementation(libs.bundles.test.impl) testRuntimeOnly(libs.bundles.test.runtime) testCompileOnly(libs.bundles.test.compileOnly) diff --git a/fdb-record-layer-core/fdb-record-layer-core.gradle b/fdb-record-layer-core/fdb-record-layer-core.gradle index 463f2d581d..ece46d39fa 100644 --- a/fdb-record-layer-core/fdb-record-layer-core.gradle +++ b/fdb-record-layer-core/fdb-record-layer-core.gradle @@ -35,7 +35,7 @@ dependencies { compileOnly(libs.autoService) annotationProcessor(libs.autoService) - testImplementation testFixtures(project(':fdb-extensions')) + testImplementation project(':fdb-test-utils') testImplementation(libs.bundles.test.impl) testRuntimeOnly(libs.bundles.test.runtime) testCompileOnly(libs.bundles.test.compileOnly) diff --git a/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/test/FDBDatabaseExtension.java b/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/test/FDBDatabaseExtension.java index 189e5a5649..e99fc5c6fd 100644 --- a/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/test/FDBDatabaseExtension.java +++ b/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/test/FDBDatabaseExtension.java @@ -88,7 +88,7 @@ private static FDB getInitedFDB() { synchronized (FDBDatabaseExtension.class) { if (fdb == null) { // Note: in some ways, this mirrors the TestDatabaseExtension abstraction in the - // fdb-extensions project. We could re-use this here, except that if we did, we'd + // fdb-test-utils project. We could re-use this here, except that if we did, we'd // never test the FDBDatabaseFactory's methods for initializing FDB FDBDatabaseFactory baseFactory = FDBDatabaseFactory.instance(); if (TRACE) { diff --git a/fdb-record-layer-icu/fdb-record-layer-icu.gradle b/fdb-record-layer-icu/fdb-record-layer-icu.gradle index 62e5b9d84e..f7e89def0d 100644 --- a/fdb-record-layer-icu/fdb-record-layer-icu.gradle +++ b/fdb-record-layer-icu/fdb-record-layer-icu.gradle @@ -28,7 +28,7 @@ dependencies { compileOnly(libs.autoService) annotationProcessor(libs.autoService) - testImplementation testFixtures(project(':fdb-extensions')) + testImplementation project(':fdb-test-utils') testImplementation project(path: coreProject, configuration: 'tests') testImplementation(libs.bundles.test.impl) testRuntimeOnly(libs.bundles.test.runtime) diff --git a/fdb-record-layer-lucene/fdb-record-layer-lucene.gradle b/fdb-record-layer-lucene/fdb-record-layer-lucene.gradle index c31ec46c4d..62844de28a 100644 --- a/fdb-record-layer-lucene/fdb-record-layer-lucene.gradle +++ b/fdb-record-layer-lucene/fdb-record-layer-lucene.gradle @@ -33,7 +33,7 @@ dependencies { compileOnly(libs.autoService) annotationProcessor(libs.autoService) - testImplementation testFixtures(project(':fdb-extensions')) + testImplementation project(':fdb-test-utils') testImplementation project(path: coreProject, configuration: 'tests') testImplementation(libs.bundles.test.impl) testImplementation(libs.lucene.testFramework) diff --git a/fdb-record-layer-spatial/fdb-record-layer-spatial.gradle b/fdb-record-layer-spatial/fdb-record-layer-spatial.gradle index 99e81042d5..3c3acabacd 100644 --- a/fdb-record-layer-spatial/fdb-record-layer-spatial.gradle +++ b/fdb-record-layer-spatial/fdb-record-layer-spatial.gradle @@ -36,7 +36,7 @@ dependencies { testImplementation(libs.bundles.test.impl) testRuntimeOnly(libs.bundles.test.runtime) testCompileOnly(libs.bundles.test.compileOnly) - testImplementation testFixtures(project(':fdb-extensions')) + testImplementation project(':fdb-test-utils') testImplementation project(path: coreProject, configuration: 'tests') } diff --git a/fdb-test-utils/fdb-test-utils.gradle b/fdb-test-utils/fdb-test-utils.gradle new file mode 100644 index 0000000000..693fde20a9 --- /dev/null +++ b/fdb-test-utils/fdb-test-utils.gradle @@ -0,0 +1,45 @@ +/* + * fdb-test-utils.gradle + * + * 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. + */ + +apply from: rootProject.file('gradle/publishing.gradle') + +dependencies { + api(libs.bundles.test.impl) + api(libs.slf4j.api) + compileOnly(libs.bundles.test.compileOnly) + compileOnly(libs.jsr305) + annotationProcessor(libs.autoService) + implementation(libs.fdbJava) + + testImplementation(libs.bundles.test.impl) + testRuntimeOnly(libs.bundles.test.runtime) + testCompileOnly(libs.bundles.test.compileOnly) + testAnnotationProcessor(libs.autoService) +} + +publishing { + publications { + library(MavenPublication) { + pom { + description = 'Test utilities for FoundationDB Record Layer projects.' + } + } + } +} diff --git a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestClassSubspaceExtension.java b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestClassSubspaceExtension.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestClassSubspaceExtension.java rename to fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestClassSubspaceExtension.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestDatabaseExtension.java b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestDatabaseExtension.java similarity index 96% rename from fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestDatabaseExtension.java rename to fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestDatabaseExtension.java index e64b12e890..ebd1d494db 100644 --- a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestDatabaseExtension.java +++ b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestDatabaseExtension.java @@ -37,10 +37,10 @@ * create an instance of this as static member variable and then register the class as an extension so * that the callbacks associated with this extension are executed. Like so: * - *
{@code
- *     @RegisterExtension
- *     static final TestDatabaseExtension dbExtension = new TestDatabaseExtension();
- * }
+ *
+ * @RegisterExtension
+ * static final TestDatabaseExtension dbExtension = new TestDatabaseExtension();
+ * 
* *

* The user can then call {@link #getDatabase() dbExtension.getDatabase()} to get an actual FDB handle. diff --git a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestExecutors.java b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestExecutors.java similarity index 96% rename from fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestExecutors.java rename to fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestExecutors.java index 91e455e8d3..866ff646a1 100644 --- a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestExecutors.java +++ b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestExecutors.java @@ -29,7 +29,13 @@ /** * Executors to use during testing. */ -public class TestExecutors { +public final class TestExecutors { + @Nonnull + private static final Executor DEFAULT_THREAD_POOL = newThreadPool("fdb-unit-test"); + + private TestExecutors() { + } + /** * Thread factory for creating threads used by test thread pools. */ @@ -51,9 +57,6 @@ public Thread newThread(final Runnable r) { } } - @Nonnull - private static final Executor DEFAULT_THREAD_POOL = newThreadPool("fdb-unit-test"); - public static Executor newThreadPool(@Nonnull String namePrefix) { return Executors.newCachedThreadPool(new TestThreadFactory(namePrefix)); } diff --git a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestMdcExtension.java b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestMdcExtension.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestMdcExtension.java rename to fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestMdcExtension.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestSubspaceExtension.java b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestSubspaceExtension.java similarity index 88% rename from fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestSubspaceExtension.java rename to fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestSubspaceExtension.java index 5165ee748d..f938d0ee89 100644 --- a/fdb-extensions/src/testFixtures/java/com/apple/foundationdb/test/TestSubspaceExtension.java +++ b/fdb-test-utils/src/main/java/com/apple/foundationdb/test/TestSubspaceExtension.java @@ -23,7 +23,6 @@ import com.apple.foundationdb.Range; import com.apple.foundationdb.directory.DirectoryLayer; import com.apple.foundationdb.subspace.Subspace; -import com.apple.foundationdb.tuple.ByteArrayUtil2; import com.apple.foundationdb.tuple.Tuple; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -40,12 +39,12 @@ * will be cleared out during the {@link AfterEachCallback} for this extension. To use, create a member variable * of the test and register the extension: * - *

{@code
- *     @RegisterExtension
- *     static final TestDatabaseExtension dbExtension = new TestDatabaseExtension();
- *     @RegisterExtension
- *     TestSubspaceExtension subspaceExtension = new TestSubspaceExtension(dbExtension);
- * }
+ *
+ * @RegisterExtension
+ * static final TestDatabaseExtension dbExtension = new TestDatabaseExtension();
+ * @RegisterExtension
+ * TestSubspaceExtension subspaceExtension = new TestSubspaceExtension(dbExtension);
+ * 
* *

* Within the test, call {@link #getSubspace()} to get the test's allocated exception. As long as all usage @@ -72,7 +71,7 @@ public Subspace getSubspace() { .thenApply(directorySubspace -> directorySubspace.subspace(Tuple.from(UUID.randomUUID()))) ).join(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("created test subspace subspace=\"{}\"", ByteArrayUtil2.loggable(subspace.getKey())); + LOGGER.debug("created test subspace subspace=\"{}\"", subspace); } } return subspace; @@ -82,7 +81,7 @@ public Subspace getSubspace() { public void afterEach(final ExtensionContext extensionContext) { if (subspace != null) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("clearing test subspace subspace=\"{}\"", ByteArrayUtil2.loggable(subspace.getKey())); + LOGGER.debug("clearing test subspace subspace=\"{}\"", subspace); } dbExtension.getDatabase().run(tx -> { tx.clear(Range.startsWith(subspace.pack())); diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/BooleanArgumentsProvider.java b/fdb-test-utils/src/main/java/com/apple/test/BooleanArgumentsProvider.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/BooleanArgumentsProvider.java rename to fdb-test-utils/src/main/java/com/apple/test/BooleanArgumentsProvider.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/BooleanSource.java b/fdb-test-utils/src/main/java/com/apple/test/BooleanSource.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/BooleanSource.java rename to fdb-test-utils/src/main/java/com/apple/test/BooleanSource.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/ParameterizedTestUtils.java b/fdb-test-utils/src/main/java/com/apple/test/ParameterizedTestUtils.java similarity index 97% rename from fdb-extensions/src/testFixtures/java/com/apple/test/ParameterizedTestUtils.java rename to fdb-test-utils/src/main/java/com/apple/test/ParameterizedTestUtils.java index 391974fcc0..a27e31137e 100644 --- a/fdb-extensions/src/testFixtures/java/com/apple/test/ParameterizedTestUtils.java +++ b/fdb-test-utils/src/main/java/com/apple/test/ParameterizedTestUtils.java @@ -30,7 +30,10 @@ /** * Helper utility class for interacting with {@link org.junit.jupiter.params.ParameterizedTest}s. */ -public class ParameterizedTestUtils { +public final class ParameterizedTestUtils { + + private ParameterizedTestUtils() { + } /** * Provides a stream of boolean, named arguments. diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/RandomSeedProvider.java b/fdb-test-utils/src/main/java/com/apple/test/RandomSeedProvider.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/RandomSeedProvider.java rename to fdb-test-utils/src/main/java/com/apple/test/RandomSeedProvider.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/RandomSeedSource.java b/fdb-test-utils/src/main/java/com/apple/test/RandomSeedSource.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/RandomSeedSource.java rename to fdb-test-utils/src/main/java/com/apple/test/RandomSeedSource.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/RandomizedTestUtils.java b/fdb-test-utils/src/main/java/com/apple/test/RandomizedTestUtils.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/RandomizedTestUtils.java rename to fdb-test-utils/src/main/java/com/apple/test/RandomizedTestUtils.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/SuperSlow.java b/fdb-test-utils/src/main/java/com/apple/test/SuperSlow.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/SuperSlow.java rename to fdb-test-utils/src/main/java/com/apple/test/SuperSlow.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/Tags.java b/fdb-test-utils/src/main/java/com/apple/test/Tags.java similarity index 94% rename from fdb-extensions/src/testFixtures/java/com/apple/test/Tags.java rename to fdb-test-utils/src/main/java/com/apple/test/Tags.java index e602e83745..22246779d8 100644 --- a/fdb-extensions/src/testFixtures/java/com/apple/test/Tags.java +++ b/fdb-test-utils/src/main/java/com/apple/test/Tags.java @@ -23,7 +23,8 @@ /** * Annotation {@link org.junit.jupiter.api.Tag}s for Record Layer tests. */ -public class Tags { +@SuppressWarnings("PMD.FieldNamingConventions") +public final class Tags { /** * Tests that require FoundationDB to be available. */ @@ -46,4 +47,8 @@ public class Tags { * Tests that wipe the entire FDB cluster during their run. */ public static final String WipesFDB = "WipesFDB"; + + private Tags() { + } + } diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/TestConfigurationUtils.java b/fdb-test-utils/src/main/java/com/apple/test/TestConfigurationUtils.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/TestConfigurationUtils.java rename to fdb-test-utils/src/main/java/com/apple/test/TestConfigurationUtils.java diff --git a/fdb-extensions/src/testFixtures/java/com/apple/test/ParameterizedTestUtilsTest.java b/fdb-test-utils/src/test/java/com/apple/test/ParameterizedTestUtilsTest.java similarity index 100% rename from fdb-extensions/src/testFixtures/java/com/apple/test/ParameterizedTestUtilsTest.java rename to fdb-test-utils/src/test/java/com/apple/test/ParameterizedTestUtilsTest.java diff --git a/settings.gradle b/settings.gradle index a86cd8a425..b6f1d24f3b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ rootProject.name='fdb-record-layer' include 'fdb-java-annotations' include 'fdb-extensions' +include 'fdb-test-utils' include 'fdb-record-layer-core' include 'fdb-record-layer-core-shaded' include 'fdb-record-layer-icu'