Package org.apache.geronimo.transaction.context

Examples of org.apache.geronimo.transaction.context.TransactionContext


* */
public class ConnectionManagerTest extends ConnectionManagerTestUtils {


    public void testSingleTransactionCall() throws Throwable {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        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());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here


        assertEquals("XAResource should know 0 xid", 0, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
    }

    public void testOneTransactionTwoCalls() throws Throwable {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        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());
        defaultComponentInterceptor.invoke(defaultComponentContext);
        assertEquals("Expected same XAResource", mockXAResource, mockManagedConnection.getXAResource());
        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here

                mockConnection2.close();
                return null;
            }

        };
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        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());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here

            transactionContextManager.setContext(null);
        }
    }

    public void testTasksInTransaction() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (long i = 0; i < COUNT; i++) {
            timer.schedule(userTaskFactory, key, userId, userKey, i);
        }
        Thread.sleep(COUNT + SLOP);
        assertEquals(0, counter.get());
        transactionContext.commit();
        Thread.sleep(COUNT + SLOP);
        assertEquals(COUNT, counter.get());
    }
View Full Code Here

        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.commit();
        Thread.sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
    }
View Full Code Here

        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.rollback();
        Thread.sleep(SLOP + DELAY);
        // Catches up with two periods.
        assertEquals(3 * COUNT, counter.get());
    }
View Full Code Here

        assertTrue("Expected returned", returned);
        assertTrue("Expected not committed", !committed);
    }

    public void testTransactionShareableConnection() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        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);
        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }
View Full Code Here

        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }

    public void testTransactionUnshareableConnection() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo = makeConnectionInfo();
        connectionInfo.setUnshareable(true);
        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);
        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }
View Full Code Here

    public void main(final String[] args) throws Exception {
        //TODO reorganize this so it makes more sense.  maybe use an interceptor stack.
        Thread thread = Thread.currentThread();

        ClassLoader oldClassLoader = thread.getContextClassLoader();
        TransactionContext oldTransactionContext = transactionContextManager.getContext();
        TransactionContext currentTransactionContext = null;
        Callers oldCallers = ContextManager.getCallers();
        Subject clientSubject = defaultSubject;
        LoginContext loginContext = null;
        try {
            thread.setContextClassLoader(classLoader);
            if (callbackHandlerClass != null) {
                //look for a constructor taking the args
                CallbackHandler callbackHandler;
                try {
                    Constructor cArgs = callbackHandlerClass.getConstructor(new Class[] {String[].class});
                    callbackHandler = (CallbackHandler) cArgs.newInstance(new Object[] {args});
                } catch (NoSuchMethodException e) {
                    callbackHandler = (CallbackHandler) callbackHandlerClass.newInstance();
                }
                loginContext = new LoginContext(realmName, callbackHandler);
                try {
                    loginContext.login();
                } catch (LoginException e) {
                    loginContext = null;
                    throw e;
                }
                clientSubject = loginContext.getSubject();
            }
            ContextManager.setCallers(clientSubject, clientSubject);
            jndiContext.startClient(appClientModuleName, kernel, classLoader);
            currentTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
            if (clientSubject == null) {
                mainMethod.invoke(null, new Object[]{args});
            } else {
                Subject.doAs(clientSubject, new PrivilegedAction() {
                    public Object run() {
                        try {
                            mainMethod.invoke(null, new Object[]{args});
                        } catch (IllegalAccessException e) {
                            throw new RuntimeException(e);
                        } catch (InvocationTargetException e) {
                            throw new RuntimeException(e);
                        }
                        return null;
                    }
                });
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof Exception) {
                throw (Exception) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            }
            throw new Error(e);
        } finally {
            if (loginContext != null) {
                loginContext.logout();
            }
            jndiContext.stopClient(appClientModuleName);

            thread.setContextClassLoader(oldClassLoader);
            transactionContextManager.setContext(oldTransactionContext);
            if (currentTransactionContext != null) {
                currentTransactionContext.commit();
            }
            ContextManager.popCallers(oldCallers);
        }
    }
View Full Code Here

        this.newTxIndex = newTxIndex;
        this.transactionContextManager = transactionContextManager;
    }

    public void before(Object[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
        TransactionContext oldTransactionContext = transactionContextManager.getContext();
        TransactionContext newTransactionContext = null;
        if (oldTransactionContext == null || !oldTransactionContext.isInheritable()) {
            newTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
        }
        context[oldTxIndex] = oldTransactionContext;
        context[newTxIndex] = newTransactionContext;
View Full Code Here

TOP

Related Classes of org.apache.geronimo.transaction.context.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.