Package com.sun.jini.test.share

Examples of com.sun.jini.test.share.TestParticipant


    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant part = null;
        int state = 0;

        startTxnMgr();

        part = new TestParticipantImpl();

        /*
         * Create the transaction, extract the semantic object
         * and query the state.  Next, commit the transaction
         * and query the state. Success means that the
         * ACTIVE state is read in the first test and the
         * TransactionException is thrown in the second test.
         */
        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        str = (ServerTransaction) cr.transaction;
        state = str.mgr.getState(str.id);
        part.setBehavior(OP_JOIN);
        part.setBehavior(OP_VOTE_PREPARED);
        part.behave(cr.transaction);

        if (state != ACTIVE) {
            cr.transaction.commit();
            throw new TestException( "couldn't read ACTIVE state");
        }

        // So far, the test has passed.
        cr.transaction.commit();

        /*
         * Test that getState for a non-existant transaction
         * causes the TransactionException to be thrown.
         */
        try {
            state = str.mgr.getState(str.id);

            if (state != TransactionConstants.COMMITTED) {
                throw new TestException("Illegal transaction state observed: "
                        + TxnConstants.getName(state));
            }
        } catch (UnknownTransactionException ute) {
            // So far, the test has passed
        }

        /*
         * get the manager, tell the test participant to pause a
         * long time (30sec) during the commit.
         * At this point, the transaction will be in the prepare
         * phase with a state of VOTING.
         */
        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            str = (ServerTransaction) cr.transaction;
            state = str.mgr.getState(str.id);
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_PREPARED);
            part.setBehavior(OP_TIMEOUT_PREPARE);
            part.behave(cr.transaction);
            Thread commiter = new CommitThread(cr.transaction);
            commiter.start();

            /*
             * By looping on the first ocurrance of
             * the VOTING state, we know that
             * the transaction is cycling from ACTIVE
             * to voting.  The issue in this test is
             * to give the commiter thread enough time
             * to do its thang.
             */
            while (true) {
                state = str.mgr.getState(str.id);

                if (state == VOTING) {
                    break;
                }
            }
        } catch (UnknownTransactionException ute) {
            // Things happened quickly and transaction now gone
        }

        // Expect no exception at this point. First test passed.

        /*
         * since the commit was done in a thread,
         * we need to wait until the transaction
         * has been scrubbed before proceeding.
         */
        try {
            while (true) {
                state = str.mgr.getState(str.id);
            }
        } catch (TransactionException bte) {
        } catch (RemoteException re) {}

        /*
         * get the manager, tell the test participant to pause a
         * long time (30sec) during the commit.
         * At this point, the transaction will be in the prepare
         * phase with a state of VOTING.
         */
        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            str = (ServerTransaction) cr.transaction;
            part.clearBehavior(OP_TIMEOUT_PREPARE);
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_PREPARED);
            part.setBehavior(OP_TIMEOUT_ABORT);
            part.behave(cr.transaction);
            Thread aborter = new AbortThread(cr.transaction);
            aborter.start();

            /*
             * By looping on the first ocurrance of
View Full Code Here


    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant part = null;
        int state = 0;

        startTxnMgr();

        part = new TestParticipantImpl();

        try {
            mgr = manager();

            if (DEBUG) {
                System.out.println("CommitExpiredTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, FORTY_SECONDS);
            str = (ServerTransaction) cr.transaction;
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_PREPARED);
            part.behave(cr.transaction);

            try {
                Thread.sleep(FORTY_SECONDS + SLOP);
            } catch (InterruptedException ie) {}
View Full Code Here

    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant[] parts = null;
        TestParticipant tp = null;

        startTxnMgr();

        // Create a number of TestParticipants
        logger.log(Level.INFO, "RollBackErrorTest: creating " + NUM_PARTICIPANTS
                + " participants");
        parts = TxnTestUtils.createParticipants(NUM_PARTICIPANTS);

        /*
         * All Participants will join and vote prepared.  One, randomly
         * chosen Participant will throw an exception when asked
         * to roll back.  There are two major cases for this,
         * the first time a RemoteException is thrown.  The second
         * time, a TransactionException is thrown.
         */
        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "RollBackErrorTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        str = (ServerTransaction) cr.transaction;
        logger.log(Level.INFO, "RollBackErrorTest: setting behavior for "
                + NUM_PARTICIPANTS + " participants");
        TxnTestUtils.setBulkBehavior(OP_JOIN, parts);
        TxnTestUtils.setBulkBehavior(OP_VOTE_PREPARED, parts);
        tp = TxnTestUtils.chooseOne(parts);
        tp.setBehavior(OP_EXCEPTION_ON_ABORT);
        tp.setBehavior(EXCEPTION_REMOTE);
        TxnTestUtils.doBulkBehavior(cr.transaction, parts);
        logger.log(Level.INFO, "RollBackErrorTest: aborting the txn");
        cr.transaction.abort();

        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        str = (ServerTransaction) cr.transaction;
        logger.log(Level.INFO, "RollBackErrorTest: setting behavior for "
                + NUM_PARTICIPANTS + " participants");
        tp.clearBehavior(EXCEPTION_REMOTE);
        tp.setBehavior(EXCEPTION_TRANSACTION);
        TxnTestUtils.doBulkBehavior(cr.transaction, parts);
        logger.log(Level.INFO, "RollBackErrorTest: aborting the txn");
        cr.transaction.abort();

        return;
