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