1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import org.apache.geronimo.connector.mock.MockConnection; 21 import org.apache.geronimo.connector.mock.MockXAResource; 22 import org.apache.geronimo.connector.outbound.connectiontracking.DefaultInterceptor; 23 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext; 24 import org.apache.geronimo.transaction.GeronimoUserTransaction; 25 26 32 public class ConnectionManagerTest extends ConnectionManagerTestUtils { 33 34 35 public void testSingleTransactionCall() throws Throwable { 36 transactionManager.begin(); 37 defaultComponentInterceptor.invoke(connectorInstanceContext); 38 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 39 assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size()); 40 assertNull("Should not be committed", mockXAResource.getCommitted()); 41 transactionManager.commit(); 42 assertNotNull("Should be committed", mockXAResource.getCommitted()); 43 } 44 45 public void testNoTransactionCall() throws Throwable { 46 defaultComponentInterceptor.invoke(connectorInstanceContext); 47 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 48 assertEquals("XAResource should know 0 xid", 0, mockXAResource.getKnownXids().size()); 49 assertNull("Should not be committed", mockXAResource.getCommitted()); 50 } 51 52 public void testOneTransactionTwoCalls() throws Throwable { 53 transactionManager.begin(); 54 defaultComponentInterceptor.invoke(connectorInstanceContext); 55 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 56 assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size()); 57 assertNull("Should not be committed", mockXAResource.getCommitted()); 58 defaultComponentInterceptor.invoke(connectorInstanceContext); 59 assertEquals("Expected same XAResource", mockXAResource, mockManagedConnection.getXAResource()); 60 assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size()); 61 assertNull("Should not be committed", mockXAResource.getCommitted()); 62 transactionManager.commit(); 63 assertNotNull("Should be committed", mockXAResource.getCommitted()); 64 } 65 66 public void testUserTransactionEnlistingExistingConnections() throws Throwable { 67 mockComponent = new DefaultInterceptor() { 68 public Object invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable { 69 MockConnection mockConnection = (MockConnection) connectionFactory.getConnection(); 70 mockManagedConnection = mockConnection.getManagedConnection(); 71 userTransaction.begin(); 72 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 73 assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size()); 74 assertNull("Should not be committed", mockXAResource.getCommitted()); 75 userTransaction.commit(); 76 assertNotNull("Should be committed", mockXAResource.getCommitted()); 77 mockConnection.close(); 78 return null; 79 } 80 }; 81 userTransaction = new GeronimoUserTransaction(transactionManager); 82 defaultComponentInterceptor.invoke(connectorInstanceContext); 83 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 84 assertEquals("XAResource should know 1 xid", 1, mockXAResource.getKnownXids().size()); 85 assertNotNull("Should be committed", mockXAResource.getCommitted()); 86 mockXAResource.clear(); 87 } 88 89 public void testConnectionCloseReturnsCxAfterUserTransaction() throws Throwable { 90 for (int i = 0; i < maxSize + 1; i++) { 91 testUserTransactionEnlistingExistingConnections(); 92 } 93 } 94 95 public void testUnshareableConnections() throws Throwable { 96 unshareableResources.add(name); 97 mockComponent = new DefaultInterceptor() { 98 public Object invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable { 99 MockConnection mockConnection1 = (MockConnection) connectionFactory.getConnection(); 100 mockManagedConnection = mockConnection1.getManagedConnection(); 101 MockConnection mockConnection2 = (MockConnection) connectionFactory.getConnection(); 102 assertNotNull("Expected non-null managedconnection 1", mockConnection1.getManagedConnection()); 105 assertNotNull("Expected non-null managedconnection 2", mockConnection2.getManagedConnection()); 106 assertTrue("Expected different managed connections for each unshared handle", mockConnection1.getManagedConnection() != mockConnection2.getManagedConnection()); 107 108 mockConnection1.close(); 109 mockConnection2.close(); 110 return null; 111 } 112 113 }; 114 transactionManager.begin(); 115 defaultComponentInterceptor.invoke(connectorInstanceContext); 116 MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource(); 117 assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size()); 118 assertNull("Should not be committed", mockXAResource.getCommitted()); 119 transactionManager.commit(); 120 assertNotNull("Should be committed", mockXAResource.getCommitted()); 121 } 122 } 123 | Popular Tags |