[jboss-cvs] JBossAS SVN: r111210 - in projects/jboss-jca/trunk/core/src: main/java/org/jboss/jca/core/connectionmanager and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 19 11:41:00 EDT 2011
Author: jesper.pedersen
Date: 2011-04-19 11:41:00 -0400 (Tue, 19 Apr 2011)
New Revision: 111210
Added:
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/TestConnectionTestCase.java
Removed:
projects/jboss-jca/trunk/core/src/test/resources/log4j.xml
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/Pool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/ReauthPool.java
projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/PrefillTestCase.java
Log:
[JBJCA-555] Add testConnection to pool api
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/Pool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/Pool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/Pool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -46,6 +46,12 @@
public void flush(boolean kill);
/**
+ * Test if a connection can be obtained
+ * @return True if it was poosible to get a connection; otherwise false
+ */
+ public boolean testConnection();
+
+ /**
* Get the statistics
* @return The value
*/
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -37,6 +37,12 @@
public int getActiveCount();
/**
+ * Get the available count
+ * @return The value
+ */
+ public int getAvailableCount();
+
+ /**
* Get the average time spent waiting on a connection (milliseconds)
* @return The value
*/
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -204,6 +204,14 @@
}
/**
+ * {@inheritDoc}
+ */
+ public String getSecurityDomain()
+ {
+ return securityDomain;
+ }
+
+ /**
* Sets security domain
* @param securityDomain security domain
*/
@@ -219,18 +227,8 @@
}
/**
- * Gets security domain.
- * @return security domain
+ * {@inheritDoc}
*/
- public String getSecurityDomain()
- {
- return securityDomain;
- }
-
- /**
- * Gets subject factory instance.
- * @return subject factory
- */
public SubjectFactory getSubjectFactory()
{
return subjectFactory;
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManager.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManager.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -27,6 +27,8 @@
import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
import org.jboss.jca.core.connectionmanager.pool.api.Pool;
+import org.jboss.security.SubjectFactory;
+
/**
* Internal connection manager contract.
* <p>
@@ -82,6 +84,18 @@
public void setJndiName(String value);
/**
+ * Get the security domain.
+ * @return The value
+ */
+ public String getSecurityDomain();
+
+ /**
+ * Get the subject factory
+ * @return The value
+ */
+ public SubjectFactory getSubjectFactory();
+
+ /**
* Unregister association.
* @param cl connection listener
* @param c connection
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -108,7 +108,7 @@
this.poolConfiguration = pc;
this.noTxSeparatePools = noTxSeparatePools;
this.trace = log.isTraceEnabled();
- this.statistics = new SubPoolStatistics(subPools);
+ this.statistics = new SubPoolStatistics(pc.getMaxSize(), subPools);
}
/**
@@ -502,6 +502,15 @@
}
/**
+ * Get the connection listener factory
+ * @return The value
+ */
+ protected ConnectionListenerFactory getConnectionListenerFactory()
+ {
+ return clf;
+ }
+
+ /**
* {@inheritDoc}
*/
public void setConnectionListenerFactory(ConnectionListenerFactory clf)
@@ -514,7 +523,7 @@
*/
public void shutdown()
{
- flush();
+ flush(true);
}
/**
@@ -526,6 +535,50 @@
}
/**
+ * {@inheritDoc}
+ */
+ public abstract boolean testConnection();
+
+ /**
+ * Test if a connection can be obtained
+ * @param subject Optional subject
+ * @return True if possible; otherwise false
+ */
+ protected boolean internalTestConnection(Subject subject)
+ {
+ boolean result = false;
+ ConnectionListener cl = null;
+ try
+ {
+ if (getStatistics().getAvailableCount() > 0)
+ {
+ cl = getConnection(null, subject, null);
+ result = true;
+ }
+ }
+ catch (Throwable ignored)
+ {
+ // Ignore
+ }
+ finally
+ {
+ if (cl != null)
+ {
+ try
+ {
+ returnConnection(cl, false);
+ }
+ catch (ResourceException ire)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
* Get the subPools. This method is package protected beacause it is intended only for test case use.
* Please don't use it in your production code.
*
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -42,6 +42,7 @@
public class SubPoolStatistics implements PoolStatistics
{
private static final String ACTIVE_COUNT = "ActiveCount";
+ private static final String AVAILABLE_COUNT = "AvailableCount";
private static final String AVERAGE_BLOCKING_TIME = "AverageBlockingTime";
private static final String AVERAGE_CREATION_TIME = "AverageCreationTime";
private static final String CREATED_COUNT = "CreatedCount";
@@ -53,6 +54,7 @@
private static final String TOTAL_BLOCKING_TIME = "TotalBlockingTime";
private static final String TOTAL_CREATION_TIME = "TotalCreationTime";
+ private int maxPoolSize;
private ConcurrentMap<Object, SubPoolContext> subPools;
private Set<String> names;
private Map<String, Class> types;
@@ -61,10 +63,12 @@
/**
* Constructor
+ * @param maxPoolSize The maximum pool size
* @param subPools The sub pool map
*/
- public SubPoolStatistics(ConcurrentMap<Object, SubPoolContext> subPools)
+ public SubPoolStatistics(int maxPoolSize, ConcurrentMap<Object, SubPoolContext> subPools)
{
+ this.maxPoolSize = maxPoolSize;
this.subPools = subPools;
Set<String> n = new HashSet<String>();
@@ -73,6 +77,9 @@
n.add(ACTIVE_COUNT);
t.put(ACTIVE_COUNT, int.class);
+ n.add(AVAILABLE_COUNT);
+ t.put(AVAILABLE_COUNT, int.class);
+
n.add(AVERAGE_BLOCKING_TIME);
t.put(AVERAGE_BLOCKING_TIME, long.class);
@@ -175,6 +182,10 @@
{
return getActiveCount();
}
+ else if (AVAILABLE_COUNT.equals(name))
+ {
+ return getAvailableCount();
+ }
else if (AVERAGE_BLOCKING_TIME.equals(name))
{
return getAverageBlockingTime();
@@ -262,6 +273,33 @@
/**
* {@inheritDoc}
*/
+ public int getAvailableCount()
+ {
+ if (isEnabled())
+ {
+ int result = -1;
+
+ if (subPools.size() > 0)
+ {
+ result = 0;
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getAvailableCount();
+ }
+ }
+
+ if (result != -1)
+ return result;
+
+ return maxPoolSize;
+ }
+
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public long getAverageBlockingTime()
{
if (isEnabled())
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -27,9 +27,9 @@
import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
import org.jboss.jca.core.connectionmanager.listener.ConnectionState;
-import org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool;
import org.jboss.jca.core.connectionmanager.pool.SubPoolContext;
import org.jboss.jca.core.connectionmanager.pool.api.Pool;
+import org.jboss.jca.core.connectionmanager.pool.api.PrefillPool;
import org.jboss.jca.core.connectionmanager.pool.idle.IdleRemover;
import org.jboss.jca.core.connectionmanager.pool.validator.ConnectionValidator;
@@ -162,10 +162,10 @@
this.trace = log.isTraceEnabled();
this.cls = new ArrayBlockingQueue<ConnectionListener>(this.maxSize, true);
this.permits = new ConcurrentHashMap<ConnectionListener, ConnectionListener>(this.maxSize);
- this.statistics = new ManagedConnectionPoolStatisticsImpl();
+ this.statistics = new ManagedConnectionPoolStatisticsImpl(maxSize);
// Schedule managed connection pool for prefill
- if (pc.isPrefill() && p instanceof AbstractPrefillPool)
+ if (pc.isPrefill() && p instanceof PrefillPool)
{
PoolFiller.fillPool(this);
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -41,6 +41,7 @@
public class ManagedConnectionPoolStatisticsImpl implements ManagedConnectionPoolStatistics
{
private static final String ACTIVE_COUNT = "ActiveCount";
+ private static final String AVAILABLE_COUNT = "AvailableCount";
private static final String AVERAGE_BLOCKING_TIME = "AverageBlockingTime";
private static final String AVERAGE_CREATION_TIME = "AverageCreationTime";
private static final String CREATED_COUNT = "CreatedCount";
@@ -52,6 +53,8 @@
private static final String TOTAL_BLOCKING_TIME = "TotalBlockingTime";
private static final String TOTAL_CREATION_TIME = "TotalCreationTime";
+ private int maxPoolSize;
+
private Set<String> names;
private Map<String, Class> types;
private AtomicBoolean enabled;
@@ -68,15 +71,21 @@
/**
* Constructor
+ * @param maxPoolSize The maximum pool size
*/
- public ManagedConnectionPoolStatisticsImpl()
+ public ManagedConnectionPoolStatisticsImpl(int maxPoolSize)
{
+ this.maxPoolSize = maxPoolSize;
+
Set<String> n = new HashSet<String>();
Map<String, Class> t = new HashMap<String, Class>();
n.add(ACTIVE_COUNT);
t.put(ACTIVE_COUNT, int.class);
+ n.add(AVAILABLE_COUNT);
+ t.put(AVAILABLE_COUNT, int.class);
+
n.add(AVERAGE_BLOCKING_TIME);
t.put(AVERAGE_BLOCKING_TIME, long.class);
@@ -188,6 +197,10 @@
{
return getActiveCount();
}
+ else if (AVAILABLE_COUNT.equals(name))
+ {
+ return getAvailableCount();
+ }
else if (AVERAGE_BLOCKING_TIME.equals(name))
{
return getAverageBlockingTime();
@@ -258,6 +271,17 @@
/**
* {@inheritDoc}
*/
+ public int getAvailableCount()
+ {
+ if (isEnabled())
+ return maxPoolSize - getActiveCount();
+
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public long getAverageBlockingTime()
{
if (isEnabled())
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -163,7 +163,7 @@
this.trace = log.isTraceEnabled();
this.cls = new ArrayList<ConnectionListener>(this.maxSize);
this.permits = new Semaphore(this.maxSize, true);
- this.statistics = new ManagedConnectionPoolStatisticsImpl();
+ this.statistics = new ManagedConnectionPoolStatisticsImpl(maxSize);
// Schedule managed connection pool for prefill
if (pc.isPrefill() && p instanceof PrefillPool)
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -73,4 +73,12 @@
{
// No-operation
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean testConnection()
+ {
+ return internalTestConnection(null);
+ }
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -59,4 +59,12 @@
{
return new CriKey(cri, separateNoTx);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean testConnection()
+ {
+ return false;
+ }
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -23,13 +23,24 @@
package org.jboss.jca.core.connectionmanager.pool.strategy;
import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.connectionmanager.ConnectionManager;
import org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Set;
+
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextAssociation;
+import org.jboss.security.SecurityContextFactory;
+import org.jboss.security.SubjectFactory;
+
/**
* Pool implementation that uses subject.
*
@@ -59,4 +70,94 @@
{
return new SubjectKey(subject, separateNoTx);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean testConnection()
+ {
+ try
+ {
+ ConnectionManager cm = (ConnectionManager)getConnectionListenerFactory();
+ ManagedConnectionFactory mcf = getManagedConnectionFactory();
+
+ Subject subject = createSubject(cm.getSubjectFactory(), cm.getSecurityDomain(), mcf);
+
+ if (subject != null)
+ return internalTestConnection(subject);
+ }
+ catch (Throwable t)
+ {
+ log.debug("Error during testConnection: " + t.getMessage(), t);
+ }
+
+ return false;
+ }
+
+ /**
+ * Create a subject
+ * @param subjectFactory The subject factory
+ * @param securityDomain The security domain
+ * @param mcf The managed connection factory
+ * @return The subject; <code>null</code> in case of an error
+ */
+ protected Subject createSubject(final SubjectFactory subjectFactory,
+ final String securityDomain,
+ final ManagedConnectionFactory mcf)
+ {
+ if (subjectFactory == null)
+ throw new IllegalArgumentException("SubjectFactory is null");
+
+ if (securityDomain == null)
+ throw new IllegalArgumentException("SecurityDomain is null");
+
+ return AccessController.doPrivileged(new PrivilegedAction<Subject>()
+ {
+ public Subject run()
+ {
+ try
+ {
+ if (SecurityContextAssociation.getSecurityContext() == null)
+ {
+ // Create a security context on the association
+ SecurityContext securityContext = SecurityContextFactory.createSecurityContext(securityDomain);
+ SecurityContextAssociation.setSecurityContext(securityContext);
+
+ // Unauthenticated
+ Subject unauthenticated = new Subject();
+
+ // Leave the subject empty as we don't have any information to do the
+ // authentication with - and we only need it to be able to get the
+ // real subject from the SubjectFactory
+
+ // Set the authenticated subject
+ securityContext.getSubjectInfo().setAuthenticatedSubject(unauthenticated);
+ }
+
+ // Use the unauthenticated subject to get the real subject instance
+ Subject subject = subjectFactory.createSubject(securityDomain);
+
+ Set<PasswordCredential> pcs = subject.getPrivateCredentials(PasswordCredential.class);
+ if (pcs != null && pcs.size() > 0)
+ {
+ for (PasswordCredential pc : pcs)
+ {
+ pc.setManagedConnectionFactory(mcf);
+ }
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Subject=" + subject);
+
+ return subject;
+ }
+ catch (Throwable t)
+ {
+ log.error("Exception during createSubject()" + t.getMessage(), t);
+ }
+
+ return null;
+ }
+ });
+ }
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -60,4 +60,12 @@
{
return new SubjectCriKey(subject, cri, separateNoTx);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean testConnection()
+ {
+ return false;
+ }
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/ReauthPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/ReauthPool.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/ReauthPool.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -77,4 +77,12 @@
{
// No-operation
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean testConnection()
+ {
+ return false;
+ }
}
Modified: projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties
===================================================================
--- projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties 2011-04-19 15:41:00 UTC (rev 111210)
@@ -1,4 +1,5 @@
ActiveCount=The active count
+AvailableCount=The available count
AverageBlockingTime=The average time spent blocking for a connection
AverageCreationTime=The average time spent creating a physical connection
CreatedCount=The created count
Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/PrefillTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/PrefillTestCase.java 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/PrefillTestCase.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -266,4 +266,22 @@
assertFalse(pool instanceof PrefillPool);
}
+
+ /**
+ * Reauth
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testReauth() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.REAUTH, mcf, config, false);
+
+ assertFalse(pool instanceof PrefillPool);
+ }
}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/TestConnectionTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/TestConnectionTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/TestConnectionTestCase.java 2011-04-19 15:41:00 UTC (rev 111210)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.pool;
+
+import org.jboss.jca.common.api.metadata.common.FlushStrategy;
+import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.connectionmanager.ConnectionManagerFactory;
+import org.jboss.jca.core.connectionmanager.NoTxConnectionManager;
+import org.jboss.jca.core.connectionmanager.common.MockManagedConnectionFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.Pool;
+import org.jboss.jca.core.connectionmanager.pool.api.PoolFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.PoolStrategy;
+import org.jboss.jca.core.security.DefaultSubjectFactory;
+
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
+
+import org.jboss.security.SubjectFactory;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test connection test case
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TestConnectionTestCase
+{
+ /**
+ * OnePool
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testOnePool() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.ONE_POOL, mcf, config, false);
+
+ NoTxConnectionManager noTxConnectionManager =
+ cmf.createNonTransactional(TransactionSupportLevel.NoTransaction,
+ pool, null, null, false, null,
+ FlushStrategy.FAILING_CONNECTION_ONLY,
+ null, null);
+
+ assertTrue(pool.testConnection());
+ }
+
+ /**
+ * PoolByCri
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testPoolByCri() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.POOL_BY_CRI, mcf, config, false);
+
+ assertFalse(pool.testConnection());
+ }
+
+ /**
+ * PoolBySubject
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testPoolBySubject() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ SubjectFactory subjectFactory = new DefaultSubjectFactory("domain", "user", "password");
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.POOL_BY_SUBJECT, mcf, config, false);
+
+ NoTxConnectionManager noTxConnectionManager =
+ cmf.createNonTransactional(TransactionSupportLevel.NoTransaction, pool,
+ subjectFactory, "domain", false, null,
+ FlushStrategy.FAILING_CONNECTION_ONLY,
+ null, null);
+
+ assertTrue(pool.testConnection());
+ }
+
+ /**
+ * PoolBySubjectAndCri
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testPoolBySubjectAndCri() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.POOL_BY_SUBJECT_AND_CRI, mcf, config, false);
+
+ assertFalse(pool.testConnection());
+ }
+
+ /**
+ * ReauthPool
+ * @throws Exception for exception.
+ */
+ @Test
+ public void testReauth() throws Exception
+ {
+ ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+ ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+
+ PoolConfiguration config = new PoolConfiguration();
+
+ PoolFactory pf = new PoolFactory();
+ Pool pool = pf.create(PoolStrategy.REAUTH, mcf, config, false);
+
+ assertFalse(pool.testConnection());
+ }
+}
Deleted: projects/jboss-jca/trunk/core/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/log4j.xml 2011-04-19 13:50:00 UTC (rev 111209)
+++ projects/jboss-jca/trunk/core/src/test/resources/log4j.xml 2011-04-19 15:41:00 UTC (rev 111210)
@@ -1,98 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-
-<!-- ===================================================================== -->
-<!-- -->
-<!-- Log4j Configuration -->
-<!-- -->
-<!-- ===================================================================== -->
-
-<!-- $Id: log4j.xml 68954 2008-01-14 17:55:41Z ALRubinger $ -->
-
-<!--
- | For more configuration infromation and examples see the Jakarta Log4j
- | owebsite: http://jakarta.apache.org/log4j
- -->
-
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
-
- <!-- ================================= -->
- <!-- Preserve messages in a local file -->
- <!-- ================================= -->
-
- <!-- A time/date based rolling appender -->
- <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
- <param name="File" value="${test.dir}/test.log"/>
- <param name="Append" value="true"/>
-
- <!-- Rollover at midnight each day -->
- <param name="DatePattern" value="'.'yyyy-MM-dd"/>
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
- </layout>
- </appender>
-
- <!-- ============================== -->
- <!-- Append messages to the console -->
- <!-- ============================== -->
-
- <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
- <param name="Threshold" value="FATAL"/>
- <param name="Target" value="System.out"/>
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
- </layout>
- </appender>
-
-
- <!-- ================ -->
- <!-- Limit categories -->
- <!-- ================ -->
-
- <!-- Limit JBoss categories to INFO
- <category name="org.jboss">
- <priority value="INFO" class="org.jboss.logging.XLevel"/>
- </category>
- -->
-
- <!-- Increase the priority threshold for the DefaultDS category
- <category name="DefaultDS">
- <priority value="FATAL"/>
- </category>
- -->
-
- <!-- Decrease the priority threshold for the org.jboss.varia category
- <category name="org.jboss.varia">
- <priority value="DEBUG"/>
- </category>
- -->
-
- <!--
- | An example of enabling the custom TRACE level priority that is used
- | by the JBoss internals to diagnose low level details.
-
- <category name="org.jboss.system">
- <priority value="TRACE" class="org.jboss.logging.XLevel"/>
- </category>
-
- <category name="org.jboss.security">
- <priority value="TRACE" class="org.jboss.logging.XLevel"/>
- </category>
-
- <category name="org.jboss.tm">
- <priority value="TRACE" class="org.jboss.logging.XLevel"/>
- </category>
- -->
-
- <!-- ======================= -->
- <!-- Setup the Root category -->
- <!-- ======================= -->
-
- <root>
- <!-- <appender-ref ref="CONSOLE"/> -->
- <appender-ref ref="FILE"/>
- </root>
-
-</log4j:configuration>
More information about the jboss-cvs-commits
mailing list