Browse Source
* commit '9240f2d32ba48e8f96beb75211bc69ec7762a877': KERNEL-18022 refactor:db.properties增加keepAlive等参数的支持persist/jsy11
superman
3 weeks 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