Package org.jboss.jbossts.star.util

Examples of org.jboss.jbossts.star.util.TxSupport


        WorkRestATResource.clearFaults();
    }

    @Test
    public void testListTransactions() {
        TxSupport[] txns = { new TxSupport(), new TxSupport() };
        int txnCount = new TxSupport().txCount();

        for (TxSupport txn : txns) {
            txn.startTx();
        }
View Full Code Here


        Assert.assertEquals(txnCount, txns[0].txCount());
    }

    @Test
    public void test1PCAbort() throws Exception {
        TxSupport txn = new TxSupport();
        String pUrl = getDeploymentUrl() + WorkRestATResource.PATH_SEGMENT;
        String pid = null;
        String pVal;

        pid = modifyResource(txn, pUrl, pid, "p1", "v1");
        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v1");

        txn.startTx();
        pid = enlistResource(txn, pUrl + "?pId=" + pid);

        modifyResource(txn, pUrl, pid, "p1", "v2");
        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v2");

        txn.rollbackTx();

        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v1");
    }
View Full Code Here

        Assert.assertEquals(pVal, "v1");
    }

    @Test
    public void test1PCCommit() throws Exception {
        TxSupport txn = new TxSupport();
        String pUrl = getDeploymentUrl() + WorkRestATResource.PATH_SEGMENT;
        String pid = null;
        String pVal;

        pid = modifyResource(txn, pUrl, pid, "p1", "v1");
        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v1");

        txn.startTx();
        pid = enlistResource(txn, pUrl + "?pId=" + pid);

        modifyResource(txn, pUrl, pid, "p1", "v2");
        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v2");

        txn.commitTx();

        pVal = getResourceProperty(txn, pUrl, pid, "p1");
        Assert.assertEquals(pVal, "v2");
    }
View Full Code Here

        Assert.assertEquals(pVal, "v2");
    }

    @Test
    public void test2PC() throws Exception {
        TxSupport txn = new TxSupport();
        String pUrl = getDeploymentUrl() + WorkRestATResource.PATH_SEGMENT;
        String[] pid = new String[2];
        String[] pVal = new String[2];

        for (int i = 0; i < pid.length; i++) {
            pid[i] = modifyResource(txn, pUrl, null, "p1", "v1");
            pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");

            Assert.assertEquals(pVal[i], "v1");
        }

        txn.startTx();

        for (int i = 0; i < pid.length; i++) {
            enlistResource(txn, pUrl + "?pId=" + pid[i]);

            modifyResource(txn, pUrl, pid[i], "p1", "v2");
            pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");

            Assert.assertEquals(pVal[i], "v2");
        }

        txn.rollbackTx();

        for (int i = 0; i < pid.length; i++) {
            pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
            Assert.assertEquals(pVal[i], "v1");
        }
View Full Code Here

        }
    }

    @Test
    public void testCommitInvalidTx() throws IOException {
        TxSupport txn = new TxSupport().startTx();

        String terminator = txn.getTerminatorURI();
        terminator += "/_dead";
        // an attempt to commit on this URI should fail:
        txn.httpRequest(new int[] { HttpURLConnection.HTTP_NOT_FOUND }, terminator, "PUT", TxMediaType.TX_STATUS_MEDIA_TYPE,
                TxStatusMediaType.TX_COMMITTED);
        // commit it properly
        txn.commitTx();
    }
View Full Code Here

        txn.commitTx();
    }

    @Test
    public void testTimeoutCleanup() throws InterruptedException {
        TxSupport txn = new TxSupport();
        int txnCount = txn.txCount();
        txn.startTx(1000);
        txn.enlistTestResource(getDeploymentUrl() + WorkRestATResource.PATH_SEGMENT, false);

        // Let the txn timeout
        Thread.sleep(2000);

        Assert.assertEquals(txnCount, txn.txCount());
    }
View Full Code Here

    }

    @Before
    public void before() {
        TxSupport.setTxnMgrUrl(getBaseUrl() + "/rest-at-coordinator/tx/transaction-manager");
        txSupport = new TxSupport();
    }
View Full Code Here

        boolean isTwoPhaseAware = "true".equals(twoPhaseAware);

        if (name.length() != 0) {
            if (value.length() != 0) {
                if (work == null) {
                    work = makeWork(new TxSupport(), info.getAbsolutePath().toString(), String.valueOf(++pid), null, null,
                            isTwoPhaseAware, isVolatile, null, null);
                    work.oldState.put(name, value);
                    faults.put(work.id, work);
                    return work.id;
                }
View Full Code Here

            @QueryParam("fault") @DefaultValue("") String fault,
            @QueryParam("twoPhaseAware") @DefaultValue("true") String twoPhaseAware,
            @QueryParam("isVolatile") @DefaultValue("false") String isVolatile, String enlistUrl) throws IOException {

        Work work = faults.get(pId);
        TxSupport txn = new TxSupport();
        String txId = enlistUrl.substring(enlistUrl.lastIndexOf('/') + 1);
        boolean isTwoPhaseAware = "true".equals(twoPhaseAware);
        boolean isVolatileParticipant = "true".equals(isVolatile);
        String vRegistration = null; // URI for registering with the volatile phase
        String vParticipantLink = null; // URI for handling pre and post 2PC phases

        if (work == null) {
            int id = ++pid;

            work = makeWork(txn, info.getAbsolutePath().toString(), String.valueOf(id), txId, enlistUrl, isTwoPhaseAware,
                    isVolatileParticipant, null, fault);
        } else {
            Work newWork = makeWork(txn, info.getAbsolutePath().toString(), work.id, txId, enlistUrl, isTwoPhaseAware,
                    isVolatileParticipant, null, fault);
            newWork.oldState = work.oldState;
            newWork.newState = work.newState;
            work = newWork;
        }

        if (enlistUrl.indexOf(',') != -1) {
            String[] urls = enlistUrl.split(",");

            if (urls.length < 2)
                throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST);

            enlistUrl = urls[0];
            vRegistration = urls[1];

            String vParticipant = new StringBuilder(info.getAbsolutePath().toString()).append('/').append(work.id).append('/')
                    .append(txId).append('/').append("vp").toString();
            vParticipantLink = txn.addLink2(new StringBuilder(), TxLinkNames.VOLATILE_PARTICIPANT, vParticipant, true)
                    .toString();
        }

        try {
            // enlist TestResource in the transaction as a participant
            work.recoveryUrl = txn.enlistParticipant(enlistUrl, work.pLinks);

            if (vParticipantLink != null)
                txn.enlistVolatileParticipant(vRegistration, vParticipantLink);
        } catch (HttpResponseException e) {
            throw new WebApplicationException(e.getActualResponse());
        }

        work.status = TxStatus.TransactionActive.name();
View Full Code Here

        }

        invocations.add("LoggingRestATResource.headParticipant()");

        final String serviceURL = uriInfo.getBaseUri() + uriInfo.getPath();
        final String linkHeader = new TxSupport().makeTwoPhaseAwareParticipantLinkHeader(serviceURL, false, null, null);

        return Response.ok().header("Link", linkHeader).build();
    }
View Full Code Here

TOP

Related Classes of org.jboss.jbossts.star.util.TxSupport

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.