Skip to content

Commit 4444749

Browse files
committed
Configure JTA tests to write logs beneath build/
Closes spring-projectsgh-26440
1 parent 64aac01 commit 4444749

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ manifest.yml
3636
out
3737
overridedb.*
3838
target
39-
transaction-logs
4039
.flattened-pom.xml
4140
secrets.yml
4241
.gradletasknamecache

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.orm.jpa;
1818

19+
import java.io.File;
1920
import java.util.HashMap;
2021
import java.util.Map;
2122
import java.util.UUID;
@@ -37,6 +38,7 @@
3738
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3839
import org.springframework.boot.test.context.runner.ContextConsumer;
3940
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
41+
import org.springframework.boot.testsupport.BuildOutput;
4042
import org.springframework.boot.web.servlet.FilterRegistrationBean;
4143
import org.springframework.context.annotation.Bean;
4244
import org.springframework.context.annotation.Configuration;
@@ -68,7 +70,9 @@ abstract class AbstractJpaAutoConfigurationTests {
6870
protected AbstractJpaAutoConfigurationTests(Class<?> autoConfiguredClass) {
6971
this.autoConfiguredClass = autoConfiguredClass;
7072
this.contextRunner = new ApplicationContextRunner()
71-
.withPropertyValues("spring.datasource.generate-unique-name=true")
73+
.withPropertyValues("spring.datasource.generate-unique-name=true",
74+
"spring.jta.log-dir="
75+
+ new File(new BuildOutput(getClass()).getRootLocation(), "transaction-logs"))
7276
.withUserConfiguration(TestConfiguration.class).withConfiguration(AutoConfigurations.of(
7377
DataSourceAutoConfiguration.class, TransactionAutoConfiguration.class, autoConfiguredClass));
7478
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java

+33-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@
5151
import org.springframework.boot.jta.bitronix.PoolingConnectionFactoryBean;
5252
import org.springframework.boot.jta.bitronix.PoolingDataSourceBean;
5353
import org.springframework.boot.test.util.TestPropertyValues;
54+
import org.springframework.boot.testsupport.BuildOutput;
5455
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5556
import org.springframework.context.annotation.Bean;
5657
import org.springframework.context.annotation.Configuration;
@@ -74,6 +75,8 @@
7475
@SuppressWarnings("deprecation")
7576
class JtaAutoConfigurationTests {
7677

78+
private final File buildOutput = new BuildOutput(JtaAutoConfigurationTests.class).getRootLocation();
79+
7780
private AnnotationConfigApplicationContext context;
7881

7982
@AfterEach
@@ -104,7 +107,11 @@ void disableJtaSupport() {
104107

105108
@Test
106109
void atomikosSanityCheck() {
107-
this.context = new AnnotationConfigApplicationContext(JtaProperties.class, AtomikosJtaConfiguration.class);
110+
this.context = new AnnotationConfigApplicationContext();
111+
TestPropertyValues.of("spring.jta.log-dir:" + new File(this.buildOutput, "atomikos-logs"))
112+
.applyTo(this.context);
113+
this.context.register(JtaProperties.class, AtomikosJtaConfiguration.class);
114+
this.context.refresh();
108115
this.context.getBean(AtomikosProperties.class);
109116
this.context.getBean(UserTransactionService.class);
110117
this.context.getBean(UserTransactionManager.class);
@@ -118,7 +125,11 @@ void atomikosSanityCheck() {
118125
@Test
119126
@Deprecated
120127
void bitronixSanityCheck() {
121-
this.context = new AnnotationConfigApplicationContext(JtaProperties.class, BitronixJtaConfiguration.class);
128+
this.context = new AnnotationConfigApplicationContext();
129+
TestPropertyValues.of("spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs"))
130+
.applyTo(this.context);
131+
this.context.register(JtaProperties.class, BitronixJtaConfiguration.class);
132+
this.context.refresh();
122133
this.context.getBean(bitronix.tm.Configuration.class);
123134
this.context.getBean(TransactionManager.class);
124135
this.context.getBean(XADataSourceWrapper.class);
@@ -130,7 +141,11 @@ void bitronixSanityCheck() {
130141
@Test
131142
@Deprecated
132143
void defaultBitronixServerId() throws UnknownHostException {
133-
this.context = new AnnotationConfigApplicationContext(BitronixJtaConfiguration.class);
144+
this.context = new AnnotationConfigApplicationContext();
145+
TestPropertyValues.of("spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs"))
146+
.applyTo(this.context);
147+
this.context.register(BitronixJtaConfiguration.class);
148+
this.context.refresh();
134149
String serverId = this.context.getBean(bitronix.tm.Configuration.class).getServerId();
135150
assertThat(serverId).isEqualTo(InetAddress.getLocalHost().getHostAddress());
136151
}
@@ -139,7 +154,8 @@ void defaultBitronixServerId() throws UnknownHostException {
139154
@Deprecated
140155
void customBitronixServerId() {
141156
this.context = new AnnotationConfigApplicationContext();
142-
TestPropertyValues.of("spring.jta.transactionManagerId:custom").applyTo(this.context);
157+
TestPropertyValues.of("spring.jta.transactionManagerId:custom",
158+
"spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs")).applyTo(this.context);
143159
this.context.register(BitronixJtaConfiguration.class);
144160
this.context.refresh();
145161
String serverId = this.context.getBean(bitronix.tm.Configuration.class).getServerId();
@@ -162,7 +178,8 @@ void defaultAtomikosTransactionManagerName(@TempDir Path dir) throws IOException
162178
void atomikosConnectionFactoryPoolConfiguration() {
163179
this.context = new AnnotationConfigApplicationContext();
164180
TestPropertyValues.of("spring.jta.atomikos.connectionfactory.minPoolSize:5",
165-
"spring.jta.atomikos.connectionfactory.maxPoolSize:10").applyTo(this.context);
181+
"spring.jta.atomikos.connectionfactory.maxPoolSize:10",
182+
"spring.jta.log-dir:" + new File(this.buildOutput, "atomikos-logs")).applyTo(this.context);
166183
this.context.register(AtomikosJtaConfiguration.class, PoolConfiguration.class);
167184
this.context.refresh();
168185
AtomikosConnectionFactoryBean connectionFactory = this.context.getBean(AtomikosConnectionFactoryBean.class);
@@ -175,7 +192,8 @@ void atomikosConnectionFactoryPoolConfiguration() {
175192
void bitronixConnectionFactoryPoolConfiguration() {
176193
this.context = new AnnotationConfigApplicationContext();
177194
TestPropertyValues.of("spring.jta.bitronix.connectionfactory.minPoolSize:5",
178-
"spring.jta.bitronix.connectionfactory.maxPoolSize:10").applyTo(this.context);
195+
"spring.jta.bitronix.connectionfactory.maxPoolSize:10",
196+
"spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs")).applyTo(this.context);
179197
this.context.register(BitronixJtaConfiguration.class, PoolConfiguration.class);
180198
this.context.refresh();
181199
PoolingConnectionFactoryBean connectionFactory = this.context.getBean(PoolingConnectionFactoryBean.class);
@@ -187,7 +205,8 @@ void bitronixConnectionFactoryPoolConfiguration() {
187205
void atomikosDataSourcePoolConfiguration() {
188206
this.context = new AnnotationConfigApplicationContext();
189207
TestPropertyValues
190-
.of("spring.jta.atomikos.datasource.minPoolSize:5", "spring.jta.atomikos.datasource.maxPoolSize:10")
208+
.of("spring.jta.atomikos.datasource.minPoolSize:5", "spring.jta.atomikos.datasource.maxPoolSize:10",
209+
"spring.jta.log-dir:" + new File(this.buildOutput, "atomikos-logs"))
191210
.applyTo(this.context);
192211
this.context.register(AtomikosJtaConfiguration.class, PoolConfiguration.class);
193212
this.context.refresh();
@@ -201,7 +220,8 @@ void atomikosDataSourcePoolConfiguration() {
201220
void bitronixDataSourcePoolConfiguration() {
202221
this.context = new AnnotationConfigApplicationContext();
203222
TestPropertyValues
204-
.of("spring.jta.bitronix.datasource.minPoolSize:5", "spring.jta.bitronix.datasource.maxPoolSize:10")
223+
.of("spring.jta.bitronix.datasource.minPoolSize:5", "spring.jta.bitronix.datasource.maxPoolSize:10",
224+
"spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs"))
205225
.applyTo(this.context);
206226
this.context.register(BitronixJtaConfiguration.class, PoolConfiguration.class);
207227
this.context.refresh();
@@ -214,7 +234,8 @@ void bitronixDataSourcePoolConfiguration() {
214234
void atomikosCustomizeJtaTransactionManagerUsingProperties() {
215235
this.context = new AnnotationConfigApplicationContext();
216236
TestPropertyValues
217-
.of("spring.transaction.default-timeout:30", "spring.transaction.rollback-on-commit-failure:true")
237+
.of("spring.transaction.default-timeout:30", "spring.transaction.rollback-on-commit-failure:true",
238+
"spring.jta.log-dir:" + new File(this.buildOutput, "atomikos-logs"))
218239
.applyTo(this.context);
219240
this.context.register(AtomikosJtaConfiguration.class, TransactionAutoConfiguration.class);
220241
this.context.refresh();
@@ -228,7 +249,8 @@ void atomikosCustomizeJtaTransactionManagerUsingProperties() {
228249
void bitronixCustomizeJtaTransactionManagerUsingProperties() {
229250
this.context = new AnnotationConfigApplicationContext();
230251
TestPropertyValues
231-
.of("spring.transaction.default-timeout:30", "spring.transaction.rollback-on-commit-failure:true")
252+
.of("spring.transaction.default-timeout:30", "spring.transaction.rollback-on-commit-failure:true",
253+
"spring.jta.log-dir:" + new File(this.buildOutput, "bitronix-logs"))
232254
.applyTo(this.context);
233255
this.context.register(BitronixJtaConfiguration.class, TransactionAutoConfiguration.class);
234256
this.context.refresh();

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-artemis"))
1010
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-jpa"))
1111
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jta-atomikos"))
12+
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
1213
if (JavaVersion.current().java9Compatible) {
1314
implementation("jakarta.xml.bind:jakarta.xml.bind-api")
1415
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/test/java/smoketest/atomikos/SampleAtomikosApplicationTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,15 @@
1616

1717
package smoketest.atomikos;
1818

19+
import java.io.File;
1920
import java.util.function.Consumer;
2021

2122
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.api.extension.ExtendWith;
2324

2425
import org.springframework.boot.test.system.CapturedOutput;
2526
import org.springframework.boot.test.system.OutputCaptureExtension;
27+
import org.springframework.boot.testsupport.BuildOutput;
2628
import org.springframework.util.StringUtils;
2729

2830
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,7 +39,8 @@ class SampleAtomikosApplicationTests {
3739

3840
@Test
3941
void testTransactionRollback(CapturedOutput output) throws Exception {
40-
SampleAtomikosApplication.main(new String[] {});
42+
File logDir = new File(new BuildOutput(getClass()).getRootLocation(), "atomikos-logs");
43+
SampleAtomikosApplication.main(new String[] { "--spring.jta.log-dir=" + logDir });
4144
assertThat(output).satisfies(numberOfOccurrences("---->", 1));
4245
assertThat(output).satisfies(numberOfOccurrences("----> josh", 1));
4346
assertThat(output).satisfies(numberOfOccurrences("Count is 1", 2));

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-artemis"))
1010
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-jpa"))
1111
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jta-bitronix"))
12+
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
1213
if (JavaVersion.current().java9Compatible) {
1314
implementation("jakarta.xml.bind:jakarta.xml.bind-api")
1415
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/test/java/smoketest/bitronix/SampleBitronixApplicationTests.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package smoketest.bitronix;
1818

19+
import java.io.File;
1920
import java.util.function.Consumer;
2021

2122
import bitronix.tm.resource.jms.PoolingConnectionFactory;
@@ -25,6 +26,7 @@
2526
import org.springframework.boot.SpringApplication;
2627
import org.springframework.boot.test.system.CapturedOutput;
2728
import org.springframework.boot.test.system.OutputCaptureExtension;
29+
import org.springframework.boot.testsupport.BuildOutput;
2830
import org.springframework.context.ApplicationContext;
2931
import org.springframework.util.StringUtils;
3032

@@ -38,9 +40,11 @@
3840
@ExtendWith(OutputCaptureExtension.class)
3941
class SampleBitronixApplicationTests {
4042

43+
private final File jtaLogDir = new File(new BuildOutput(getClass()).getRootLocation(), "bitronix-logs");
44+
4145
@Test
4246
void testTransactionRollback(CapturedOutput output) throws Exception {
43-
SampleBitronixApplication.main(new String[] {});
47+
SampleBitronixApplication.main(new String[] { "--spring.jta.log-dir=" + this.jtaLogDir });
4448
assertThat(output).satisfies(numberOfOccurrences("---->", 1));
4549
assertThat(output).satisfies(numberOfOccurrences("----> josh", 1));
4650
assertThat(output).satisfies(numberOfOccurrences("Count is 1", 2));
@@ -49,7 +53,8 @@ void testTransactionRollback(CapturedOutput output) throws Exception {
4953

5054
@Test
5155
void testExposesXaAndNonXa() {
52-
ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class);
56+
ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class,
57+
"--spring.jta.log-dir=" + this.jtaLogDir);
5358
Object jmsConnectionFactory = context.getBean("jmsConnectionFactory");
5459
Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory");
5560
Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory");

0 commit comments

Comments
 (0)