diff --git a/grpc/grpc-operation-ledger-jpa/build.gradle b/grpc/grpc-operation-ledger-jpa/build.gradle index 05d90ae..e4a8fc3 100644 --- a/grpc/grpc-operation-ledger-jpa/build.gradle +++ b/grpc/grpc-operation-ledger-jpa/build.gradle @@ -17,9 +17,11 @@ configurations { } // One definition of a versioned migration file and of Flyway's order for both builds (re-review -// README 12, r6-b; r9). This build cannot depend on persistence-jpa's testkit, so the one file the -// ledger lanes need from it — VersionedMigrationFiles, JDK only — is copied from there into this -// lane's sources at build time instead of being kept here as a second copy that could drift. +// README 12, r6-b; r9), and one concurrent index check (round 7, RR7-03-01). This build cannot +// depend on persistence-jpa's testkit, so the files the ledger lanes need from it, all JDK only — +// VersionedMigrationFiles, and ConcurrentIndexMigrationInspector with the MigrationResource it +// takes — are copied from there into this lane's sources at build time instead of being kept here +// as second copies that could drift. // Rejected: that testkit directory as a source root of this lane (Spotless refuses a target outside // this project's directory, and the include filter would cover this lane's own sources too), a // dependency on the main build (it would pull the whole main build into this one), and a test that @@ -27,6 +29,8 @@ configurations { def sharedMigrationFileSources = tasks.register('sharedMigrationFileSources', Sync) { from(file('../../adapter/outbound/persistence-jpa/src/testFixtures/java')) { include 'dev/caskeleton/adapter/outbound/persistence/testkit/migration/VersionedMigrationFiles.java' + include 'dev/caskeleton/adapter/outbound/persistence/testkit/migration/ConcurrentIndexMigrationInspector.java' + include 'dev/caskeleton/adapter/outbound/persistence/testkit/migration/MigrationResource.java' } into(layout.buildDirectory.dir('generated/sources/sharedMigrationFiles/java')) } diff --git a/grpc/grpc-operation-ledger-jpa/src/integrationTest/java/dev/caskeleton/grpc/ledger/GrpcOperationLedgerMigrationLockWaitIT.java b/grpc/grpc-operation-ledger-jpa/src/integrationTest/java/dev/caskeleton/grpc/ledger/GrpcOperationLedgerMigrationLockWaitIT.java index 723fe1d..7efd263 100644 --- a/grpc/grpc-operation-ledger-jpa/src/integrationTest/java/dev/caskeleton/grpc/ledger/GrpcOperationLedgerMigrationLockWaitIT.java +++ b/grpc/grpc-operation-ledger-jpa/src/integrationTest/java/dev/caskeleton/grpc/ledger/GrpcOperationLedgerMigrationLockWaitIT.java @@ -3,19 +3,24 @@ package dev.caskeleton.grpc.ledger; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; +import dev.caskeleton.adapter.outbound.persistence.testkit.migration.ConcurrentIndexMigrationInspector; +import dev.caskeleton.adapter.outbound.persistence.testkit.migration.MigrationResource; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.time.Duration; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.postgresql.ds.PGSimpleDataSource; @@ -38,9 +43,18 @@ import org.testcontainers.postgresql.PostgreSQLContainer; *
A file Flyway runs outside a transaction — one holding {@code CREATE INDEX CONCURRENTLY} or * another statement on Flyway's list, or with {@code executeInTransaction=false} beside it — is not * one this test can judge: run here in a transaction, PostgreSQL refuses it ({@code 25001}), and no - * {@code SET LOCAL} would bound it in a deploy anyway. Name such a file as an exception in this - * test, and keep it alone in its migration ({@code docs/jpa/migration-guide.md}, "Concurrent index - * builds"; re-review 2026-11-03 round 6, RR6-03-05). + * {@code SET LOCAL} would bound it in a deploy anyway. The one such file the ledger may have is a + * concurrent index build, and it goes in {@link #RUN_OUTSIDE_A_TRANSACTION} with the reason it + * needs to: the lock-wait case leaves it out, and {@code + * everyMigrationListedAsRunningOutsideATransactionIsOneConcurrentIndexBuildThatSaysSo} holds it to + * the guide instead — a concurrent index statement, alone in its file, with {@code + * executeInTransaction=false} beside it ({@code docs/jpa/migration-guide.md}, "Concurrent index + * builds"). The list takes nothing else: a {@code VACUUM FULL} or another locking statement that + * cannot run in a transaction does not belong in a migration at all ("Bound the lock wait"). The + * migrations before the one under test are applied one file at a time ({@link + * GrpcOperationLedgerMigrations#before(String)}), so a listed file is no obstacle to a later one. + * Re-review 2026-11-03 round 6, RR6-03-05; round 7, RR7-03-01: the message pointed at a list this + * test did not have. * *
Every migration after V001 is held to this, read from the tree itself ({@link
* GrpcOperationLedgerMigrations#inOrder()}), so a V004 is checked without anyone naming it here.
@@ -66,9 +80,18 @@ class GrpcOperationLedgerMigrationLockWaitIT {
.withUsername("grpc")
.withPassword("grpc");
- /** Every ledger migration after V001, the one that creates the ledger. */
+ /**
+ * The ledger migrations Flyway runs outside a transaction, by file name, each with why it has to:
+ * a concurrent index build that would stop the ledger's writes if it were built in a transaction.
+ * Empty while the tree has none.
+ */
+ static final Map One list for every PostgreSQL lane, so a new migration is applied by all of them or by none.
* The list is the tree on disk, not a copy of it: a hand-kept list let a V004 that nobody added to
@@ -38,21 +42,26 @@ final class GrpcOperationLedgerMigrations {
.toList();
}
- /** Every migration's SQL, concatenated in version order. */
- static String all() throws IOException {
+ /** Every migration's SQL in version order, one script per file. */
+ static List