mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add lock fair testcase
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import junit.framework.Assert;
|
||||
@@ -11,19 +12,50 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
public class LockFairTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xx");
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_fair() throws Exception {
|
||||
Assert.assertEquals(false, ((ReentrantLock)dataSource.getLock()).isFair());
|
||||
Assert.assertEquals(false, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
dataSource.setMaxWait(100);
|
||||
|
||||
Assert.assertEquals(true, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setMaxWait(110);
|
||||
|
||||
Assert.assertEquals(true, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(true, ((ReentrantLock)dataSource.getLock()).isFair());
|
||||
dataSource.setMaxWait(0);
|
||||
|
||||
Assert.assertEquals(true, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_fair_1() throws Exception {
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(false, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
dataSource.setMaxWait(100);
|
||||
|
||||
Assert.assertEquals(false, ((ReentrantLock) dataSource.getLock()).isFair());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user