mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #19637 from nosan
* pr/19637: Fix retrieval of parent logger in PoolingDataSourceBean Closes gh-19637
This commit is contained in:
commit
e87ed08ef4
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -107,13 +107,16 @@ public class PoolingDataSourceBean extends PoolingDataSource implements BeanName
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
try {
|
||||
return this.getParentLogger();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Work around https://jira.codehaus.org/browse/BTM-134
|
||||
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
XADataSource dataSource = this.dataSource;
|
||||
if (dataSource != null) {
|
||||
try {
|
||||
return dataSource.getParentLogger();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Swallow and continue
|
||||
}
|
||||
}
|
||||
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -17,6 +17,8 @@
|
||||
package org.springframework.boot.jta.bitronix;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.sql.XAConnection;
|
||||
import javax.sql.XADataSource;
|
||||
@ -60,6 +62,28 @@ public class PoolingDataSourceBeanTests {
|
||||
assertThat(this.bean.getUniqueName()).isEqualTo("un");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGlobalLoggerWhenDataSourceIsAbsent() throws SQLFeatureNotSupportedException {
|
||||
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGlobalLoggerWhenDataSourceThrowsException() throws SQLFeatureNotSupportedException {
|
||||
XADataSource dataSource = mock(XADataSource.class);
|
||||
given(dataSource.getParentLogger()).willThrow(new SQLFeatureNotSupportedException());
|
||||
this.bean.setDataSource(dataSource);
|
||||
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnParentLoggerFromDataSource() throws SQLFeatureNotSupportedException {
|
||||
Logger logger = Logger.getLogger("test");
|
||||
XADataSource dataSource = mock(XADataSource.class);
|
||||
given(dataSource.getParentLogger()).willReturn(logger);
|
||||
this.bean.setDataSource(dataSource);
|
||||
assertThat(this.bean.getParentLogger()).isSameAs(logger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDataSource() throws Exception {
|
||||
XADataSource dataSource = mock(XADataSource.class);
|
||||
|
Loading…
Reference in New Issue
Block a user