Skip to content

Commit 40dca75

Browse files
committed
Use the same TransactionManager
Metadata and QueryStateMachine must use the same `TransactionManager` instance.
1 parent b08eb4d commit 40dca75

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

core/trino-main/src/test/java/io/trino/execution/TestQueryStateMachine.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.trino.execution.warnings.WarningCollector;
3131
import io.trino.execution.warnings.WarningCollectorConfig;
3232
import io.trino.metadata.Metadata;
33+
import io.trino.metadata.TestMetadataManager;
3334
import io.trino.plugin.base.security.AllowAllSystemAccessControl;
3435
import io.trino.plugin.base.security.DefaultSystemAccessControl;
3536
import io.trino.security.AccessControlConfig;
@@ -89,7 +90,6 @@
8990
import static io.trino.execution.QueryState.STARTING;
9091
import static io.trino.execution.QueryState.WAITING_FOR_RESOURCES;
9192
import static io.trino.execution.querystats.PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector;
92-
import static io.trino.metadata.TestMetadataManager.createTestMetadataManager;
9393
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
9494
import static io.trino.spi.StandardErrorCode.TYPE_MISMATCH;
9595
import static io.trino.spi.StandardErrorCode.USER_CANCELED;
@@ -442,15 +442,7 @@ public void testPreserveFirstFailure()
442442
{
443443
CountDownLatch cleanup = new CountDownLatch(1);
444444
QueryStateMachine queryStateMachine = queryStateMachine()
445-
.withMetadata(new TracingMetadata(noopTracer(), createTestMetadataManager())
446-
{
447-
@Override
448-
public void cleanupQuery(Session session)
449-
{
450-
cleanup.countDown();
451-
super.cleanupQuery(session);
452-
}
453-
})
445+
.beforeQueryCleanup(cleanup::countDown)
454446
.build();
455447

456448
Future<?> anotherThread = executor.submit(() -> {
@@ -479,15 +471,7 @@ public void testPreserveCancellation()
479471
{
480472
CountDownLatch cleanup = new CountDownLatch(1);
481473
QueryStateMachine queryStateMachine = queryStateMachine()
482-
.withMetadata(new TracingMetadata(noopTracer(), createTestMetadataManager())
483-
{
484-
@Override
485-
public void cleanupQuery(Session session)
486-
{
487-
cleanup.countDown();
488-
super.cleanupQuery(session);
489-
}
490-
})
474+
.beforeQueryCleanup(cleanup::countDown)
491475
.build();
492476

493477
Future<?> anotherThread = executor.submit(() -> {
@@ -761,7 +745,7 @@ private QueryStateMachineBuilder queryStateMachine()
761745
private class QueryStateMachineBuilder
762746
{
763747
private Ticker ticker = Ticker.systemTicker();
764-
private Metadata metadata;
748+
private Optional<Runnable> beforeQueryCleanup = Optional.empty();
765749
private WarningCollector warningCollector = WarningCollector.NOOP;
766750
private String setCatalog;
767751
private String setPath;
@@ -780,9 +764,9 @@ public QueryStateMachineBuilder withTicker(Ticker ticker)
780764
}
781765

782766
@CanIgnoreReturnValue
783-
public QueryStateMachineBuilder withMetadata(Metadata metadata)
767+
public QueryStateMachineBuilder beforeQueryCleanup(Runnable runnable)
784768
{
785-
this.metadata = metadata;
769+
this.beforeQueryCleanup = Optional.of(runnable);
786770
return this;
787771
}
788772

@@ -842,10 +826,23 @@ public QueryStateMachineBuilder withAddPreparedStatements(Map<String, String> pr
842826

843827
public QueryStateMachine build()
844828
{
845-
if (metadata == null) {
846-
metadata = createTestMetadataManager();
847-
}
848829
TransactionManager transactionManager = createTestTransactionManager();
830+
Metadata metadata = TestMetadataManager.builder()
831+
.withTransactionManager(transactionManager)
832+
.build();
833+
if (beforeQueryCleanup.isPresent()) {
834+
Runnable beforeQueryCleanupAction = beforeQueryCleanup.get();
835+
metadata = new TracingMetadata(noopTracer(), metadata)
836+
{
837+
@Override
838+
public void cleanupQuery(Session session)
839+
{
840+
beforeQueryCleanupAction.run();
841+
super.cleanupQuery(session);
842+
}
843+
};
844+
}
845+
849846
AccessControlManager accessControl = new AccessControlManager(
850847
NodeVersion.UNKNOWN,
851848
transactionManager,

0 commit comments

Comments
 (0)