View Full Code Here

public class PrepareAndCommitExceptionTest5 extends TxnManagerTest {

     public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        TestParticipant part = null;

        startTxnMgr();

        part = new TestParticipantImpl();

        mgr = manager();

        logger.log(Level.INFO, "PrepareAndCommitExceptionTest5: run: mgr = " + mgr);
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        logger.log(Level.INFO, "Created: cr = " + cr);       
        part.setBehavior(OP_JOIN);
        logger.log(Level.INFO, "Configured participant to join");       
        part.setBehavior(OP_EXCEPTION_ON_PREPARECOMMIT);
        logger.log(Level.INFO, "Configured participant to throw an exception");               
        part.setBehavior(EXCEPTION_TRANSACTION);
        logger.log(Level.INFO, "Configured participant to throw UTE");                               
        logger.log(Level.INFO, "Configuring participant to behave");
        part.behave(cr.transaction);

        logger.log(Level.INFO, "Committing transaction");
        try {
            cr.transaction.commit();
            throw new TestException("CannotCommitException not thrown");
View Full Code Here

public class PrepareAndCommitExceptionTest4 extends TxnManagerTest {

     public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        TestParticipant part = null;

        startTxnMgr();

        part = new TestParticipantImpl();

        mgr = manager();

        logger.log(Level.INFO, "PrepareAndCommitExceptionTest4: run: mgr = " + mgr);
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        logger.log(Level.INFO, "Created: cr = " + cr);       
        part.setBehavior(OP_JOIN);
        logger.log(Level.INFO, "Configured participant to join");       
        part.setBehavior(OP_EXCEPTION_ON_PREPARECOMMIT);
        logger.log(Level.INFO, "Configured participant to throw an exception");               
        part.setBehavior(EXCEPTION_TRANSACTION);
        logger.log(Level.INFO, "Configured participant to throw UTE");                               
        logger.log(Level.INFO, "Configuring participant to behave");
        part.behave(cr.transaction);

        logger.log(Level.INFO, "Committing transaction");
        try {
            cr.transaction.commit(1000);
            throw new TestException("CannotCommitException not thrown");
View Full Code Here

    
     
     public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        TestParticipant part = null;

        startTxnMgr();

        part = new TestParticipantImpl();

        mgr = manager();

        logger.log(Level.INFO, "PrepareAndCommitExceptionTest3: run: mgr = " + mgr);
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        logger.log(Level.INFO, "Created: cr = " + cr);       
        part.setBehavior(OP_JOIN);
        logger.log(Level.INFO, "Configured participant to join");       
        part.setBehavior(OP_EXCEPTION_ON_PREPARECOMMIT);
        logger.log(Level.INFO, "Configured participant to throw an exception");               
        part.setBehavior(EXCEPTION_REMOTE);       
        logger.log(Level.INFO, "Configured participant to throw RE 1st");               
        part.setBehavior(EXCEPTION_TRANSACTION);
        logger.log(Level.INFO, "Configured participant to throw UTE 2nd");                               
        logger.log(Level.INFO, "Configuring participant to behave");
        part.behave(cr.transaction);
        Clearer clearer = new Clearer(part);
        Thread t = new Thread(clearer);
        logger.log(Level.INFO, "Running clearer thread");                       
        t.start();
        logger.log(Level.INFO, "Committing transaction");                       
View Full Code Here

public class TwoPhaseTest extends TxnManagerTest {

    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        TestParticipant part = null;

        startTxnMgr();

        part = new TestParticipantImpl();

        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "TwoPhaseTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        part.setBehavior(OP_JOIN);
        part.setBehavior(OP_VOTE_NOTCHANGED);
        part.behave(cr.transaction);
        cr.transaction.commit();
        part.clearBehavior(OP_VOTE_NOTCHANGED);

        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "TwoPhaseTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        part.setBehavior(OP_JOIN);
        part.setBehavior(OP_VOTE_PREPARED);
        part.behave(cr.transaction);
        cr.transaction.commit();
        part.clearBehavior(OP_VOTE_PREPARED);

        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "TwoPhaseTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_ABORTED);
            part.behave(cr.transaction);
            cr.transaction.commit();
      throw new TestException("CannotCommitException is not raised");
        } catch (CannotCommitException cce) {

            // Expected exception. Test passed.
            try {
                part.clearBehavior(OP_VOTE_ABORTED);
            } catch (RemoteException re1) {
                logger.log(Level.INFO, "TwoPhaseTest: run: " + re1.getMessage());
                re1.printStackTrace();
            }
        }
View Full Code Here

    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant part = null;
        int state = 0;

        startTxnMgr();

        part = new TestParticipantImpl();

        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "AsynchAbortOnPrepareTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        str = (ServerTransaction) cr.transaction;
        part.setBehavior(OP_JOIN);
        part.setBehavior(OP_TIMEOUT_PREPARE);
        part.setBehavior(OP_TIMEOUT_PREPARECOMMIT);
        part.setBehavior(OP_TIMEOUT_VERYLONG);
        part.setBehavior(OP_VOTE_PREPARED);
        part.behave(cr.transaction);
        Thread committer = new CommitThread(cr.transaction);
        committer.start();
        /*
         * Wait for the transaction to switch
         * from ACTIVE to VOTING, then proceed to
View Full Code Here

    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant part = null;
        int state = 0;

        startTxnMgr();

        part = new TestParticipantImpl();

        /*
         * Create the transaction, extract the semantic object
         * and query the state.  Next, commit the transaction
         * and query the state. Success means that the
         * ACTIVE state is read in the first test and the
         * TransactionException is thrown in the second test.
         */
        mgr = manager();

        if (DEBUG) {
            logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
        }
        cr = TransactionFactory.create(mgr, Lease.FOREVER);
        str = (ServerTransaction) cr.transaction;
        state = str.mgr.getState(str.id);
        part.setBehavior(OP_JOIN);
        part.setBehavior(OP_VOTE_PREPARED);
        part.behave(cr.transaction);

        if (state != ACTIVE) {
            cr.transaction.commit();
            throw new TestException( "couldn't read ACTIVE state");
        }

        // So far, the test has passed.
        cr.transaction.commit();

        /*
         * Test that getState for a non-existant transaction
         * causes the TransactionException to be thrown.
         */
        try {
            state = str.mgr.getState(str.id);

            if (state != TransactionConstants.COMMITTED) {
                throw new TestException("Illegal transaction state observed: "
                        + TxnConstants.getName(state));
            }
        } catch (UnknownTransactionException ute) {
            // So far, the test has passed
        }

        /*
         * get the manager, tell the test participant to pause a
         * long time (30sec) during the commit.
         * At this point, the transaction will be in the prepare
         * phase with a state of VOTING.
         */
        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            str = (ServerTransaction) cr.transaction;
            state = str.mgr.getState(str.id);
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_PREPARED);
            part.setBehavior(OP_TIMEOUT_PREPARE);
            part.behave(cr.transaction);
            Thread commiter = new CommitThread(cr.transaction);
            commiter.start();

            /*
             * By looping on the first ocurrance of
             * the VOTING state, we know that
             * the transaction is cycling from ACTIVE
             * to voting.  The issue in this test is
             * to give the commiter thread enough time
             * to do its thang.
             */
            while (true) {
                state = str.mgr.getState(str.id);

                if (state == VOTING) {
                    break;
                }
            }
        } catch (UnknownTransactionException ute) {
            // Things happened quickly and transaction now gone
        }

        // Expect no exception at this point. First test passed.

        /*
         * since the commit was done in a thread,
         * we need to wait until the transaction
         * has been scrubbed before proceeding.
         */
        try {
            while (true) {
                state = str.mgr.getState(str.id);
            }
        } catch (TransactionException bte) {
        } catch (RemoteException re) {}

        /*
         * get the manager, tell the test participant to pause a
         * long time (30sec) during the commit.
         * At this point, the transaction will be in the prepare
         * phase with a state of VOTING.
         */
        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "GetStateTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            str = (ServerTransaction) cr.transaction;
            part.clearBehavior(OP_TIMEOUT_PREPARE);
            part.setBehavior(OP_JOIN);
            part.setBehavior(OP_VOTE_PREPARED);
            part.setBehavior(OP_TIMEOUT_ABORT);
            part.behave(cr.transaction);
            Thread aborter = new AbortThread(cr.transaction);
            aborter.start();

            /*
             * By looping on the first ocurrance of
View Full Code Here

    public void run() throws Exception {
        TransactionManager mgr = null;
        Transaction.Created cr = null;
        ServerTransaction str = null;
        TestParticipant part = null;
        TestParticipant[] parts = null;
        int state = 0;

        startTxnMgr();

        logger.log(Level.INFO,
       "JoinWhileActiveTest: creating " + NUM_PARTICIPANTS
                + " participants");
        parts = TxnTestUtils.createParticipants(NUM_PARTICIPANTS);
        part = new TestParticipantImpl(TestParticipant.DEFAULT_NAME + "-"
                + NUM_PARTICIPANTS);

        /*
         * A specified number of participants will join the transaction
         * and vote PREPARED.  Another participant will attempt to
         * join the transaction once its state is no longer ACTIVE.
         */
        try {
            mgr = manager();

            if (DEBUG) {
                logger.log(Level.INFO, "JoinWhileActiveTest: run: mgr = " + mgr);
            }
            cr = TransactionFactory.create(mgr, Lease.FOREVER);
            str = (ServerTransaction) cr.transaction;
            logger.log(Level.INFO, "JoinWhileActive: setting behavior for "
                    + "odd-ball participant");
            part.setBehavior(OP_JOIN);
            logger.log(Level.INFO, "JoinWhileActive: setting behavior for "
                    + NUM_PARTICIPANTS + " participants");
            TxnTestUtils.setBulkBehavior(OP_JOIN, parts);
            TxnTestUtils.setBulkBehavior(OP_VOTE_PREPARED, parts);
            TxnTestUtils.setBulkBehavior(OP_TIMEOUT_PREPARE, parts);
            TxnTestUtils.doBulkBehavior(str, parts);
            Thread committer = new CommitThread(str);
            committer.start();

            /*
             * First make sure the transaction's state
             * is no longer in the ACTIVE state
             */
            state = str.mgr.getState(str.id);

            while (state == ACTIVE) {
                if (DEBUG) {
                    int st = state;
                    logger.log(Level.INFO, "JoinWhileActiveTest: run: state = "
                            + com.sun.jini.constants.TxnConstants.getName(st));
                }
                state = str.mgr.getState(str.id);
            }

            /*
             * Now instruct the odd-ball participant to join
             * the non ACTIVE transaction
             */
            try {
                part.behave(str);
    throw new TestException( "CannotJoinException is not raised");
            } catch (CannotJoinException cje) {
                if (DEBUG) {
                    cje.printStackTrace();
                    logger.log(Level.INFO, cje.getMessage());
View Full Code Here

TOP

Related Classes of com.sun.jini.test.share.TestParticipant

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.