Skip to content

test: add @Query Data Service connection routing tests#15423

Merged
jdaugherty merged 2 commits into7.0.xfrom
test/query-connection-routing
Feb 21, 2026
Merged

test: add @Query Data Service connection routing tests#15423
jdaugherty merged 2 commits into7.0.xfrom
test/query-connection-routing

Conversation

@jamesfredley
Copy link
Contributor

Summary

  • Add unit and functional tests for @Query-annotated Data Service methods routing to non-default datasources via @Transactional(connection)
  • Tests cover FindOneStringQueryImplementer, FindAllStringQueryImplementer, and UpdateStringQueryImplementer - previously untested code paths
  • Both abstract class and interface service patterns are tested

Changes

  • Unit test (DataServiceMultiDataSourceSpec in grails-data-hibernate5-core): 7 new tests covering @Query find-one, find-all, and update for both abstract and interface services
  • Functional test (DataServiceMultiDataSourceSpec in grails-test-examples): 4 new integration tests covering @Query find-one, find-all, and update in a full Grails application context

Test Results

  • Unit: 23/23 pass (16 existing + 7 new)
  • Functional: 10/10 pass (6 existing + 4 new)
  • codeStyle: pass

Context

During the exhaustive bug pattern sweep for connection routing issues (#15395, #15416), we identified that findStaticApiForConnectionId(domainClassNode, newMethodNode) in the 3 String Query implementers had no test coverage for multi-datasource routing. Investigation confirmed the pattern works correctly via the declaring-class fallback in TransactionalTransform.findTransactionalAnnotation(), but the code paths lacked regression tests.

Add unit and functional tests verifying that @Query-annotated Data
Service methods (find-one, find-all, update) correctly route to
non-default datasources when @transactional(connection) is specified.

Tests cover both abstract class and interface service patterns using
FindOneStringQueryImplementer, FindAllStringQueryImplementer, and
UpdateStringQueryImplementer - previously untested code paths.

Assisted-by: Claude Code <Claude@Claude.ai>
@jamesfredley jamesfredley self-assigned this Feb 20, 2026
@jamesfredley jamesfredley moved this to In Progress in Apache Grails Feb 20, 2026
@jamesfredley jamesfredley added this to the grails:7.0.8 milestone Feb 20, 2026
@jamesfredley jamesfredley marked this pull request as ready for review February 20, 2026 17:02
Copilot AI review requested due to automatic review settings February 20, 2026 17:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for @Query-annotated Data Service methods with multi-datasource connection routing via @Transactional(connection). The changes validate that FindOneStringQueryImplementer, FindAllStringQueryImplementer, and UpdateStringQueryImplementer correctly route HQL queries to non-default datasources—code paths that were previously untested following the connection routing fixes in PRs #15395 and #15416.

Changes:

  • Unit tests: 7 new tests in grails-data-hibernate5 covering @Query find-one, find-all, and update operations for both abstract class and interface service patterns
  • Functional tests: 4 new integration tests in grails-test-examples validating the same operations in a full Grails application context
  • Service methods: Added findOneByQuery, findAllByQuery, and updateAmountByName to both ProductService abstract class and ProductDataService interface

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
grails-test-examples/.../DataServiceMultiDataSourceSpec.groovy Added 4 integration tests validating @Query methods route to secondary datasource (find-one, find-one null, find-all, update)
grails-test-examples/.../ProductService.groovy Added 3 @Query-annotated abstract methods for testing HQL query routing
grails-data-hibernate5/.../DataServiceMultiDataSourceSpec.groovy Added 7 unit tests covering @Query routing for both abstract and interface service patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Restore Javadoc comments on ProductService, ProductDataService, and
DataServiceMultiDataSourceSpec that were inadvertently removed.

Assisted-by: Claude Code <Claude@Claude.ai>
@jdaugherty jdaugherty merged commit 95bb302 into 7.0.x Feb 21, 2026
32 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache Grails Feb 21, 2026
@jdaugherty jdaugherty deleted the test/query-connection-routing branch March 11, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants