You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by "Yakov Zhdanov (JIRA)" <ji...@apache.org> on 2016/11/23 05:39:58 UTC

[jira] [Created] (IGNITE-4267) Need to revisit JTA functionality

Yakov Zhdanov created IGNITE-4267:
-------------------------------------

             Summary: Need to revisit JTA functionality
                 Key: IGNITE-4267
                 URL: https://issues.apache.org/jira/browse/IGNITE-4267
             Project: Ignite
          Issue Type: Task
            Reporter: Yakov Zhdanov


I have found this in older emails:
====
I found 2 problem:
1) We threw XAException without error code in GridCacheXAResource
2) I debugged 2 different transaction managers - jotm and narayana (JBoss). Both doesn't trigger rollback logic in our GridCacheXAResource if exception was thrown during JTA commit (and I didn't found such logic in its sources, so I suppose we should trigger it ourself). Added GridCacheJtaRollbackSelfTest which emulate this situation.
===

{noformat}
/**
 * Tests for JTA rollback scenarios.
 */
public class GridCacheJtaRollbackSelfTest extends GridCacheAbstractSelfTest {
    /** Java Open Transaction Manager facade. */
    private static Jotm jotm;

    @Override protected int gridCount() {
        return 1;
    }

    /** {@inheritDoc} */
    @Override protected void beforeTest() throws Exception {
        super.beforeTest();

        jotm = new Jotm(true, false);
    }

    /** {@inheritDoc} */
    @Override protected void afterTest() throws Exception {
        super.afterTest();

        jotm.stop();
    }

    /** {@inheritDoc} */
    @Override protected GridCacheMode cacheMode() {
        return PARTITIONED;
    }

    /** {@inheritDoc} */
    @Override protected GridCacheConfiguration cacheConfiguration(String gridName) throws Exception {
        GridCacheConfiguration cfg = super.cacheConfiguration(gridName);

        cfg.setTransactionManagerLookupClassName(TestTmLookup.class.getName());

        cfg.setStore(new GridCacheFailureStore(10));

        return cfg;
    }

    public void testJta() throws Exception {
        for (int i = 0; i < 10; i++) {
            UserTransaction jtaTx = jotm.getUserTransaction();

            try {
                jtaTx.begin();

                info("Transaction started.");

                cache().put("key1", 1);
                cache().put("key2", 2);

                cache().get("key1");

                cache().remove("key2");

                info("Start commit...");

                jtaTx.commit();

                info("Transaction commited.");
            }
            catch (Exception e) {
                e.printStackTrace();

                info("Got expected exception, status=" + jtaTx.getStatus());
            }
            finally {
                if (jtaTx.getStatus() == Status.STATUS_ACTIVE) {
                    System.out.println("Start rollback...");

                    jtaTx.rollback();
                }
            }
        }
    }

    /**
     *
     */
    private static final class GridCacheFailureStore extends GridCacheStoreAdapter {
        /** */
        private final AtomicInteger putCnt = new AtomicInteger();

        /** */
        private final int failStep;

        private GridCacheFailureStore(int failStep) {
            this.failStep = failStep;
        }

        /** {@inheritDoc} */
        @Override public Object load(@Nullable GridCacheTx tx, Object key) {
            return null;
        }

        /** {@inheritDoc} */
        @Override public void put(@Nullable GridCacheTx tx, Object key, @Nullable Object val) throws GridException {
            int cnt = putCnt.incrementAndGet();

            if (cnt == failStep)
                throw new GridException("Test exception (need to rollback JTA transactions).");
        }

        /** {@inheritDoc} */
        @Override public void remove(@Nullable GridCacheTx tx, Object key) {
        }
    }

    /**
     *
     */
    @SuppressWarnings("PublicInnerClass")
    public static class TestTmLookup implements GridCacheTmLookup {
        /** {@inheritDoc} */
        @Override public TransactionManager getTm() throws GridException {
            return jotm.getTransactionManager();
        }
    }
}
{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)