Package com.taobao.metamorphosis.server.transaction

Examples of com.taobao.metamorphosis.server.transaction.Transaction


        // ��������ʱ
        // this.processor.setTransactionTimeout(context, xid, 3);
        this.replay();
        this.processor.beginTransaction(context, xid, 3);

        final Transaction tx = this.processor.getTransaction(context, xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());

        assertNotNull(tx.getTimeoutRef());
        assertFalse(tx.getTimeoutRef().isExpired());

        Thread.sleep(4000);
        assertTrue(tx.getTimeoutRef().isExpired());
        // It's rolled back
        try {
            assertNull(this.processor.getTransaction(context, xid));
            fail();
        }
View Full Code Here


    public void testBeginPreparedCommitTwoPhase() throws Exception {
        final SessionContext context = new SessionContextImpl("test", this.conn);
        final TransactionId xid = XIDGenerator.createXID(100);
        assertNull(context.getTransactions().get(xid));
        this.processor.beginTransaction(context, xid, 0);
        final Transaction tx = this.processor.getTransaction(context, xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));

        // commit two phase
        this.processor.commitTransaction(context, xid, false);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));

        assertTrue(store.getSizeInBytes() > 0);
    }
View Full Code Here

    public void testBeginPutRollback() throws Exception {
        final SessionContext context = new SessionContextImpl("test", this.conn);
        final TransactionId xid = new LocalTransactionId("test", 100);
        assertNull(context.getTransactions().get(xid));
        this.processor.beginTransaction(context, xid, 0);
        final Transaction tx = context.getTransactions().get(xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // rollback
        this.processor.rollbackTransaction(context, xid);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));
        store.flush();
        assertEquals(0, store.getSizeInBytes());
    }
View Full Code Here

    public void testBeginPutPrepareRollbackCloseRecover() throws Exception {
        final SessionContext context = new SessionContextImpl("test", this.conn);
        final TransactionId xid = XIDGenerator.createXID(100);
        assertNull(context.getTransactions().get(xid));
        this.processor.beginTransaction(context, xid, 0);
        final Transaction tx = this.processor.getTransaction(context, xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // prepare
        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));

        // rollback
        this.processor.rollbackTransaction(context, xid);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));

        assertEquals(0, store.getSizeInBytes());

        // close and reopen it
View Full Code Here

    public void testCommitTransactionHeuristicallyRecoverHeuristicTransactions() throws Exception {
        final SessionContext context = new SessionContextImpl("test", this.conn);
        final TransactionId xid = XIDGenerator.createXID(100);
        assertNull(context.getTransactions().get(xid));
        this.processor.beginTransaction(context, xid, 0);
        final Transaction tx = this.processor.getTransaction(context, xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // prepare
        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));

        // �ֹ��ύ
        this.processor.commitTransactionHeuristically(xid.getTransactionKey(), false);
        Map<TransactionId, XATransaction> heuristicTxMap = this.processor.getXAHeuristicTransactions();
        assertFalse(heuristicTxMap.isEmpty());
        assertTrue(heuristicTxMap.containsKey(xid));
        assertSame(tx, heuristicTxMap.get(xid));
        assertEquals(Transaction.HEURISTIC_COMMIT_STATE, heuristicTxMap.get(xid).getState());

        // �رգ����´�recover
        this.processor.dispose();
        this.newProcessor();
        this.processor.recoverHeuristicTransactions();
        // ȷ����ȷrecover
        heuristicTxMap = this.processor.getXAHeuristicTransactions();
        assertFalse(heuristicTxMap.isEmpty());
        assertTrue(heuristicTxMap.containsKey(xid));
        assertEquals(tx.getTransactionId(), heuristicTxMap.get(xid).getTransactionId());
        assertEquals(Transaction.HEURISTIC_COMMIT_STATE, heuristicTxMap.get(xid).getState());
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.server.transaction.Transaction

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.