Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Commit

Permalink
JBTM-2353 Compensation handler should not throw exception, if there i…
Browse files Browse the repository at this point in the history
…s no transaction
  • Loading branch information
gytis committed Apr 7, 2015
1 parent 1f37e61 commit ed943d5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
Expand Up @@ -22,6 +22,9 @@

package org.jboss.narayana.compensations.impl;

import org.jboss.narayana.compensations.api.NoTransactionException;
import org.jboss.narayana.compensations.api.TxLogged;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import java.lang.reflect.Method;
Expand All @@ -35,6 +38,10 @@ public abstract class ParticipantInterceptor {
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {

if (!BAControllerFactory.getInstance().isBARunning()) {
return ic.proceed();
}

ParticipantManager participantManager = enlistParticipant(ic.getMethod());

Object result;
Expand Down
Expand Up @@ -23,7 +23,6 @@
package org.jboss.narayana.compensations.impl;

import org.jboss.narayana.compensations.api.CompensationHandler;
import org.jboss.narayana.compensations.api.NoTransactionException;
import org.jboss.narayana.compensations.api.TxCompensate;

import javax.annotation.Priority;
Expand All @@ -50,14 +49,8 @@ public Object intercept(InvocationContext ic) throws Exception {
@Override
protected ParticipantManager enlistParticipant(Method method) throws Exception {

BAControler baControler = BAControllerFactory.getInstance();

if (!baControler.isBARunning()) {
throw new NoTransactionException("Methods annotated with '" + TxCompensate.class.getName() + "' must be invoked in the context of a compensation based transaction");
}

Class<? extends CompensationHandler> compensationHandler = getCompensationHandler(method);
return baControler.enlist(compensationHandler, null, null);
return BAControllerFactory.getInstance().enlist(compensationHandler, null, null);
}

private Class<? extends CompensationHandler> getCompensationHandler(Method method) {
Expand Down
Expand Up @@ -23,7 +23,6 @@
package org.jboss.narayana.compensations.impl;

import org.jboss.narayana.compensations.api.ConfirmationHandler;
import org.jboss.narayana.compensations.api.NoTransactionException;
import org.jboss.narayana.compensations.api.TxConfirm;

import javax.annotation.Priority;
Expand All @@ -50,14 +49,8 @@ public Object intercept(InvocationContext ic) throws Exception {
@Override
protected ParticipantManager enlistParticipant(Method method) throws Exception {

BAControler baControler = BAControllerFactory.getInstance();

if (!baControler.isBARunning()) {
throw new NoTransactionException("Methods annotated with '" + TxConfirm.class.getName() + "' must be invoked in the context of a compensation based transaction");
}

Class<? extends ConfirmationHandler> confirmationHandler = getConfirmationHandler(method);
return baControler.enlist(null, confirmationHandler, null);
return BAControllerFactory.getInstance().enlist(null, confirmationHandler, null);
}

private Class<? extends ConfirmationHandler> getConfirmationHandler(Method method) {
Expand Down
Expand Up @@ -22,7 +22,6 @@

package org.jboss.narayana.compensations.impl;

import org.jboss.narayana.compensations.api.NoTransactionException;
import org.jboss.narayana.compensations.api.TransactionLoggedHandler;
import org.jboss.narayana.compensations.api.TxLogged;

Expand Down Expand Up @@ -50,14 +49,8 @@ public Object intercept(InvocationContext ic) throws Exception {
@Override
protected ParticipantManager enlistParticipant(Method method) throws Exception {

BAControler baControler = BAControllerFactory.getInstance();

if (!baControler.isBARunning()) {
throw new NoTransactionException("Methods annotated with '" + TxLogged.class.getName() + "' must be invoked in the context of a compensation based transaction");
}

Class<? extends TransactionLoggedHandler> transactionLogHandler = getTransactionLoggedHandler(method);
return baControler.enlist(null, null, transactionLogHandler);
return BAControllerFactory.getInstance().enlist(null, null, transactionLogHandler);
}

private Class<? extends TransactionLoggedHandler> getTransactionLoggedHandler(Method method) {
Expand Down
Expand Up @@ -164,12 +164,7 @@ public void testAlternativeThenFail() throws Exception {
@Test
public void testNoTransaction() throws Exception {

try {
singleService.noTransactionPresent();
Assert.fail();
} catch (NoTransactionException e) {
//expected
}
singleService.noTransactionPresent();

Assert.assertEquals(false, DummyCompensationHandler1.getCalled());
Assert.assertEquals(false, DummyConfirmationHandler1.getCalled());
Expand Down
Expand Up @@ -117,6 +117,9 @@ public void invokeWithMandatory(final Object expectedTransaction) throws Excepti
}

@Compensatable(CompensationTransactionType.SUPPORTS)
@TxCompensate(DummyCompensationHandler1.class)
@TxConfirm(DummyConfirmationHandler1.class)
@TxLogged(DummyTransactionLoggedHandler1.class)
public void invokeWithSupports() throws Exception {

Utills.assertTransactionActive(false);
Expand All @@ -134,12 +137,18 @@ public void invokeWithSupports(final Object expectedTransaction) throws Exceptio
}

@Compensatable(CompensationTransactionType.NOT_SUPPORTED)
@TxCompensate(DummyCompensationHandler1.class)
@TxConfirm(DummyConfirmationHandler1.class)
@TxLogged(DummyTransactionLoggedHandler1.class)
public void invokeWithNotSupported() throws Exception {

Utills.assertTransactionActive(false);
}

@Compensatable(CompensationTransactionType.NEVER)
@TxCompensate(DummyCompensationHandler1.class)
@TxConfirm(DummyConfirmationHandler1.class)
@TxLogged(DummyTransactionLoggedHandler1.class)
public void invokeWithNever() throws Exception {

Utills.assertTransactionActive(false);
Expand Down

0 comments on commit ed943d5

Please sign in to comment.