Skip to content

Commit

Permalink
Merge pull request #179 from mslovik/WFTC-136-test-case
Browse files Browse the repository at this point in the history
Add test case for WFTC-136
  • Loading branch information
tadamski authored Nov 9, 2023
2 parents b636ece + d91c404 commit 3ec38f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wildfly.transaction.client.provider.jboss.TestImportedTransaction;
import org.wildfly.transaction.client.provider.jboss.TestTransaction;
import org.wildfly.transaction.client.provider.jboss.TestTransactionManager;
import org.wildfly.transaction.client.provider.jboss.TestTransactionProvider;
import org.wildfly.transaction.client.provider.jboss.TestXAResource;
import org.wildfly.transaction.client.provider.jboss.TestXid;
import org.wildfly.transaction.client.provider.jboss.*;

import javax.transaction.xa.XAResource;
import java.net.URI;
Expand All @@ -40,9 +35,11 @@
*/
public class LocalUserTransactionTestCase {

private static final TestXAResourceRecoveryRegistry testXAResourceRecoveryRegistry = new TestXAResourceRecoveryRegistry();

@BeforeClass
public static void init() {
final LocalTransactionContext transactionContext = new LocalTransactionContext(new TestTransactionProvider(500, Path.of("./target")));
final LocalTransactionContext transactionContext = new LocalTransactionContext(new TestTransactionProvider(500, Path.of("./target"), testXAResourceRecoveryRegistry));
LocalTransactionContext.getContextManager().setGlobalDefault(transactionContext);
}

Expand Down Expand Up @@ -207,4 +204,28 @@ public void outflowedTransactionTest() throws Exception {
Assert.assertFalse(TestTransactionManager.rolledback);
}

@Test
public void removeXAResourceRecoveryTest() throws Exception {
ContextTransactionManager tm = ContextTransactionManager.getInstance();
Assert.assertNull(tm.stateRef.get().transaction);
tm.begin();
Assert.assertTrue(TestTransactionProvider.newTransactionCreated);
Assert.assertNotNull(tm.stateRef.get().transaction);

Transaction t = tm.stateRef.get().transaction;
Assert.assertNotNull(t);
Assert.assertTrue(t instanceof LocalTransaction);
LocalTransaction lt = (LocalTransaction) t;

tm.commit();
Assert.assertNull(tm.stateRef.get().transaction);
Assert.assertTrue(TestTransactionManager.committed);
Assert.assertFalse(TestTransactionManager.rolledback);

TestTransactionProvider testTransactionProvider = (TestTransactionProvider) lt.getProvider();
Assert.assertNotNull(testXAResourceRecoveryRegistry.getXaResourceRecovery());

testTransactionProvider.removeXAResourceRecovery(testXAResourceRecoveryRegistry);
Assert.assertNull(testXAResourceRecoveryRegistry.getXaResourceRecovery());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jakarta.transaction.Synchronization;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import org.jboss.tm.XAResourceRecoveryRegistry;
import org.wildfly.common.Assert;
import org.wildfly.transaction.client.SimpleXid;

Expand All @@ -42,6 +43,12 @@ public TestTransactionProvider(final int staleTransactionTime,
super(new TestExtendedJBossXATerminator(), staleTransactionTime, new TestTransactionManager(), new TestXAResourceRecoveryRegistry(), xaRecoveryPath);
}

public TestTransactionProvider(final int staleTransactionTime,
final Path xaRecoveryPath,
final XAResourceRecoveryRegistry xaResourceRecoveryRegistry) {
super(new TestExtendedJBossXATerminator(), staleTransactionTime, new TestTransactionManager(), xaResourceRecoveryRegistry, xaRecoveryPath);
}

@Override
public Transaction createNewTransaction(int timeout) throws SystemException, SecurityException {
newTransactionCreated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@

public class TestXAResourceRecoveryRegistry implements XAResourceRecoveryRegistry {

private XAResourceRecovery xaResourceRecovery;

public TestXAResourceRecoveryRegistry(){}

@Override
public void addXAResourceRecovery(XAResourceRecovery xaResourceRecovery) {

this.xaResourceRecovery = xaResourceRecovery;
}

@Override
public void removeXAResourceRecovery(XAResourceRecovery xaResourceRecovery) {
this.xaResourceRecovery = null;
}

public XAResourceRecovery getXaResourceRecovery() {
return xaResourceRecovery;
}
}

0 comments on commit 3ec38f6

Please sign in to comment.