djencks 2003/12/23 09:34:35
Modified: modules/core/src/test/org/apache/geronimo/connector/outbound
ConnectionTrackingInterceptorTest.java
modules/core/src/java/org/apache/geronimo/connector/outbound
ConnectionManagerDeployment.java
GeronimoConnectionEventListener.java
modules/core/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl
DefaultComponentInterceptor.java
DefaultInterceptor.java
Added: modules/core/src/test/org/apache/geronimo/connector/mock
MockCCILocalTransaction.java MockConnection.java
MockConnectionFactory.java
MockConnectionRequestInfo.java
MockManagedConnection.java
MockManagedConnectionFactory.java
MockResourceAdapter.java
MockSPILocalTransaction.java MockXAResource.java
modules/core/src/test/org/apache/geronimo/connector/outbound
ConnectionManagerTest.java
Log:
Mock adapter for testing the whole outbound framework at once
Revision Changes Path
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockCCILocalTransaction.java
Index: MockCCILocalTransaction.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.resource.cci.LocalTransaction;
import javax.resource.ResourceException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockCCILocalTransaction extends MockSPILocalTransaction
implements LocalTransaction {
private final MockConnection mockConnection;
public MockCCILocalTransaction(MockConnection mockConnection) {
this.mockConnection = mockConnection;
}
public void begin() throws ResourceException {
super.begin();
mockConnection.getManagedConnection().localTransactionStartedEvent(mockConnection);
}
public void commit() throws ResourceException {
super.commit();
mockConnection.getManagedConnection().localTransactionCommittedEvent(mockConnection);
}
public void rollback() throws ResourceException {
super.rollback();
mockConnection.getManagedConnection().localTransactionRolledBackEvent(mockConnection);
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockConnection.java
Index: MockConnection.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.security.auth.Subject;
import javax.resource.cci.Connection;
import javax.resource.cci.Interaction;
import javax.resource.cci.LocalTransaction;
import javax.resource.cci.ConnectionMetaData;
import javax.resource.cci.ResultSetInfo;
import javax.resource.ResourceException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockConnection implements Connection {
private MockManagedConnection managedConnection;
private Subject subject;
private MockConnectionRequestInfo connectionRequestInfo;
private boolean closed;
public MockConnection(MockManagedConnection managedConnection, Subject
subject, MockConnectionRequestInfo connectionRequestInfo) {
this.managedConnection = managedConnection;
this.subject = subject;
this.connectionRequestInfo = connectionRequestInfo;
}
public Interaction createInteraction() throws ResourceException {
return null;
}
public LocalTransaction getLocalTransaction() throws ResourceException {
return new MockCCILocalTransaction(this);
}
public ConnectionMetaData getMetaData() throws ResourceException {
return null;
}
public ResultSetInfo getResultSetInfo() throws ResourceException {
return null;
}
public void close() throws ResourceException {
closed = true;
managedConnection.removeHandle(this);
managedConnection.closedEvent(this);
}
public void error() {
managedConnection.errorEvent(this);
}
public MockManagedConnection getManagedConnection() {
return managedConnection;
}
public Subject getSubject() {
return subject;
}
public MockConnectionRequestInfo getConnectionRequestInfo() {
return connectionRequestInfo;
}
public boolean isClosed() {
return closed;
}
public void reassociate(MockManagedConnection mockManagedConnection) {
assert managedConnection != null;
managedConnection.removeHandle(this);
managedConnection = mockManagedConnection;
subject = mockManagedConnection.getSubject();
connectionRequestInfo =
mockManagedConnection.getConnectionRequestInfo();
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockConnectionFactory.java
Index: MockConnectionFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.resource.spi.ConnectionManager;
import javax.resource.cci.ConnectionFactory;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionSpec;
import javax.resource.cci.RecordFactory;
import javax.resource.cci.ResourceAdapterMetaData;
import javax.resource.ResourceException;
import javax.naming.Reference;
import javax.naming.NamingException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockConnectionFactory implements ConnectionFactory {
private ConnectionManager connectionManager;
private MockManagedConnectionFactory managedConnectionFactory;
private Reference reference;
public MockConnectionFactory(MockManagedConnectionFactory
managedConnectionFactory, ConnectionManager connectionManager) {
this.managedConnectionFactory = managedConnectionFactory;
this.connectionManager = connectionManager;
}
public Connection getConnection() throws ResourceException {
return getConnection(null);
}
public Connection getConnection(ConnectionSpec properties) throws
ResourceException {
return
(MockConnection)connectionManager.allocateConnection(managedConnectionFactory,
(MockConnectionRequestInfo)properties);
}
public RecordFactory getRecordFactory() throws ResourceException {
return null;
}
public ResourceAdapterMetaData getMetaData() throws ResourceException {
return null;
}
public void setReference(Reference reference) {
this.reference = reference;
}
public Reference getReference() throws NamingException {
return reference;
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockConnectionRequestInfo.java
Index: MockConnectionRequestInfo.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.cci.ConnectionSpec;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockConnectionRequestInfo implements ConnectionRequestInfo,
ConnectionSpec {
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockManagedConnection.java
Index: MockManagedConnection.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import java.io.PrintWriter;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.resource.spi.ConnectionEvent;
import javax.resource.ResourceException;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockManagedConnection implements ManagedConnection {
private final MockManagedConnectionFactory managedConnectionFactory;
private final MockXAResource mockXAResource;
private Subject subject;
private MockConnectionRequestInfo connectionRequestInfo;
private final Set connections = new HashSet();
private final List connectionEventListeners =
Collections.synchronizedList(new ArrayList());
private boolean destroyed;
private PrintWriter logWriter;
public MockManagedConnection(MockManagedConnectionFactory
managedConnectionFactory, Subject subject, MockConnectionRequestInfo
connectionRequestInfo) {
this.managedConnectionFactory = managedConnectionFactory;
mockXAResource = new MockXAResource(this);
this.subject = subject;
this.connectionRequestInfo = connectionRequestInfo;
}
public Object getConnection(Subject subject, ConnectionRequestInfo
connectionRequestInfo) throws ResourceException {
checkSecurityConsistency(subject, connectionRequestInfo);
MockConnection mockConnection = new MockConnection(this, subject,
(MockConnectionRequestInfo)connectionRequestInfo);
connections.add(mockConnection);
return mockConnection;
}
private void checkSecurityConsistency(Subject subject,
ConnectionRequestInfo connectionRequestInfo) {
if (!managedConnectionFactory.isReauthentication()) {
assert subject == null? this.subject == null:
subject.equals(this.subject);
assert connectionRequestInfo == null? this.connectionRequestInfo
== null: connectionRequestInfo.equals(this.connectionRequestInfo);
}
}
public void destroy() throws ResourceException {
destroyed = true;
cleanup();
}
public void cleanup() throws ResourceException {
for (Iterator iterator = new HashSet(connections).iterator();
iterator.hasNext();) {
MockConnection mockConnection = (MockConnection) iterator.next();
mockConnection.close();
}
assert connections.isEmpty();
}
public void associateConnection(Object connection) throws
ResourceException {
assert connection != null;
assert connection.getClass() == MockConnection.class;
MockConnection mockConnection = (MockConnection)connection;
checkSecurityConsistency(mockConnection.getSubject(),
mockConnection.getConnectionRequestInfo());
mockConnection.reassociate(this);
connections.add(mockConnection);
}
public void addConnectionEventListener(ConnectionEventListener listener) {
connectionEventListeners.add(listener);
}
public void removeConnectionEventListener(ConnectionEventListener
listener) {
connectionEventListeners.remove(listener);
}
public XAResource getXAResource() throws ResourceException {
return mockXAResource;
}
public LocalTransaction getLocalTransaction() throws ResourceException {
return new MockSPILocalTransaction();
}
public ManagedConnectionMetaData getMetaData() throws ResourceException {
return null;
}
public void setLogWriter(PrintWriter logWriter) throws ResourceException {
this.logWriter = logWriter;
}
public PrintWriter getLogWriter() throws ResourceException {
return logWriter;
}
public Subject getSubject() {
return subject;
}
public MockConnectionRequestInfo getConnectionRequestInfo() {
return connectionRequestInfo;
}
public void removeHandle(MockConnection mockConnection) {
connections.remove(mockConnection);
}
public MockManagedConnectionFactory getManagedConnectionFactory() {
return managedConnectionFactory;
}
public Set getConnections() {
return connections;
}
public List getConnectionEventListeners() {
return connectionEventListeners;
}
public boolean isDestroyed() {
return destroyed;
}
public void closedEvent(MockConnection mockConnection) {
ConnectionEvent connectionEvent = new ConnectionEvent(this,
ConnectionEvent.CONNECTION_CLOSED);
connectionEvent.setConnectionHandle(mockConnection);
for (Iterator iterator = new
ArrayList(connectionEventListeners).iterator(); iterator.hasNext();) {
ConnectionEventListener connectionEventListener =
(ConnectionEventListener) iterator.next();
connectionEventListener.connectionClosed(connectionEvent);
}
}
public void errorEvent(MockConnection mockConnection) {
ConnectionEvent connectionEvent = new ConnectionEvent(this,
ConnectionEvent.CONNECTION_ERROR_OCCURRED);
connectionEvent.setConnectionHandle(mockConnection);
for (Iterator iterator = new
ArrayList(connectionEventListeners).iterator(); iterator.hasNext();) {
ConnectionEventListener connectionEventListener =
(ConnectionEventListener) iterator.next();
connectionEventListener.connectionErrorOccurred(connectionEvent);
}
}
public void localTransactionStartedEvent(MockConnection mockConnection) {
ConnectionEvent connectionEvent = new ConnectionEvent(this,
ConnectionEvent.LOCAL_TRANSACTION_STARTED);
connectionEvent.setConnectionHandle(mockConnection);
for (Iterator iterator = new
ArrayList(connectionEventListeners).iterator(); iterator.hasNext();) {
ConnectionEventListener connectionEventListener =
(ConnectionEventListener) iterator.next();
connectionEventListener.localTransactionStarted(connectionEvent);
}
}
public void localTransactionCommittedEvent(MockConnection mockConnection)
{
ConnectionEvent connectionEvent = new ConnectionEvent(this,
ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
connectionEvent.setConnectionHandle(mockConnection);
for (Iterator iterator = new
ArrayList(connectionEventListeners).iterator(); iterator.hasNext();) {
ConnectionEventListener connectionEventListener =
(ConnectionEventListener) iterator.next();
connectionEventListener.localTransactionCommitted(connectionEvent);
}
}
public void localTransactionRolledBackEvent(MockConnection
mockConnection) {
ConnectionEvent connectionEvent = new ConnectionEvent(this,
ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
connectionEvent.setConnectionHandle(mockConnection);
for (Iterator iterator = new
ArrayList(connectionEventListeners).iterator(); iterator.hasNext();) {
ConnectionEventListener connectionEventListener =
(ConnectionEventListener) iterator.next();
connectionEventListener.localTransactionRolledback(connectionEvent);
}
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockManagedConnectionFactory.java
Index: MockManagedConnectionFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.io.PrintWriter;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.ResourceException;
import javax.security.auth.Subject;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockManagedConnectionFactory implements ManagedConnectionFactory
{
private MockResourceAdapter resourceAdapter;
private PrintWriter logWriter;
private final Set managedConnections = new HashSet();
private boolean reauthentication;
public void setResourceAdapter(ResourceAdapter resourceAdapter) throws
ResourceException {
assert this.resourceAdapter == null: "Setting ResourceAdapter twice";
assert resourceAdapter != null: "trying to set resourceAdapter to
null";
this.resourceAdapter = (MockResourceAdapter)resourceAdapter;
}
public ResourceAdapter getResourceAdapter() {
return resourceAdapter;
}
public Object createConnectionFactory(ConnectionManager
connectionManager) throws ResourceException {
return new MockConnectionFactory(this, connectionManager);
}
public Object createConnectionFactory() throws ResourceException {
return null;
}
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
MockManagedConnection managedConnection = new
MockManagedConnection(this, subject,
(MockConnectionRequestInfo)connectionRequestInfo);
managedConnections.add(managedConnection);
return managedConnection;
}
public ManagedConnection matchManagedConnections(Set connectionSet,
Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
if (reauthentication) {
for (Iterator iterator = connectionSet.iterator();
iterator.hasNext();) {
ManagedConnection managedConnection = (ManagedConnection)
iterator.next();
if (managedConnections.contains(managedConnection)) {
return managedConnection;
}
}
} else {
for (Iterator iterator = connectionSet.iterator();
iterator.hasNext();) {
ManagedConnection managedConnection = (ManagedConnection)
iterator.next();
if (managedConnections.contains(managedConnection)) {
MockManagedConnection mockManagedConnection =
(MockManagedConnection)managedConnection;
if ((subject == null? mockManagedConnection.getSubject()
== null: subject.equals(mockManagedConnection.getSubject())
&& (cxRequestInfo == null?
mockManagedConnection.getConnectionRequestInfo() == null:
cxRequestInfo.equals(mockManagedConnection.getConnectionRequestInfo())))) {
return mockManagedConnection;
}
}
}
}
return null;
}
public void setLogWriter(PrintWriter logWriter) throws ResourceException {
this.logWriter = logWriter;
}
public PrintWriter getLogWriter() throws ResourceException {
return logWriter;
}
public boolean isReauthentication() {
return reauthentication;
}
public void setReauthentication(boolean reauthentication) {
this.reauthentication = reauthentication;
}
public Set getManagedConnections() {
return managedConnections;
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockResourceAdapter.java
Index: MockResourceAdapter.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.BootstrapContext;
import javax.resource.spi.ResourceAdapterInternalException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.endpoint.MessageEndpointFactory;
import javax.resource.ResourceException;
import javax.transaction.xa.XAResource;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockResourceAdapter implements ResourceAdapter {
private BootstrapContext bootstrapContext;
public void start(BootstrapContext bootstrapContext) throws
ResourceAdapterInternalException {
assert this.bootstrapContext == null : "Attempting to restart adapter
without stoppping";
assert bootstrapContext != null: "Null bootstrap context";
this.bootstrapContext = bootstrapContext;
}
public void stop() {
bootstrapContext = null;
}
public void endpointActivation(MessageEndpointFactory endpointFactory,
ActivationSpec spec) throws ResourceException {
}
public void endpointDeactivation(MessageEndpointFactory endpointFactory,
ActivationSpec spec) {
}
public XAResource[] getXAResources(ActivationSpec[] specs) throws
ResourceException {
return new XAResource[0];
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockSPILocalTransaction.java
Index: MockSPILocalTransaction.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import javax.resource.spi.LocalTransaction;
import javax.resource.ResourceException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockSPILocalTransaction implements LocalTransaction {
private boolean inTransaction;
private boolean begun;
private boolean committed;
private boolean rolledBack;
public MockSPILocalTransaction() {
}
public void begin() throws ResourceException {
assert !inTransaction;
inTransaction = true;
begun = true;
}
public void commit() throws ResourceException {
assert inTransaction;
inTransaction = false;
committed = true;
}
public void rollback() throws ResourceException {
assert inTransaction;
inTransaction = false;
rolledBack = true;
}
public void reset() {
inTransaction = false;
begun = false;
committed = false;
rolledBack = false;
}
public boolean isInTransaction() {
return inTransaction;
}
public boolean isBegun() {
return begun;
}
public boolean isCommitted() {
return committed;
}
public boolean isRolledBack() {
return rolledBack;
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/mock/MockXAResource.java
Index: MockXAResource.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.mock;
import java.util.Set;
import java.util.HashSet;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import javax.transaction.xa.XAException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:34 $
*
* */
public class MockXAResource implements XAResource {
private final MockManagedConnection mockManagedConnection;
private int prepareResult = XAResource.XA_OK;
private Xid currentXid;
private int transactionTimeoutSeconds;
private final Set knownXids = new HashSet();
private final Set successfulXids = new HashSet();
private Xid prepared;
private Xid committed;
private Xid rolledback;
public MockXAResource(MockManagedConnection mockManagedConnection) {
this.mockManagedConnection = mockManagedConnection;
}
public void commit(Xid xid, boolean onePhase) throws XAException {
assert xid != null;
assert onePhase || prepared == xid;
committed = xid;
}
//TODO TMFAIL? TMENDRSCAN?
public void end(Xid xid, int flags) throws XAException {
assert xid != null;
assert knownXids.contains(xid);
assert flags == XAResource.TMSUSPEND || flags == XAResource.TMSUCCESS;
if (flags == XAResource.TMSUSPEND) {
assert currentXid == xid;
currentXid = null;
}
if (flags == XAResource.TMSUCCESS) {
successfulXids.add(xid);
if (xid.equals(currentXid)) {
currentXid = null;
}
}
}
public void forget(Xid xid) throws XAException {
//todo
}
public int getTransactionTimeout() throws XAException {
return transactionTimeoutSeconds;
}
public boolean isSameRM(XAResource xaResource) throws XAException {
if (!(xaResource instanceof MockXAResource)) {
return false;
}
MockXAResource other = (MockXAResource)xaResource;
return other.mockManagedConnection.getManagedConnectionFactory() ==
mockManagedConnection.getManagedConnectionFactory();
}
public int prepare(Xid xid) throws XAException {
assert xid != null;
prepared = xid;
return prepareResult;
}
public Xid[] recover(int flag) throws XAException {
//todo
return new Xid[0];
}
public void rollback(Xid xid) throws XAException {
assert xid != null;
rolledback = xid;
}
public boolean setTransactionTimeout(int seconds) throws XAException {
transactionTimeoutSeconds = seconds;
return true;
}
//TODO TMSTARTRSCAN?
public void start(Xid xid, int flags) throws XAException {
assert currentXid == null :"Expected no xid when start called";
assert xid != null: "Expected xid supplied to start";
assert flags == XAResource.TMNOFLAGS || flags == XAResource.TMJOIN ||
flags == XAResource.TMRESUME;
if (flags == XAResource.TMNOFLAGS || flags == XAResource.TMJOIN) {
assert !knownXids.contains(xid);
knownXids.add(xid);
}
if (flags == XAResource.TMRESUME) {
assert knownXids.contains(xid);
}
currentXid = xid;
}
public void setPrepareResult(int prepareResult) {
this.prepareResult = prepareResult;
}
public Xid getCurrentXid() {
return currentXid;
}
public Set getKnownXids() {
return knownXids;
}
public Set getSuccessfulXids() {
return successfulXids;
}
public Xid getPrepared() {
return prepared;
}
public Xid getCommitted() {
return committed;
}
public Xid getRolledback() {
return rolledback;
}
public void clear() {
currentXid = null;
prepared = null;
rolledback = null;
committed = null;
knownXids.clear();
successfulXids.clear();
prepareResult = XAResource.XA_OK;
}
}
1.4 +2 -1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptorTest.java
Index: ConnectionTrackingInterceptorTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptorTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConnectionTrackingInterceptorTest.java 13 Dec 2003 23:33:54 -0000
1.3
+++ ConnectionTrackingInterceptorTest.java 23 Dec 2003 17:34:35 -0000
1.4
@@ -198,6 +198,7 @@
managedConnectionInfo.setConnectionEventListener(new
GeronimoConnectionEventListener(null, managedConnectionInfo));
managedConnectionInfo.setSubject(subject);
managedConnectionInfo.setManagedConnection(managedConnection);
+ connectionInfo.setConnectionHandle(new Object());
managedConnectionInfo.addConnectionHandle(connectionInfo);
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java
Index: ConnectionManagerTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector.outbound;
import java.util.Set;
import java.util.HashSet;
import javax.transaction.TransactionManager;
import javax.transaction.Transaction;
import javax.transaction.Status;
import javax.resource.spi.ConnectionManager;
import javax.security.auth.Subject;
import junit.framework.TestCase;
import
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultInterceptor;
import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentInterceptor;
import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
import org.apache.geronimo.connector.mock.MockConnectionFactory;
import org.apache.geronimo.connector.mock.MockConnection;
import org.apache.geronimo.connector.mock.MockXAResource;
import org.apache.geronimo.connector.mock.MockManagedConnection;
import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/12/23 17:34:35 $
*
* */
public class ConnectionManagerTest extends TestCase implements
DefaultInterceptor, SecurityDomain {
protected boolean useConnectionRequestInfo = false;
protected boolean useSubject = true;
protected boolean useTransactionCaching = true;
protected boolean useLocalTransactions = false;
protected boolean useTransactions = true;
protected int maxSize = 5;
protected int blockingTimeout = 100;
protected String jndiName = "testCF";
//dependencies
protected SecurityDomain securityDomain = this;
protected ConnectionTrackingCoordinator connectionTrackingCoordinator;
protected TransactionManager transactionManager;
protected ConnectionManagerDeployment connectionManagerDeployment;
protected MockConnectionFactory connectionFactory;
protected MockManagedConnectionFactory mockManagedConnectionFactory;
protected DefaultComponentContext defaultComponentContext;
protected DefaultComponentInterceptor defaultComponentInterceptor;
protected Set unshareableResources = new HashSet();
protected MockManagedConnection mockManagedConnection;
protected Subject subject;
protected void setUp() throws Exception {
connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
transactionManager = new TransactionManagerImpl();
mockManagedConnectionFactory = new MockManagedConnectionFactory();
subject = new Subject();
connectionManagerDeployment = new
ConnectionManagerDeployment(useConnectionRequestInfo,
useSubject,
useTransactionCaching,
useLocalTransactions,
useTransactions,
maxSize,
blockingTimeout,
securityDomain,
jndiName,
connectionTrackingCoordinator);
connectionFactory =
(MockConnectionFactory)connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory);
defaultComponentContext = new DefaultComponentContext();
defaultComponentInterceptor = new DefaultComponentInterceptor(this,
connectionTrackingCoordinator, unshareableResources, transactionManager);
}
protected void tearDown() throws Exception {
connectionTrackingCoordinator = null;
transactionManager = null;
mockManagedConnectionFactory = null;
connectionManagerDeployment = null;
connectionFactory = null;
defaultComponentContext = null;
}
public void testSingleTransactionCall() throws Throwable {
transactionManager.begin();
defaultComponentInterceptor.invoke(defaultComponentContext);
MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
assertTrue("XAResource should know one xid",
mockXAResource.getKnownXids().size() == 1);
assertTrue("Should not be committed", mockXAResource.getCommitted()
== null);
transactionManager.commit();
assertTrue("Should be committed", mockXAResource.getCommitted() !=
null);
}
public void testNoTransactionCall() throws Throwable {
defaultComponentInterceptor.invoke(defaultComponentContext);
MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
assertTrue("XAResource should know 0 xid",
mockXAResource.getKnownXids().size() == 0);
assertTrue("Should not be committed", mockXAResource.getCommitted()
== null);
}
public void testOneTransactionTwoCalls() throws Throwable {
transactionManager.begin();
defaultComponentInterceptor.invoke(defaultComponentContext);
MockXAResource mockXAResource = (MockXAResource)
mockManagedConnection.getXAResource();
assertTrue("XAResource should know one xid",
mockXAResource.getKnownXids().size() == 1);
assertTrue("Should not be committed", mockXAResource.getCommitted()
== null);
defaultComponentInterceptor.invoke(defaultComponentContext);
assertTrue("Expected same XAResource", mockXAResource ==
mockManagedConnection.getXAResource());
assertTrue("XAResource should know one xid",
mockXAResource.getKnownXids().size() == 1);
assertTrue("Should not be committed", mockXAResource.getCommitted()
== null);
transactionManager.commit();
assertTrue("Should be committed", mockXAResource.getCommitted() !=
null);
}
public Object invoke(ConnectorComponentContext
newConnectorComponentContext) throws Throwable {
MockConnection mockConnection =
(MockConnection)connectionFactory.getConnection();
mockManagedConnection = mockConnection.getManagedConnection();
mockConnection.close();
return null;
}
public Subject getSubject() {
return subject;
}
}
1.6 +46 -23
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java
Index: ConnectionManagerDeployment.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConnectionManagerDeployment.java 13 Dec 2003 23:33:53 -0000 1.5
+++ ConnectionManagerDeployment.java 23 Dec 2003 17:34:35 -0000 1.6
@@ -101,27 +101,44 @@
private boolean useTransactions;
private int maxSize;
private int blockingTimeout;
-
-
- //dependencies
-
- /**
- * (proxy for) the security domain object
- */
- private SecurityDomain securityDomain;
-
/**
* Identifying string used by unshareable resource detection
*/
private String jndiName;
+ //dependencies
+ private SecurityDomain securityDomain;
+ private ConnectionTracker connectionTracker;
+ //GeronimoMBeanTarget support.
private GeronimoMBeanContext context;
+ //default constructor for normal use as mbean
+ public ConnectionManagerDeployment() {
+ }
- /**
- * Actual CachedConnectionManager we relate to.
- */
- private ConnectionTracker connectionTracker;
+ //constructor primarily for testing. Connection manager/connection
factory will not be serializable.
+ public ConnectionManagerDeployment(boolean useConnectionRequestInfo,
+ boolean useSubject,
+ boolean useTransactionCaching,
+ boolean useLocalTransactions,
+ boolean useTransactions,
+ int maxSize,
+ int blockingTimeout,
+ SecurityDomain securityDomain,
+ String jndiName,
+ ConnectionTracker connectionTracker) {
+ this.useConnectionRequestInfo = useConnectionRequestInfo;
+ this.useLocalTransactions = useLocalTransactions;
+ this.useSubject = useSubject;
+ this.useTransactionCaching = useTransactionCaching;
+ this.useTransactions = useTransactions;
+ this.maxSize = maxSize;
+ this.blockingTimeout = blockingTimeout;
+ this.securityDomain = securityDomain;
+ this.jndiName = jndiName;
+ this.connectionTracker = connectionTracker;
+ setUpConnectionManager(null, null);
+ }
public void setMBeanContext(GeronimoMBeanContext context) {
this.context = context;
@@ -131,6 +148,19 @@
return true;
}
+ public void doStart() {
+ ObjectName connectionManagerName = context.getObjectName();
+ String agentID;
+ try {
+ ObjectName name = ObjectName.getInstance(MBEAN_SERVER_DELEGATE);
+ agentID = (String) context.getServer().getAttribute(name,
"MBeanServerId");
+ } catch (Exception e) {
+ throw new RuntimeException("Problem getting agentID from
MBeanServerDelegate", e);
+ }
+ setUpConnectionManager(agentID, connectionManagerName);
+
+ }
+
/**
* Order of constructed interceptors:
*
@@ -143,7 +173,7 @@
* LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor
(useTransactions (&localTransactions))
* MCFConnectionInterceptor
*/
- public void doStart() {
+ private void setUpConnectionManager(String agentID, ObjectName
connectionManagerName) {
//check for consistency between attributes
if (securityDomain == null) {
assert useSubject == false: "To use Subject in pooling, you need
a SecurityDomain";
@@ -191,14 +221,7 @@
securityDomain);
}
- ObjectName name = JMXUtil.getObjectName(MBEAN_SERVER_DELEGATE);
- try {
- String agentID = (String) context.getServer().getAttribute(name,
"MBeanServerId");
- cm = new ProxyConnectionManager(agentID,
context.getObjectName(), stack);
- } catch (Exception e) {
- throw new RuntimeException("Problem getting agentID from
MBeanServerDelegate", e);
- }
-
+ cm = new ProxyConnectionManager(agentID, connectionManagerName,
stack);
}
public boolean canStop() {
1.6 +2 -2
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java
Index: GeronimoConnectionEventListener.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- GeronimoConnectionEventListener.java 13 Dec 2003 23:33:53 -0000
1.5
+++ GeronimoConnectionEventListener.java 23 Dec 2003 17:34:35 -0000
1.6
@@ -127,7 +127,7 @@
* The <code>localTransactionCommitted</code> method
*
* @param event a <code>ConnectionEvent</code> value
- * @todo implement this method
+ * todo implement this method
*/
public void localTransactionCommitted(ConnectionEvent event) {
}
@@ -136,7 +136,7 @@
* The <code>localTransactionRolledback</code> method
*
* @param event a <code>ConnectionEvent</code> value
- * @todo implement this method
+ * todo implement this method
*/
public void localTransactionRolledback(ConnectionEvent event) {
}
1.3 +2 -1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl/DefaultComponentInterceptor.java
Index: DefaultComponentInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl/DefaultComponentInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultComponentInterceptor.java 10 Dec 2003 09:39:46 -0000 1.2
+++ DefaultComponentInterceptor.java 23 Dec 2003 17:34:35 -0000 1.3
@@ -101,6 +101,7 @@
newConnectorTransactionContext = (ConnectorTransactionContext)
transactionToTransactionContextMap.get(transaction);
if (newConnectorTransactionContext == null) {
newConnectorTransactionContext = new
DefaultTransactionContext(transaction);
+ transactionToTransactionContextMap.put(transaction,
newConnectorTransactionContext);
}
}
Set oldUnshareableResources =
cachedConnectionAssociator.setUnshareableResources(unshareableResources);
1.2 +2 -2
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl/DefaultInterceptor.java
Index: DefaultInterceptor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl/DefaultInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultInterceptor.java 9 Dec 2003 04:13:20 -0000 1.1
+++ DefaultInterceptor.java 23 Dec 2003 17:34:35 -0000 1.2
@@ -66,5 +66,5 @@
* */
public interface DefaultInterceptor {
- Object invoke(ConnectorComponentContext
newConnectorComponentContextontext) throws Throwable;
+ Object invoke(ConnectorComponentContext newConnectorComponentContext)
throws Throwable;
}