Browse Source
* commit 'cd496c872104ff716f1435fb9a7c3430637be9ac': KERNEL-18022 refactor:db.properties增加keepAlive等参数的支持bugfix/11.0
superman
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