djencks 2004/05/24 12:10:35
Modified: modules/connector/src/java/org/apache/geronimo/connector/outbound
ConnectionInfo.java
ConnectionTrackingInterceptor.java
GenericConnectionManager.java
MCFConnectionInterceptor.java
SinglePoolConnectionInterceptor.java
SinglePoolMatchAllConnectionInterceptor.java
SubjectInterceptor.java
ThreadLocalCachingConnectionInterceptor.java
TransactionCachingInterceptor.java
modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig
XATransactions.java
modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking
ConnectionTracker.java
ConnectionTrackingCoordinator.java
modules/connector/src/test/org/apache/geronimo/connector/outbound
ConnectionManagerTest.java
ConnectionManagerTestUtils.java
ConnectionTrackingInterceptorTest.java
ManagedConnectionFactoryWrapperTest.java
SubjectInterceptorTest.java
TransactionCachingInterceptorTest.java
TransactionEnlistingInterceptorTest.java
modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking
ConnectionTrackingCoordinatorTest.java
DefaultComponentInterceptor.java
Log:
Refactor and implement support for res-sharing-scope and res-auth choices
Revision Changes Path
1.6 +20 -0
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionInfo.java
Index: ConnectionInfo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionInfo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConnectionInfo.java 22 Apr 2004 17:03:28 -0000 1.5
+++ ConnectionInfo.java 24 May 2004 19:10:34 -0000 1.6
@@ -29,6 +29,8 @@
private ManagedConnectionInfo mci;
private Object connection;
+ private boolean unshareable;
+ private boolean applicationManagedSecurity;
private Exception trace;
public ConnectionInfo() {
@@ -71,6 +73,22 @@
this.connection = connection;
}
+ public boolean isUnshareable() {
+ return unshareable;
+ }
+
+ public void setUnshareable(boolean unshareable) {
+ this.unshareable = unshareable;
+ }
+
+ public boolean isApplicationManagedSecurity() {
+ return applicationManagedSecurity;
+ }
+
+ public void setApplicationManagedSecurity(boolean
applicationManagedSecurity) {
+ this.applicationManagedSecurity = applicationManagedSecurity;
+ }
+
public boolean equals(Object obj) {
if (obj == this) {
return true;
@@ -95,5 +113,7 @@
public Exception getTrace() {
return trace;
}
+
+
} // ConnectionInfo
1.9 +11 -39
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java
Index: ConnectionTrackingInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ConnectionTrackingInterceptor.java 22 Apr 2004 17:03:28 -0000
1.8
+++ ConnectionTrackingInterceptor.java 24 May 2004 19:10:34 -0000
1.9
@@ -24,12 +24,8 @@
import javax.resource.ResourceException;
import javax.resource.spi.DissociatableManagedConnection;
import javax.resource.spi.ManagedConnection;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginException;
import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
-import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.security.bridge.RealmBridge;
/**
* ConnectionTrackingInterceptor.java handles communication with the
@@ -46,21 +42,19 @@
private final ConnectionInterceptor next;
private final String key;
private final ConnectionTracker connectionTracker;
- private final RealmBridge realmBridge;
public ConnectionTrackingInterceptor(
final ConnectionInterceptor next,
final String key,
- final ConnectionTracker connectionTracker,
- final RealmBridge realmBridge) {
+ final ConnectionTracker connectionTracker
+ ) {
this.next = next;
this.key = key;
this.connectionTracker = connectionTracker;
- this.realmBridge = realmBridge;
}
/**
- * called by: ProxyConnectionManager.allocateConnection,
ProxyConnectionManager.associateConnection, and enter.
+ * called by: GenericConnectionManager.allocateConnection,
GenericConnectionManager.associateConnection, and enter.
* in: connectionInfo is non-null, and has non-null
ManagedConnectionInfo with non-null managedConnectionfactory.
* connection handle may or may not be null.
* out: connectionInfo has non-null connection handle, non null
ManagedConnectionInfo with non-null ManagedConnection and
GeronimoConnectionEventListener.
@@ -69,6 +63,7 @@
* @throws ResourceException
*/
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
+ connectionTracker.setEnvironment(connectionInfo, key);
next.getConnection(connectionInfo);
connectionTracker.handleObtained(this, connectionInfo);
}
@@ -88,32 +83,8 @@
next.returnConnection(connectionInfo, connectionReturnAction);
}
- public void enter(Collection connectionInfos, Set unshareable)
+ public void enter(Collection connectionInfos)
throws ResourceException {
- if (unshareable.contains(key)) {
- //should probably check to see if subjects are consistent,
- //and if not raise an exception. Also need to check if
- //the spec says anything about this.
- //this is wrong
- }
- if (realmBridge == null) {
- return; //this is wrong: need a "bouncing" subjectInterceptor
- }
-
- Subject currentSubject = null;
- try {
- currentSubject =
realmBridge.mapSubject(ContextManager.getCurrentCaller());
- } catch (SecurityException e) {
- throw new ResourceException("Can not obtain Subject for login",
e);
- } catch (LoginException e) {
- throw new ResourceException("Can not obtain Subject for login",
e);
- }
- //TODO figure out which is right here
- //assert currentSubject != null;
- if (currentSubject == null) {
- //check to see if mci.getSubject() is null?
- return;
- }
for (Iterator i = connectionInfos.iterator(); i.hasNext();) {
ConnectionInfo connectionInfo = (ConnectionInfo) i.next();
next.getConnection(connectionInfo);
@@ -121,13 +92,14 @@
}
- public void exit(Collection connectionInfos, Set unshareableResources)
+ public void exit(Collection connectionInfos)
throws ResourceException {
- if (unshareableResources.contains(key)) {
- return;
- }
for (Iterator i = connectionInfos.iterator(); i.hasNext();) {
ConnectionInfo connectionInfo = (ConnectionInfo) i.next();
+ if (connectionInfo.isUnshareable()) {
+ //if one is, they all are
+ return;
+ }
ManagedConnectionInfo managedConnectionInfo =
connectionInfo.getManagedConnectionInfo();
ManagedConnection managedConnection =
managedConnectionInfo.getManagedConnection();
if (managedConnection instanceof DissociatableManagedConnection
1.2 +9 -7
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java
Index: GenericConnectionManager.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GenericConnectionManager.java 6 May 2004 03:58:22 -0000 1.1
+++ GenericConnectionManager.java 24 May 2004 19:10:34 -0000 1.2
@@ -87,21 +87,23 @@
stack = transactionSupport.addXAResourceInsertionInterceptor(stack);
stack = pooling.addPoolingInterceptors(stack);
//experimental threadlocal caching
- if (transactionSupport instanceof XATransactions &&
((XATransactions)transactionSupport).isUseThreadCaching()) {
- stack = new ThreadLocalCachingConnectionInterceptor(stack,
false);
- }
+ //moved to XATransactions
+// if (transactionSupport instanceof XATransactions &&
((XATransactions)transactionSupport).isUseThreadCaching()) {
+// stack = new ThreadLocalCachingConnectionInterceptor(stack,
false);
+// }
+ stack = transactionSupport.addTransactionInterceptors(stack);
+
if (realmBridge != null) {
stack = new SubjectInterceptor(stack, realmBridge);
}
- stack = transactionSupport.addTransactionInterceptors(stack);
stack = new ConnectionHandleInterceptor(stack);
if (connectionTracker != null) {
stack = new ConnectionTrackingInterceptor(
stack,
getName(),
- connectionTracker,
- realmBridge);
+ connectionTracker
+ );
}
tail.setStack(stack);
this.stack = stack;
1.6 +4 -1
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java
Index: MCFConnectionInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MCFConnectionInterceptor.java 6 May 2004 03:58:22 -0000 1.5
+++ MCFConnectionInterceptor.java 24 May 2004 19:10:34 -0000 1.6
@@ -35,6 +35,9 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
ManagedConnectionInfo mci =
connectionInfo.getManagedConnectionInfo();
+ if (mci.getManagedConnection() != null) {
+ return;
+ }
ManagedConnection mc =
mci.getManagedConnectionFactory().createManagedConnection(
mci.getSubject(),
1.6 +4 -1
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java
Index: SinglePoolConnectionInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SinglePoolConnectionInterceptor.java 6 May 2004 03:58:22 -0000
1.5
+++ SinglePoolConnectionInterceptor.java 24 May 2004 19:10:34 -0000
1.6
@@ -66,6 +66,9 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
ManagedConnectionInfo mci =
connectionInfo.getManagedConnectionInfo();
+ if (mci.getManagedConnection() != null) {
+ return;
+ }
try {
if (permits.attempt(blockingTimeout)) {
ManagedConnectionInfo newMCI = null;
1.2 +4 -1
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java
Index: SinglePoolMatchAllConnectionInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SinglePoolMatchAllConnectionInterceptor.java 6 May 2004 03:58:22
-0000 1.1
+++ SinglePoolMatchAllConnectionInterceptor.java 24 May 2004 19:10:34
-0000 1.2
@@ -67,6 +67,9 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
ManagedConnectionInfo mci =
connectionInfo.getManagedConnectionInfo();
+ if (mci.getManagedConnection() != null) {
+ return;
+ }
ManagedConnectionFactory managedConnectionFactory =
mci.getManagedConnectionFactory();
try {
if (permits.attempt(blockingTimeout)) {
1.5 +39 -27
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SubjectInterceptor.java
Index: SubjectInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/SubjectInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SubjectInterceptor.java 10 Mar 2004 09:58:32 -0000 1.4
+++ SubjectInterceptor.java 24 May 2004 19:10:34 -0000 1.5
@@ -18,6 +18,7 @@
package org.apache.geronimo.connector.outbound;
import javax.resource.ResourceException;
+import javax.resource.spi.ApplicationServerInternalException;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
@@ -46,40 +47,51 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
Subject currentSubject = null;
- try {
- currentSubject =
realmBridge.mapSubject(ContextManager.getCurrentCaller());
- } catch (SecurityException e) {
- throw new ResourceException("Can not obtain Subject for login",
e);
- } catch (LoginException e) {
- throw new ResourceException("Can not obtain Subject for login",
e);
+ if (!connectionInfo.isApplicationManagedSecurity()) {
+ try {
+ currentSubject =
realmBridge.mapSubject(ContextManager.getCurrentCaller());
+ } catch (SecurityException e) {
+ throw new ResourceException("Can not obtain Subject for
login", e);
+ } catch (LoginException e) {
+ throw new ResourceException("Can not obtain Subject for
login", e);
+ }
+ assert currentSubject != null;
}
- assert currentSubject != null;
ManagedConnectionInfo originalManagedConnectionInfo =
connectionInfo.getManagedConnectionInfo();
//No existing managed connection, get an appropriate one and return.
if (originalManagedConnectionInfo.getManagedConnection() == null) {
originalManagedConnectionInfo.setSubject(currentSubject);
next.getConnection(connectionInfo);
- } else if
(!currentSubject.equals(originalManagedConnectionInfo.getSubject())) {
- //existing managed connection, wrong subject: must re-associate.
- //make a ConnectionInfo to process removing the handle from the
old mc
- ConnectionInfo returningConnectionInfo = new ConnectionInfo();
-
returningConnectionInfo.setManagedConnectionInfo(originalManagedConnectionInfo);
- //This should decrement handle count, but not close the handle,
when returnConnection is called
- //I'm not sure how to test/assure this.
-
returningConnectionInfo.setConnectionHandle(connectionInfo.getConnectionHandle());
-
- //make a new ManagedConnectionInfo for the mc we will ask for
- ManagedConnectionInfo newManagedConnectionInfo =
- new ManagedConnectionInfo(
-
originalManagedConnectionInfo.getManagedConnectionFactory(),
-
originalManagedConnectionInfo.getConnectionRequestInfo());
- newManagedConnectionInfo.setSubject(currentSubject);
-
connectionInfo.setManagedConnectionInfo(newManagedConnectionInfo);
- next.getConnection(connectionInfo);
- //process the removal of the handle from the previous mc
- returnConnection(returningConnectionInfo,
ConnectionReturnAction.RETURN_HANDLE);
+ } else {
+ Subject oldSubject = originalManagedConnectionInfo.getSubject();
+ if (currentSubject == null ? oldSubject != null :
!currentSubject.equals(oldSubject)) {
+ if (connectionInfo.isUnshareable()) {
+ throw new
ApplicationServerInternalException("Unshareable resource is attempting to
change security context: expected request under: " + oldSubject + ", received
request under: " + currentSubject);
+ } else {
+ //existing managed connection, wrong subject: must
re-associate.
+ //make a ConnectionInfo to process removing the handle
from the old mc
+ ConnectionInfo returningConnectionInfo = new
ConnectionInfo();
+
returningConnectionInfo.setManagedConnectionInfo(originalManagedConnectionInfo);
+ //This should decrement handle count, but not close the
handle, when returnConnection is called
+ //I'm not sure how to test/assure this.
+
returningConnectionInfo.setConnectionHandle(connectionInfo.getConnectionHandle());
+
+ //make a new ManagedConnectionInfo for the mc we will
ask for
+ ManagedConnectionInfo newManagedConnectionInfo =
+ new ManagedConnectionInfo(
+
originalManagedConnectionInfo.getManagedConnectionFactory(),
+
originalManagedConnectionInfo.getConnectionRequestInfo());
+ newManagedConnectionInfo.setSubject(currentSubject);
+
connectionInfo.setManagedConnectionInfo(newManagedConnectionInfo);
+ next.getConnection(connectionInfo);
+ //process the removal of the handle from the previous mc
+ returnConnection(returningConnectionInfo,
ConnectionReturnAction.RETURN_HANDLE);
+ }
+ }
}
//otherwise, the current ManagedConnection matches the security
info, we keep it.
+ //set up the tx context
+ next.getConnection(connectionInfo);
}
public void returnConnection(
1.2 +6 -2
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java
Index: ThreadLocalCachingConnectionInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ThreadLocalCachingConnectionInterceptor.java 22 Apr 2004 17:02:16
-0000 1.1
+++ ThreadLocalCachingConnectionInterceptor.java 24 May 2004 19:10:34
-0000 1.2
@@ -41,6 +41,10 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
+ if (connectionInfo.isUnshareable()) {
+ next.getConnection(connectionInfo);
+ return;
+ }
ManagedConnectionInfo managedConnectionInfo =
(ManagedConnectionInfo) connections.get();
if (managedConnectionInfo != null) {
if (matchConnections) {
@@ -68,7 +72,7 @@
}
public void returnConnection(ConnectionInfo connectionInfo,
ConnectionReturnAction connectionReturnAction) {
- if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
+ if (connectionReturnAction == ConnectionReturnAction.DESTROY ||
connectionInfo.isUnshareable()) {
next.returnConnection(connectionInfo, connectionReturnAction);
}
}
1.7 +65 -9
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
Index: TransactionCachingInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TransactionCachingInterceptor.java 6 May 2004 03:58:22 -0000
1.6
+++ TransactionCachingInterceptor.java 24 May 2004 19:10:34 -0000
1.7
@@ -17,9 +17,13 @@
package org.apache.geronimo.connector.outbound;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
import javax.resource.ResourceException;
-import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
import org.apache.geronimo.transaction.ConnectionReleaser;
import org.apache.geronimo.transaction.TransactionContext;
@@ -53,13 +57,25 @@
public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
TransactionContext transactionContext =
TransactionContext.getContext();
- ManagedConnectionInfo managedConnectionInfo =
(ManagedConnectionInfo)transactionContext.getManagedConnectionInfo(this);
- if (managedConnectionInfo != null) {
- connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
- return;
+ ManagedConnectionInfos managedConnectionInfos =
(ManagedConnectionInfos) transactionContext.getManagedConnectionInfo(this);
+ if (managedConnectionInfos == null) {
+ managedConnectionInfos = new ManagedConnectionInfos();
+ transactionContext.setManagedConnectionInfo(this,
managedConnectionInfos);
+ }
+ if (connectionInfo.isUnshareable()) {
+ if
(!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo()))
{
+ next.getConnection(connectionInfo);
+
managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo());
+ }
} else {
- next.getConnection(connectionInfo);
- transactionContext.setManagedConnectionInfo(this,
connectionInfo.getManagedConnectionInfo());
+ ManagedConnectionInfo managedConnectionInfo =
managedConnectionInfos.getShared();
+ if (managedConnectionInfo != null) {
+
connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
+ return;
+ } else {
+ next.getConnection(connectionInfo);
+
managedConnectionInfos.setShared(connectionInfo.getManagedConnectionInfo());
+ }
}
}
@@ -80,10 +96,50 @@
next.returnConnection(connectionInfo, connectionReturnAction);
}
- public void afterCompletion(Object managedConnectionInfo) {
+ public void afterCompletion(Object stuff) {
+ ManagedConnectionInfos managedConnectionInfos =
(ManagedConnectionInfos)stuff;
+ ManagedConnectionInfo sharedMCI = managedConnectionInfos.getShared();
+ if (sharedMCI != null) {
+ returnHandle(sharedMCI);
+ }
+ for (Iterator iterator =
managedConnectionInfos.getUnshared().iterator(); iterator.hasNext();) {
+ ManagedConnectionInfo managedConnectionInfo =
(ManagedConnectionInfo) iterator.next();
+ returnHandle(managedConnectionInfo);
+ }
+ }
+
+ private void returnHandle(ManagedConnectionInfo managedConnectionInfo) {
ConnectionInfo connectionInfo = new ConnectionInfo();
-
connectionInfo.setManagedConnectionInfo((ManagedConnectionInfo)managedConnectionInfo);
+ connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
returnConnection(connectionInfo,
ConnectionReturnAction.RETURN_HANDLE);
+ }
+
+ static class ManagedConnectionInfos {
+ private ManagedConnectionInfo shared;
+ private Set unshared = Collections.EMPTY_SET;
+
+ public ManagedConnectionInfo getShared() {
+ return shared;
+ }
+
+ public void setShared(ManagedConnectionInfo shared) {
+ this.shared = shared;
+ }
+
+ public Set getUnshared() {
+ return unshared;
+ }
+
+ public void addUnshared(ManagedConnectionInfo unsharedMCI) {
+ if (this.unshared == Collections.EMPTY_SET) {
+ this.unshared = new HashSet();
+ }
+ this.unshared.add(unsharedMCI);
+ }
+
+ public boolean containsUnshared(ManagedConnectionInfo unsharedMCI) {
+ return this.unshared.contains(unsharedMCI);
+ }
}
}
1.2 +7 -1
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/XATransactions.java
Index: XATransactions.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/XATransactions.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XATransactions.java 6 May 2004 03:58:22 -0000 1.1
+++ XATransactions.java 24 May 2004 19:10:34 -0000 1.2
@@ -21,6 +21,7 @@
import org.apache.geronimo.connector.outbound.XAResourceInsertionInterceptor;
import
org.apache.geronimo.connector.outbound.TransactionEnlistingInterceptor;
import org.apache.geronimo.connector.outbound.TransactionCachingInterceptor;
+import
org.apache.geronimo.connector.outbound.ThreadLocalCachingConnectionInterceptor;
/**
*
@@ -58,6 +59,11 @@
}
public ConnectionInterceptor
addTransactionInterceptors(ConnectionInterceptor stack) {
+ //experimental thread local caching
+ if (isUseThreadCaching()) {
+ //useMatching should be configurable
+ stack = new ThreadLocalCachingConnectionInterceptor(stack,
false);
+ }
stack = new TransactionEnlistingInterceptor(stack);
if (isUseTransactionCaching()) {
stack = new TransactionCachingInterceptor(stack);
1.5 +3 -1
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTracker.java
Index: ConnectionTracker.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTracker.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConnectionTracker.java 6 Apr 2004 00:21:21 -0000 1.4
+++ ConnectionTracker.java 24 May 2004 19:10:34 -0000 1.5
@@ -36,4 +36,6 @@
ConnectionTrackingInterceptor connectionTrackingInterceptor,
ConnectionInfo connectionInfo);
+ void setEnvironment(ConnectionInfo connectionInfo, String key);
+
}
1.8 +22 -11
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
Index: ConnectionTrackingCoordinator.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ConnectionTrackingCoordinator.java 7 Apr 2004 06:53:26 -0000
1.7
+++ ConnectionTrackingCoordinator.java 24 May 2004 19:10:34 -0000
1.8
@@ -53,51 +53,53 @@
private final ThreadLocal currentInstanceContexts = new ThreadLocal();
private final ThreadLocal currentUnshareableResources = new
ThreadLocal();
+ private final ThreadLocal currentApplicationManagedSecurityResources =
new ThreadLocal();
- public TrackedConnectionAssociator.ConnectorContextInfo
enter(InstanceContext newInstanceContext, Set newUnshareableResources)
+ public TrackedConnectionAssociator.ConnectorContextInfo
enter(InstanceContext newInstanceContext, Set newUnshareableResources, Set
applicationManagedSecurityResources)
throws ResourceException {
InstanceContext oldInstanceContext = (InstanceContext)
currentInstanceContexts.get();
- Set oldUnshareableResources = (Set)currentUnshareableResources.get();
- notifyConnections(newInstanceContext, newUnshareableResources);
+ Set oldUnshareableResources = (Set)
currentUnshareableResources.get();
+ Set oldApplicationManagedSecurityResources = (Set)
currentApplicationManagedSecurityResources.get();
currentInstanceContexts.set(newInstanceContext);
currentUnshareableResources.set(newUnshareableResources);
- return new
TrackedConnectionAssociator.ConnectorContextInfo(oldInstanceContext,
oldUnshareableResources);
+
currentApplicationManagedSecurityResources.set(applicationManagedSecurityResources);
+ notifyConnections(newInstanceContext);
+ return new
TrackedConnectionAssociator.ConnectorContextInfo(oldInstanceContext,
oldUnshareableResources, oldApplicationManagedSecurityResources);
}
- private void notifyConnections(InstanceContext oldInstanceContext, Set
newUnshareableResources) throws ResourceException {
+ private void notifyConnections(InstanceContext oldInstanceContext)
throws ResourceException {
Map connectionManagerToManagedConnectionInfoMap =
oldInstanceContext.getConnectionManagerMap();
for (Iterator i =
connectionManagerToManagedConnectionInfoMap.entrySet().iterator();
i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
ConnectionTrackingInterceptor mcci =
(ConnectionTrackingInterceptor) entry.getKey();
Set connections = (Set) entry.getValue();
- mcci.enter(connections, newUnshareableResources);
+ mcci.enter(connections);
}
}
public void newTransaction() throws ResourceException {
InstanceContext oldInstanceContext = (InstanceContext)
currentInstanceContexts.get();
- Set oldUnshareableResources = (Set)currentUnshareableResources.get();
- notifyConnections(oldInstanceContext, oldUnshareableResources);
+ notifyConnections(oldInstanceContext);
}
public void exit(ConnectorContextInfo reenteringConnectorContext)
throws ResourceException {
InstanceContext oldInstanceContext = (InstanceContext)
currentInstanceContexts.get();
- Set oldUnshareableResources = (Set)currentUnshareableResources.get();
Map resources = oldInstanceContext.getConnectionManagerMap();
for (Iterator i = resources.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
ConnectionTrackingInterceptor mcci =
(ConnectionTrackingInterceptor) entry.getKey();
Set connections = (Set) entry.getValue();
- mcci.exit(connections, oldUnshareableResources);
+ mcci.exit(connections);
if (connections.isEmpty()) {
i.remove();
}
}
currentInstanceContexts.set(reenteringConnectorContext.getInstanceContext());
currentUnshareableResources.set(reenteringConnectorContext.getUnshareableResources());
+
currentApplicationManagedSecurityResources.set(reenteringConnectorContext.getApplicationManagedSecurityResources());
}
@@ -128,6 +130,15 @@
Set infos = (Set) resources.get(connectionTrackingInterceptor);
//It's not at all clear that an equal ci will be supplied here
infos.remove(connectionInfo);
+ }
+
+ public void setEnvironment(ConnectionInfo connectionInfo, String key) {
+ Set unshareableResources = (Set) currentUnshareableResources.get();
+ boolean unshareable = unshareableResources.contains(key);
+ connectionInfo.setUnshareable(unshareable);
+ Set applicationManagedSecurityResources = (Set)
currentApplicationManagedSecurityResources.get();
+ boolean applicationManagedSecurity =
applicationManagedSecurityResources.contains(key);
+
connectionInfo.setApplicationManagedSecurity(applicationManagedSecurity);
}
static {
1.10 +46 -22
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java
Index: ConnectionManagerTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ConnectionManagerTest.java 22 Apr 2004 17:06:30 -0000 1.9
+++ ConnectionManagerTest.java 24 May 2004 19:10:35 -0000 1.10
@@ -17,32 +17,14 @@
package org.apache.geronimo.connector.outbound;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.security.auth.Subject;
-import javax.transaction.TransactionManager;
-
-import org.apache.geronimo.connector.mock.MockConnection;
-import org.apache.geronimo.connector.mock.MockConnectionFactory;
-import org.apache.geronimo.connector.mock.MockManagedConnection;
-import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
import org.apache.geronimo.connector.mock.MockXAResource;
-import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
-import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
-import
org.apache.geronimo.connector.outbound.connectiontracking.DefaultComponentInterceptor;
+import org.apache.geronimo.connector.mock.MockConnection;
import
org.apache.geronimo.connector.outbound.connectiontracking.DefaultInterceptor;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.security.bridge.RealmBridge;
-import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
-import org.apache.geronimo.transaction.InstanceContext;
-import org.apache.geronimo.transaction.TransactionContext;
import org.apache.geronimo.transaction.ContainerTransactionContext;
+import org.apache.geronimo.transaction.TransactionContext;
import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
import org.apache.geronimo.transaction.UserTransactionImpl;
-
-import junit.framework.TestCase;
+import org.apache.geronimo.transaction.InstanceContext;
/**
*
@@ -90,6 +72,20 @@
}
public void testUserTransactionEnlistingExistingConnections() throws
Throwable {
+ mockComponent = new DefaultInterceptor() {
+ public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
+ MockConnection mockConnection = (MockConnection)
connectionFactory.getConnection();
+ mockManagedConnection =
mockConnection.getManagedConnection();
+ userTransaction.begin();
+ MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
+ assertEquals("XAResource should know one xid", 1,
mockXAResource.getKnownXids().size());
+ assertNull("Should not be committed",
mockXAResource.getCommitted());
+ userTransaction.commit();
+ assertNotNull("Should be committed",
mockXAResource.getCommitted());
+ mockConnection.close();
+ return null;
+ }
+ };
TransactionContext.setContext(new UnspecifiedTransactionContext());
userTransaction = new UserTransactionImpl();
userTransaction.setUp(transactionManager,
connectionTrackingCoordinator);
@@ -100,5 +96,33 @@
assertNotNull("Should be committed", mockXAResource.getCommitted());
}
+ public void testUnshareableConnections() throws Throwable {
+ unshareableResources.add(name);
+ mockComponent = new DefaultInterceptor() {
+ public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
+ MockConnection mockConnection1 = (MockConnection)
connectionFactory.getConnection();
+ mockManagedConnection =
mockConnection1.getManagedConnection();
+ MockConnection mockConnection2 = (MockConnection)
connectionFactory.getConnection();
+ //the 2 cx are for the same RM, so tm will call commit only
one one (the first)
+ //mockManagedConnection =
mockConnection2.getManagedConnection();
+ assertNotNull("Expected non-null managedconnection 1",
mockConnection1.getManagedConnection());
+ assertNotNull("Expected non-null managedconnection 2",
mockConnection2.getManagedConnection());
+ assertTrue("Expected different managed connections for each
unshared handle", mockConnection1.getManagedConnection() !=
mockConnection2.getManagedConnection());
+
+ mockConnection1.close();
+ mockConnection2.close();
+ return null;
+ }
+ };
+ ContainerTransactionContext transactionContext = new
ContainerTransactionContext(transactionManager);
+ TransactionContext.setContext(transactionContext);
+ transactionContext.begin();
+ defaultComponentInterceptor.invoke(defaultComponentContext);
+ MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
+ assertEquals("XAResource should know one xid", 1,
mockXAResource.getKnownXids().size());
+ assertNull("Should not be committed", mockXAResource.getCommitted());
+ transactionManager.commit();
+ assertNotNull("Should be committed", mockXAResource.getCommitted());
+ }
}
1.9 +16 -16
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java
Index: ConnectionManagerTestUtils.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ConnectionManagerTestUtils.java 6 May 2004 03:59:56 -0000 1.8
+++ ConnectionManagerTestUtils.java 24 May 2004 19:10:35 -0000 1.9
@@ -72,12 +72,22 @@
protected DefaultComponentContext defaultComponentContext;
protected DefaultComponentInterceptor defaultComponentInterceptor;
protected Set unshareableResources = new HashSet();
+ protected Set applicationManagedSecurityResources = new HashSet();
protected MockManagedConnection mockManagedConnection;
protected Subject subject;
protected UserTransactionImpl userTransaction;
protected TransactionSupport transactionSupport = new
XATransactions(useTransactionCaching, useThreadCaching);
protected PoolingSupport poolingSupport = new
PartitionedPool(useConnectionRequestInfo, useSubject, maxSize, blockingTimeout,
matchOne, matchAll, selectOneNoMatch);
+ protected DefaultInterceptor mockComponent = new DefaultInterceptor() {
+ public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
+ MockConnection mockConnection = (MockConnection)
connectionFactory.getConnection();
+ mockManagedConnection = mockConnection.getManagedConnection();
+ mockConnection.close();
+ return null;
+ }
+ };
+
protected void setUp() throws Exception {
connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
transactionManager = new TransactionManagerImpl();
@@ -93,7 +103,7 @@
connectionManagerDeployment.doStart();
connectionFactory = (MockConnectionFactory)
connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory);
defaultComponentContext = new DefaultComponentContext();
- defaultComponentInterceptor = new DefaultComponentInterceptor(this,
connectionTrackingCoordinator, unshareableResources);
+ defaultComponentInterceptor = new DefaultComponentInterceptor(this,
connectionTrackingCoordinator, unshareableResources,
applicationManagedSecurityResources);
}
protected void tearDown() throws Exception {
@@ -105,22 +115,12 @@
defaultComponentContext = null;
}
- public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
- MockConnection mockConnection = (MockConnection)
connectionFactory.getConnection();
- mockManagedConnection = mockConnection.getManagedConnection();
- if (userTransaction != null) {
- userTransaction.begin();
- MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
- assertEquals("XAResource should know one xid", 1,
mockXAResource.getKnownXids().size());
- assertNull("Should not be committed",
mockXAResource.getCommitted());
- userTransaction.commit();
- assertNotNull("Should be committed",
mockXAResource.getCommitted());
- }
- mockConnection.close();
- return null;
- }
public Subject mapSubject(Subject sourceSubject) {
return subject;
+ }
+
+ public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
+ return mockComponent.invoke(newInstanceContext);
}
}
1.7 +9 -20
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptorTest.java
Index: ConnectionTrackingInterceptorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptorTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConnectionTrackingInterceptorTest.java 20 Apr 2004 18:29:39 -0000
1.6
+++ ConnectionTrackingInterceptorTest.java 24 May 2004 19:10:35 -0000
1.7
@@ -19,11 +19,10 @@
import java.util.Collection;
import java.util.HashSet;
-import java.util.Set;
+
import javax.resource.ResourceException;
import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
-import org.apache.geronimo.transaction.TransactionContext;
/**
* TODO test unshareable resources.
@@ -46,11 +45,10 @@
private ConnectionInfo releasedTrackedConnectionInfo;
private Collection connectionInfos;
- private Set unshareable;
protected void setUp() throws Exception {
super.setUp();
- connectionTrackingInterceptor = new
ConnectionTrackingInterceptor(this, key, this, this);
+ connectionTrackingInterceptor = new
ConnectionTrackingInterceptor(this, key, this);
}
protected void tearDown() throws Exception {
@@ -79,14 +77,6 @@
}
-
- public void testEnterWithNullSubject() throws Exception {
- getConnectionAndReenter();
- //expect no re-association
- assertTrue("Expected no connection asked for",
obtainedConnectionInfo == null);
- assertTrue("Expected no connection returned", returnedConnectionInfo
== null);
- }
-
private void getConnectionAndReenter() throws ResourceException {
ConnectionInfo connectionInfo = makeConnectionInfo();
connectionTrackingInterceptor.getConnection(connectionInfo);
@@ -94,8 +84,7 @@
obtainedConnectionInfo = null;
connectionInfos = new HashSet();
connectionInfos.add(connectionInfo);
- unshareable = new HashSet();
- connectionTrackingInterceptor.enter(connectionInfos, unshareable);
+ connectionTrackingInterceptor.enter(connectionInfos);
}
public void testEnterWithSameSubject() throws Exception {
@@ -109,7 +98,7 @@
public void testEnterWithChangedSubject() throws Exception {
testEnterWithSameSubject();
makeSubject("bar");
- connectionTrackingInterceptor.enter(connectionInfos, unshareable);
+ connectionTrackingInterceptor.enter(connectionInfos);
//expect re-association
assertTrue("Expected connection asked for", obtainedConnectionInfo
!= null);
//connection is returned by SubjectInterceptor
@@ -119,7 +108,7 @@
public void testExitWithNonDissociatableConnection() throws Exception {
managedConnection = new TestPlainManagedConnection();
testEnterWithSameSubject();
- connectionTrackingInterceptor.exit(connectionInfos, unshareable);
+ connectionTrackingInterceptor.exit(connectionInfos);
assertTrue("Expected no connection returned", returnedConnectionInfo
== null);
assertEquals("Expected one info in connectionInfos",
connectionInfos.size(), 1);
}
@@ -128,7 +117,7 @@
managedConnection = new TestDissociatableManagedConnection();
testEnterWithSameSubject();
assertEquals("Expected one info in connectionInfos", 1,
connectionInfos.size());
- connectionTrackingInterceptor.exit(connectionInfos, unshareable);
+ connectionTrackingInterceptor.exit(connectionInfos);
assertTrue("Expected connection returned", returnedConnectionInfo !=
null);
assertEquals("Expected no infos in connectionInfos", 0,
connectionInfos.size());
}
@@ -148,8 +137,8 @@
releasedTrackedConnectionInfo = connectionInfo;
}
- public TransactionContext getTransactionContext() {
- return null;
+ public void setEnvironment(ConnectionInfo connectionInfo, String key) {
+ //unsharable = false, app security = false;
}
//ConnectionInterceptor interface
1.3 +33 -4
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapperTest.java
Index: ManagedConnectionFactoryWrapperTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapperTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ManagedConnectionFactoryWrapperTest.java 6 May 2004 03:59:56 -0000
1.2
+++ ManagedConnectionFactoryWrapperTest.java 24 May 2004 19:10:35 -0000
1.3
@@ -35,9 +35,11 @@
import org.apache.geronimo.connector.mock.MockConnection;
import org.apache.geronimo.connector.mock.MockConnectionFactory;
import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
-import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
-import
org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
+import
org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
+import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.naming.deployment.RefAdapter;
@@ -181,7 +183,7 @@
protected void setUp() throws Exception {
kernel = new Kernel(KERNEL_NAME, "test.domain");
kernel.boot();
- GBeanMBean ctc = new
GBeanMBean(ConnectionTrackingCoordinator.getGBeanInfo());
+ GBeanMBean ctc = new
GBeanMBean(MockConnectionTrackingCoordinator.getGBeanInfo());
ctcName =
ObjectName.getInstance("test:role=ConnectionTrackingCoordinator");
kernel.loadGBean(ctcName, ctc);
GBeanMBean cmf = new
GBeanMBean(GenericConnectionManager.getGBeanInfo());
@@ -216,5 +218,32 @@
protected void tearDown() throws Exception {
kernel.stopGBean(selfName);
kernel.shutdown();
+ }
+
+ public static class MockConnectionTrackingCoordinator implements
ConnectionTracker {
+ public void handleObtained(
+ ConnectionTrackingInterceptor connectionTrackingInterceptor,
+ ConnectionInfo connectionInfo) {
+ }
+
+ public void handleReleased(
+ ConnectionTrackingInterceptor connectionTrackingInterceptor,
+ ConnectionInfo connectionInfo) {
+ }
+
+ public void setEnvironment(ConnectionInfo connectionInfo, String
key) {
+ }
+
+ static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoFactory infoFactory = new
GBeanInfoFactory(MockConnectionTrackingCoordinator.class);
+ infoFactory.addInterface(ConnectionTracker.class);
+ GBEAN_INFO = infoFactory.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
}
}
1.5 +32 -2
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/SubjectInterceptorTest.java
Index: SubjectInterceptorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/SubjectInterceptorTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SubjectInterceptorTest.java 20 Apr 2004 18:29:39 -0000 1.4
+++ SubjectInterceptorTest.java 24 May 2004 19:10:35 -0000 1.5
@@ -18,6 +18,7 @@
package org.apache.geronimo.connector.outbound;
import javax.security.auth.Subject;
+import javax.resource.ResourceException;
/**
*
@@ -63,7 +64,7 @@
//reset our test indicator
obtainedConnectionInfo = null;
subjectInterceptor.getConnection(connectionInfo);
- assertTrue("Expected connection asked for", obtainedConnectionInfo
== null);
+ assertTrue("Expected connection asked for", obtainedConnectionInfo
== connectionInfo);
assertTrue("Expected no connection returned", returnedConnectionInfo
== null);
}
@@ -80,6 +81,35 @@
assertTrue("Expected connection asked for", obtainedConnectionInfo
!= null);
//connection is returned by SubjectInterceptor
assertTrue("Expected connection returned", returnedConnectionInfo !=
null);
+ }
+
+ public void testApplicationManagedSecurity() throws Exception {
+ makeSubject("foo");
+ ConnectionInfo connectionInfo = makeConnectionInfo();
+ connectionInfo.setApplicationManagedSecurity(true);
+ ManagedConnectionInfo managedConnectionInfo =
connectionInfo.getManagedConnectionInfo();
+ managedConnection = new TestPlainManagedConnection();
+ subjectInterceptor.getConnection(connectionInfo);
+ //expect no subject set on mci
+ assertTrue("Expected call to next with same connectionInfo",
connectionInfo == obtainedConnectionInfo);
+ assertTrue("Expected the same managedConnectionInfo",
managedConnectionInfo == connectionInfo.getManagedConnectionInfo());
+ assertTrue("Expected no subject to be inserted", null ==
managedConnectionInfo.getSubject());
+ }
+
+ public void testUnshareablePreventsReAssociation() throws Exception {
+ makeSubject("foo");
+ ConnectionInfo connectionInfo = makeConnectionInfo();
+ connectionInfo.setUnshareable(true);
+ managedConnection = new TestPlainManagedConnection();
+ subjectInterceptor.getConnection(connectionInfo);
+ //reset our test indicator
+ obtainedConnectionInfo = null;
+ makeSubject("bar");
+ try {
+ subjectInterceptor.getConnection(connectionInfo);
+ fail("Reassociating should fail on an unshareable connection");
+ } catch (ResourceException e) {
+ }
}
}
1.8 +50 -7
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
Index: TransactionCachingInterceptorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TransactionCachingInterceptorTest.java 6 May 2004 03:59:56 -0000
1.7
+++ TransactionCachingInterceptorTest.java 24 May 2004 19:10:35 -0000
1.8
@@ -20,7 +20,6 @@
import javax.resource.ResourceException;
import javax.transaction.TransactionManager;
-import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
import org.apache.geronimo.transaction.ContainerTransactionContext;
import org.apache.geronimo.transaction.TransactionContext;
import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
@@ -32,8 +31,7 @@
* @version $Revision$ $Date$
*
* */
-public class TransactionCachingInterceptorTest extends
ConnectionInterceptorTestUtils
- implements ConnectionTracker {
+public class TransactionCachingInterceptorTest extends
ConnectionInterceptorTestUtils {
private TransactionManager transactionManager;
private TransactionCachingInterceptor transactionCachingInterceptor;
@@ -60,7 +58,7 @@
assertTrue("Expected nothing returned yet", returnedConnectionInfo
== null);
assertTrue("Expected the same ManagedConnectionInfo in the
TransactionContext as was returned",
connectionInfo1.getManagedConnectionInfo()
- ==
transactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
+ == getSharedManagedConnectionInfo(transactionContext));
obtainedConnectionInfo = null;
ConnectionInfo connectionInfo2 = new ConnectionInfo();
transactionCachingInterceptor.getConnection(connectionInfo2);
@@ -69,7 +67,7 @@
assertTrue("Expected the same ManagedConnectionInfo in both
ConnectionInfos",
connectionInfo1.getManagedConnectionInfo() ==
connectionInfo2.getManagedConnectionInfo());
assertTrue("Expected the same ManagedConnectionInfo in the
TransactionContext as was returned",
- connectionInfo1.getManagedConnectionInfo() ==
transactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
+ connectionInfo1.getManagedConnectionInfo() ==
getSharedManagedConnectionInfo(transactionContext));
//commit, see if connection returned.
//we didn't create any handles, so the "ManagedConnection" should be
returned.
assertTrue("Expected TransactionContext to report active",
transactionContext.isActive());
@@ -79,6 +77,51 @@
}
+ public void testGetUnshareableConnectionsInTransaction() throws
Exception {
+ ContainerTransactionContext transactionContext = new
ContainerTransactionContext(transactionManager);
+ TransactionContext.setContext(transactionContext);
+ transactionContext.begin();
+ ConnectionInfo connectionInfo1 = makeConnectionInfo();
+ connectionInfo1.setUnshareable(true);
+ transactionCachingInterceptor.getConnection(connectionInfo1);
+ assertTrue("Expected to get an initial connection",
obtainedConnectionInfo != null);
+ assertTrue("Expected nothing returned yet", returnedConnectionInfo
== null);
+ assertTrue("Expected different ManagedConnectionInfo in the
TransactionContext as was returned",
+ connectionInfo1.getManagedConnectionInfo()
+ != getSharedManagedConnectionInfo(transactionContext));
+ //2nd is shared, modelling a call into another ejb
+ obtainedConnectionInfo = null;
+ ConnectionInfo connectionInfo2 = makeConnectionInfo();
+ transactionCachingInterceptor.getConnection(connectionInfo2);
+ assertTrue("Expected to get a second connection",
obtainedConnectionInfo != null);
+ assertTrue("Expected nothing returned yet", returnedConnectionInfo
== null);
+ assertTrue("Expected the same ManagedConnectionInfo in both
ConnectionInfos",
+ connectionInfo1.getManagedConnectionInfo() !=
connectionInfo2.getManagedConnectionInfo());
+ assertTrue("Expected the same ManagedConnectionInfo in the
TransactionContext as was returned",
+ connectionInfo2.getManagedConnectionInfo() ==
getSharedManagedConnectionInfo(transactionContext));
+ //3rd is unshared, modelling a call into a third ejb
+ obtainedConnectionInfo = null;
+ ConnectionInfo connectionInfo3 = makeConnectionInfo();
+ connectionInfo3.setUnshareable(true);
+ transactionCachingInterceptor.getConnection(connectionInfo3);
+ assertTrue("Expected to get a third connection",
obtainedConnectionInfo != null);
+ assertTrue("Expected nothing returned yet", returnedConnectionInfo
== null);
+ assertTrue("Expected different ManagedConnectionInfo in both
unshared ConnectionInfos",
+ connectionInfo1.getManagedConnectionInfo() !=
connectionInfo3.getManagedConnectionInfo());
+ assertTrue("Expected different ManagedConnectionInfo in the
TransactionContext as was returned",
+ connectionInfo3.getManagedConnectionInfo() !=
getSharedManagedConnectionInfo(transactionContext));
+ //commit, see if connection returned.
+ //we didn't create any handles, so the "ManagedConnection" should be
returned.
+ assertTrue("Expected TransactionContext to report active",
transactionContext.isActive());
+ transactionContext.commit();
+ assertTrue("Expected connection to be returned",
returnedConnectionInfo != null);
+ assertTrue("Expected TransactionContext to report inactive",
!transactionContext.isActive());
+ }
+
+ private ManagedConnectionInfo
getSharedManagedConnectionInfo(ContainerTransactionContext transactionContext) {
+ return
((TransactionCachingInterceptor.ManagedConnectionInfos)transactionContext.getManagedConnectionInfo(transactionCachingInterceptor)).getShared();
+ }
+
public void testGetConnectionOutsideTransaction() throws Exception {
TransactionContext.setContext(new UnspecifiedTransactionContext());
ConnectionInfo connectionInfo1 = makeConnectionInfo();
@@ -128,7 +171,7 @@
assertTrue("Expected different ManagedConnectionInfo in each
ConnectionInfos",
connectionInfo1.getManagedConnectionInfo() !=
connectionInfo2.getManagedConnectionInfo());
assertTrue("Expected the same ManagedConnectionInfo in the
TransactionContext as was returned",
- connectionInfo2.getManagedConnectionInfo() ==
transactionContext2.getManagedConnectionInfo(transactionCachingInterceptor));
+ connectionInfo2.getManagedConnectionInfo() ==
getSharedManagedConnectionInfo(transactionContext2));
//commit 2nd transaction, see if connection returned.
//we didn't create any handles, so the "ManagedConnection" should be
returned.
assertTrue("Expected TransactionContext to report active",
transactionContext2.isActive());
1.6 +21 -2
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java
Index: TransactionEnlistingInterceptorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransactionEnlistingInterceptorTest.java 20 Apr 2004 18:29:39 -0000
1.5
+++ TransactionEnlistingInterceptorTest.java 24 May 2004 19:10:35 -0000
1.6
@@ -68,12 +68,31 @@
assertTrue("Expected not committed", !committed);
}
- public void testTransaction() throws Exception {
+ public void testTransactionShareableConnection() throws Exception {
TransactionManager transactionManager = new TransactionManagerImpl();
ContainerTransactionContext transactionContext = new
ContainerTransactionContext(transactionManager);
TransactionContext.setContext(transactionContext);
transactionContext.begin();
ConnectionInfo connectionInfo = makeConnectionInfo();
+ transactionEnlistingInterceptor.getConnection(connectionInfo);
+ assertTrue("Expected started", started);
+ assertTrue("Expected not ended", !ended);
+ started = false;
+ transactionEnlistingInterceptor.returnConnection(connectionInfo,
ConnectionReturnAction.RETURN_HANDLE);
+ assertTrue("Expected not started", !started);
+ assertTrue("Expected ended", ended);
+ assertTrue("Expected returned", returned);
+ transactionManager.commit();
+ assertTrue("Expected committed", committed);
+ }
+
+ public void testTransactionUnshareableConnection() throws Exception {
+ TransactionManager transactionManager = new TransactionManagerImpl();
+ ContainerTransactionContext transactionContext = new
ContainerTransactionContext(transactionManager);
+ TransactionContext.setContext(transactionContext);
+ transactionContext.begin();
+ ConnectionInfo connectionInfo = makeConnectionInfo();
+ connectionInfo.setUnshareable(true);
transactionEnlistingInterceptor.getConnection(connectionInfo);
assertTrue("Expected started", started);
assertTrue("Expected not ended", !ended);
1.6 +20 -10
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java
Index: ConnectionTrackingCoordinatorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConnectionTrackingCoordinatorTest.java 6 Apr 2004 00:21:20 -0000
1.5
+++ ConnectionTrackingCoordinatorTest.java 24 May 2004 19:10:35 -0000
1.6
@@ -22,13 +22,15 @@
import java.util.Set;
import javax.security.auth.Subject;
+import javax.resource.ResourceException;
import junit.framework.TestCase;
import org.apache.geronimo.connector.outbound.ConnectionInfo;
import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
import org.apache.geronimo.connector.outbound.ManagedConnectionInfo;
+import org.apache.geronimo.connector.outbound.ConnectionInterceptor;
+import org.apache.geronimo.connector.outbound.ConnectionReturnAction;
import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
-import org.apache.geronimo.security.bridge.RealmBridge;
import org.apache.geronimo.transaction.TrackedConnectionAssociator;
/**
@@ -38,7 +40,7 @@
*
* */
public class ConnectionTrackingCoordinatorTest extends TestCase
- implements RealmBridge {
+ implements ConnectionInterceptor {
private static final String name1 = "foo";
private static final String name2 = "bar";
@@ -47,12 +49,14 @@
private ConnectionTrackingInterceptor key2;
private Subject subject = null;
private Set unshareableResources;
+ private Set applicationManagedSecurityResources;
protected void setUp() throws Exception {
connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
- key1 = new ConnectionTrackingInterceptor(null, name1,
connectionTrackingCoordinator, this);
- key2 = new ConnectionTrackingInterceptor(null, name2,
connectionTrackingCoordinator, this);
+ key1 = new ConnectionTrackingInterceptor(this, name1,
connectionTrackingCoordinator);
+ key2 = new ConnectionTrackingInterceptor(this, name2,
connectionTrackingCoordinator);
unshareableResources = new HashSet();
+ applicationManagedSecurityResources = new HashSet();
}
protected void tearDown() throws Exception {
@@ -63,7 +67,7 @@
public void testSimpleComponentContextLifecyle() throws Exception {
DefaultComponentContext componentContext = new
DefaultComponentContext();
- TrackedConnectionAssociator.ConnectorContextInfo connectorContext =
connectionTrackingCoordinator.enter(componentContext, unshareableResources);
+ TrackedConnectionAssociator.ConnectorContextInfo connectorContext =
connectionTrackingCoordinator.enter(componentContext, unshareableResources,
applicationManagedSecurityResources);
assertNull("Expected old component context to be null",
connectorContext.getInstanceContext());
//give the context a ConnectionInfo
ManagedConnectionInfo managedConnectionInfo = new
ManagedConnectionInfo(null, null);
@@ -76,7 +80,7 @@
assertTrue("Expected to get supplied ConnectionInfo from infos",
connectionInfo == infos.iterator().next());
//Enter again, and close the handle
- connectorContext =
connectionTrackingCoordinator.enter(componentContext, unshareableResources);
+ connectorContext =
connectionTrackingCoordinator.enter(componentContext, unshareableResources,
applicationManagedSecurityResources);
assertNull("Expected old component context to be null",
connectorContext.getInstanceContext());
connectionTrackingCoordinator.handleReleased(key1, connectionInfo);
connectionTrackingCoordinator.exit(connectorContext);
@@ -87,7 +91,7 @@
public void testNestedComponentContextLifecyle() throws Exception {
DefaultComponentContext componentContext1 = new
DefaultComponentContext();
- TrackedConnectionAssociator.ConnectorContextInfo
oldConnectorContext1 = connectionTrackingCoordinator.enter(componentContext1,
unshareableResources);
+ TrackedConnectionAssociator.ConnectorContextInfo
oldConnectorContext1 = connectionTrackingCoordinator.enter(componentContext1,
unshareableResources, applicationManagedSecurityResources);
assertNull("Expected old component context to be null",
oldConnectorContext1.getInstanceContext());
//give the context a ConnectionInfo
ManagedConnectionInfo managedConnectionInfo1 = new
ManagedConnectionInfo(null, null);
@@ -96,7 +100,7 @@
//Simulate calling another component
DefaultComponentContext componentContext2 = new
DefaultComponentContext();
- TrackedConnectionAssociator.ConnectorContextInfo
oldConnectorContext2 = connectionTrackingCoordinator.enter(componentContext2,
unshareableResources);
+ TrackedConnectionAssociator.ConnectorContextInfo
oldConnectorContext2 = connectionTrackingCoordinator.enter(componentContext2,
unshareableResources, applicationManagedSecurityResources);
assertTrue("Expected returned component context to be
componentContext1", oldConnectorContext2.getInstanceContext() ==
componentContext1);
//give the context a ConnectionInfo
ManagedConnectionInfo managedConnectionInfo2 = new
ManagedConnectionInfo(null, null);
@@ -119,7 +123,7 @@
assertEquals("Expected no connection for key2", null,
connectionManagerMap1.get(key2));
//Enter again, and close the handle
- oldConnectorContext1 =
connectionTrackingCoordinator.enter(componentContext1, unshareableResources);
+ oldConnectorContext1 =
connectionTrackingCoordinator.enter(componentContext1, unshareableResources,
applicationManagedSecurityResources);
assertNull("Expected old component context to be null",
oldConnectorContext1.getInstanceContext());
connectionTrackingCoordinator.handleReleased(key1, connectionInfo1);
connectionTrackingCoordinator.exit(oldConnectorContext1);
@@ -130,5 +134,11 @@
public Subject mapSubject(Subject sourceSubject) {
return subject;
+ }
+
+ public void getConnection(ConnectionInfo connectionInfo) throws
ResourceException {
+ }
+
+ public void returnConnection(ConnectionInfo connectionInfo,
ConnectionReturnAction connectionReturnAction) {
}
}
1.2 +5 -3
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/DefaultComponentInterceptor.java
Index: DefaultComponentInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/DefaultComponentInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultComponentInterceptor.java 6 Apr 2004 00:21:20 -0000 1.1
+++ DefaultComponentInterceptor.java 24 May 2004 19:10:35 -0000 1.2
@@ -35,20 +35,22 @@
private final DefaultInterceptor next;
private final TrackedConnectionAssociator cachedConnectionAssociator;
private final Set unshareableResources;
+ private final Set applicationManagedSecurityResources;
public DefaultComponentInterceptor(DefaultInterceptor next,
TrackedConnectionAssociator cachedConnectionManager,
- Set unshareableResources) {
+ Set unshareableResources, Set
applicationManagedSecurityResources) {
this.next = next;
this.cachedConnectionAssociator = cachedConnectionManager;
this.unshareableResources = unshareableResources;
+ this.applicationManagedSecurityResources =
applicationManagedSecurityResources;
}
public Object invoke(InstanceContext newInstanceContext) throws
Throwable {
if (TransactionContext.getContext() == null) {
TransactionContext.setContext(new
UnspecifiedTransactionContext());
}
- TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext
= cachedConnectionAssociator.enter(newInstanceContext, unshareableResources);
+ TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext
= cachedConnectionAssociator.enter(newInstanceContext, unshareableResources,
applicationManagedSecurityResources);
try {
return next.invoke(newInstanceContext);
} finally {