From d07f06026c945f93bd5a2b17f520e45d63b68292 Mon Sep 17 00:00:00 2001 From: fhanik Date: Wed, 29 Oct 2008 04:34:29 +0000 Subject: [PATCH] Added in a fairness test to showcase the FairBlockingQueue git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@708769 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tomcat/jdbc/pool/FairBlockingQueue.java | 2 +- .../org/apache/tomcat/jdbc/test/FairnessTest.java | 192 +++++++++++++++++++++ .../org/apache/tomcat/jdbc/test/TestGCClose.java | 8 + 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java index 477d8c9e4..c25e20716 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java @@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReentrantLock; */ public class FairBlockingQueue implements BlockingQueue { - ReentrantLock lock = new ReentrantLock(); + ReentrantLock lock = new ReentrantLock(false); LinkedList items = null; diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java new file mode 100644 index 000000000..c2dc742da --- /dev/null +++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.jdbc.test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.sql.Connection; +import java.sql.Statement; +import java.sql.ResultSet; + +import javax.sql.DataSource; + +import org.apache.tomcat.jdbc.pool.DataSourceFactory; + +/** + * @author Filip Hanik + * @version 1.0 + */ +public class FairnessTest extends DefaultTestCase { + public FairnessTest(String name) { + super(name); + } + + protected boolean run = true; + protected long sleep = 10; + protected long complete = 20000; + CountDownLatch latch = null; + protected void printThreadResults(TestThread[] threads, String name) { + long minfetch = Long.MAX_VALUE, maxfetch = Long.MIN_VALUE, totalfetch = 0; + float avgfetch = 0; + for (int i=0; i