From 219adb3e18a8153917e6b1355b2cee7e7408feff Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Mon, 22 May 2023 18:00:55 -0400 Subject: [PATCH] fix: additional sample test for both transactionManager work together. (#1848) This pr adds an integration test to `spring-cloud-gcp-data-multi-sample` for the scenario of both Datastore and Spanner Transaction manager working in the same app. It is a followup on #1412 --- .../MultipleDataModuleIntegrationTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-data-multi-sample/src/test/java/com/example/MultipleDataModuleIntegrationTest.java b/spring-cloud-gcp-samples/spring-cloud-gcp-data-multi-sample/src/test/java/com/example/MultipleDataModuleIntegrationTest.java index ddc6f71ae5..d8ff90cbfa 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-data-multi-sample/src/test/java/com/example/MultipleDataModuleIntegrationTest.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-data-multi-sample/src/test/java/com/example/MultipleDataModuleIntegrationTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -31,7 +32,7 @@ @ExtendWith(SpringExtension.class) @EnabledIfSystemProperty(named = "it.multisample", matches = "true") @TestPropertySource("classpath:application-test.properties") -@EnableAutoConfiguration +@SpringBootTest class MultipleDataModuleIntegrationTest { // The Spanner Repo @@ -40,6 +41,10 @@ class MultipleDataModuleIntegrationTest { // The Datastore Repo @Autowired PersonRepository datastorePersonRepository; + @Autowired TraderService traderService; + + @Autowired PersonService personService; + @Test void testMultipleModulesTogether() { @@ -55,4 +60,20 @@ void testMultipleModulesTogether() { assertThat(this.traderRepository.count()).isEqualTo(1L); assertThat(this.datastorePersonRepository.count()).isEqualTo(1L); } + + @Test + void testMultipleModulesTogetherWithTransaction() { + + this.traderService.deleteAll(); + this.personService.deleteAll(); + + assertThat(this.traderService.count()).isZero(); + assertThat(this.personService.count()).isZero(); + + this.traderService.save(new Trader("id1", "trader", "one")); + this.personService.save(new Person(1L, "person1")); + + assertThat(this.traderService.count()).isEqualTo(1L); + assertThat(this.personService.count()).isEqualTo(1L); + } }