Enable connection validation by default

Hikari and Commons DBCP2 are already validating that the connection is
valid before borrowing it from the pool. This commit makes that behaviour
consistent by enabling that feature for the Tomcat and Commons DBCP data
sources.

Since a validation query is required in those cases, the infrastructure
of `DataSourceHealthIndicator` has been merged in a single place: the
`DatabaseDriver` enum provides not only the driver class names but also
the validation query, if any.

Closes gh-4906
This commit is contained in:
Stephane Nicoll
2016-02-10 18:01:04 +01:00
parent eb7b1ec33c
commit 1f106ddf8c
10 changed files with 339 additions and 272 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@@ -24,7 +24,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.actuate.health.DataSourceHealthIndicator.Product;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
@@ -104,20 +103,4 @@ public class DataSourceHealthIndicatorTests {
verify(connection, times(2)).close();
}
@Test
public void productLookups() throws Exception {
assertThat(Product.forProduct("newone")).isNull();
assertThat(Product.forProduct("HSQL Database Engine")).isEqualTo(Product.HSQLDB);
assertThat(Product.forProduct("Oracle")).isEqualTo(Product.ORACLE);
assertThat(Product.forProduct("Apache Derby")).isEqualTo(Product.DERBY);
assertThat(Product.forProduct("DB2")).isEqualTo(Product.DB2);
assertThat(Product.forProduct("DB2/LINUXX8664")).isEqualTo(Product.DB2);
assertThat(Product.forProduct("DB2 UDB for AS/400")).isEqualTo(Product.DB2_AS400);
assertThat(Product.forProduct("DB3 XDB for AS/400")).isEqualTo(Product.DB2_AS400);
assertThat(Product.forProduct("Informix Dynamic Server"))
.isEqualTo(Product.INFORMIX);
assertThat(Product.forProduct("Firebird 2.5.WI")).isEqualTo(Product.FIREBIRD);
assertThat(Product.forProduct("Firebird 2.1.LI")).isEqualTo(Product.FIREBIRD);
}
}