Browse Source
Merge in CORE/base-third from ~GAATTC.DANG/base-third:feature/x to feature/x * commit '49d8ac32bd2da2f3e946956ff9b92e04d08d1d44': KERNEL-18022 refactor:db.properties增加keepAlive等参数的支持feature/x
Gaattc.Dang-党伟豪
2 months ago
3 changed files with 137 additions and 20 deletions
@ -0,0 +1,57 @@
|
||||
package com.fr.third.alibaba.druid.pool; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* @author gaattc |
||||
* @since 6.1 |
||||
* Created by gaattc on 2024/9/10 |
||||
*/ |
||||
public class DruidDataSourceFactoryTest { |
||||
|
||||
@Test |
||||
public void testConfigFromProperty() throws Exception { |
||||
try (DruidDataSource druidDataSource = new DruidDataSource()) { |
||||
Properties properties = new Properties(); |
||||
properties.setProperty("keepAlive", "true"); |
||||
properties.setProperty("keepAliveBetweenTimeMillis", "233333"); |
||||
properties.setProperty("validationQueryTimeout", "2333"); |
||||
properties.setProperty("removeAbandoned", "true"); |
||||
properties.setProperty("logAbandoned", "true"); |
||||
properties.setProperty("removeAbandonedTimeout", "2333"); |
||||
|
||||
DruidDataSourceFactory.config(druidDataSource, properties); |
||||
Assert.assertTrue(druidDataSource.isKeepAlive()); |
||||
Assert.assertEquals(233333, druidDataSource.getKeepAliveBetweenTimeMillis()); |
||||
Assert.assertEquals(2333, druidDataSource.getValidationQueryTimeout()); |
||||
Assert.assertTrue(druidDataSource.isRemoveAbandoned()); |
||||
Assert.assertTrue(druidDataSource.isLogAbandoned()); |
||||
Assert.assertEquals(2333, druidDataSource.getRemoveAbandonedTimeout()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testConfigFromPropertyWithPrefix() throws Exception { |
||||
try (DruidDataSource druidDataSource = new DruidDataSource()) { |
||||
Properties properties = new Properties(); |
||||
properties.setProperty("hibernate.keepAlive", "true"); |
||||
properties.setProperty("hibernate.keepAliveBetweenTimeMillis", "233333"); |
||||
properties.setProperty("hibernate.validationQueryTimeout", "2333"); |
||||
properties.setProperty("hibernate.removeAbandoned", "true"); |
||||
properties.setProperty("hibernate.logAbandoned", "true"); |
||||
properties.setProperty("hibernate.removeAbandonedTimeout", "2333"); |
||||
|
||||
DruidDataSourceFactory.config(druidDataSource, properties); |
||||
Assert.assertTrue(druidDataSource.isKeepAlive()); |
||||
Assert.assertEquals(233333, druidDataSource.getKeepAliveBetweenTimeMillis()); |
||||
Assert.assertEquals(2333, druidDataSource.getValidationQueryTimeout()); |
||||
Assert.assertTrue(druidDataSource.isRemoveAbandoned()); |
||||
Assert.assertTrue(druidDataSource.isLogAbandoned()); |
||||
Assert.assertEquals(2333, druidDataSource.getRemoveAbandonedTimeout()); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue