Package com.taobao.metamorphosis.server.store

Examples of com.taobao.metamorphosis.server.store.MessageStore


public class JournalTransactionStoreUnitTest extends BaseTransactionUnitTest {

    @Test
    public void testAddAddRollBackCloseRecover() throws Exception {
        final LocalTransactionId xid = new LocalTransactionId("test", 1);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid, 0, 1), null);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg2".getBytes(), xid, 0, 2), null);

        final Tx tx = this.transactionStore.getInflyTx(xid);
        assertNotNull(tx);
        final PutCommand[] commands = tx.getRequests();
        assertNotNull(commands);
        assertEquals(2, commands.length);
        store.flush();
        // ��û��д��
        assertEquals(0, store.getSizeInBytes());

        // rollback
        this.transactionStore.rollback(xid);
        assertNull(this.transactionStore.getInflyTx(xid));
        store.flush();
        // �ع�����Ȼû��д��
        assertEquals(0, store.getSizeInBytes());

        this.tearDown();
        this.init(this.path);
        assertTrue(this.journalStore.getCurrDataFile().getLength() > 0);
        assertNull(this.transactionStore.getInflyTx(xid));
View Full Code Here



    @Test
    public void testAddAddCloseRecover() throws Exception {
        final LocalTransactionId xid1 = new LocalTransactionId("test", 1);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid1, 0, 1), null);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg2".getBytes(), xid1, 0, 2), null);

        final LocalTransactionId xid2 = new LocalTransactionId("test", 2);
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid2, 0, 1), null);

        this.tearDown();
        this.init(this.path);
        assertTrue(this.journalStore.getCurrDataFile().getLength() > 0);

        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        // ȷ����Ϣû��д��
        assertEquals(0, store.getSizeInBytes());

        // ȷ��TX������
        final Tx tx1 = this.transactionStore.getInflyTx(xid1);
        assertNotNull(tx1);
        PutCommand[] commands = tx1.getRequests();
        assertNotNull(commands);
        assertEquals(2, commands.length);

        final Tx tx2 = this.transactionStore.getInflyTx(xid2);
        assertNotNull(tx2);
        commands = tx2.getRequests();
        assertNotNull(commands);
        assertEquals(1, commands.length);

        // recover�󣬶��ع���
        this.transactionStore.recover(null);
        assertNull(this.transactionStore.getInflyTx(xid1));
        assertNull(this.transactionStore.getInflyTx(xid2));
        // ȷ����Ϣ����û��д��
        assertEquals(0, store.getSizeInBytes());
    }
View Full Code Here


    @Test
    public void testAddAddCommitCloseRecover() throws Exception {
        final LocalTransactionId xid = new LocalTransactionId("test", 1);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid, 0, 1), null);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg2".getBytes(), xid, 0, 2), null);

        final Tx tx = this.transactionStore.getInflyTx(xid);
        assertNotNull(tx);
        final PutCommand[] commands = tx.getRequests();
        assertNotNull(commands);
        assertEquals(2, commands.length);
        store.flush();
        // ��û��д��
        assertEquals(0, store.getSizeInBytes());

        // rollback
        this.transactionStore.commit(xid, false);
        assertNull(this.transactionStore.getInflyTx(xid));
        store.flush();
        // д����Ϣ
        assertTrue(store.getSizeInBytes() > 0);

        this.tearDown();
        this.init(this.path);
        assertTrue(this.journalStore.getCurrDataFile().getLength() > 0);
        assertNull(this.transactionStore.getInflyTx(xid));
View Full Code Here


    @Test
    public void testAddAddPrepareCommitCloseRecover() throws Exception {
        final XATransactionId xid = XIDGenerator.createXID(99);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid, 0, 1), null);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg2".getBytes(), xid, 0, 2), null);
        assertNotNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));
        // prepare
        this.transactionStore.prepare(xid);
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNotNull(this.transactionStore.getPreparedTx(xid));
        store.flush();
        // ȷ�ϻ�δд��
        assertEquals(0, store.getSizeInBytes());

        // commit
        this.transactionStore.commit(xid, true);
        store.flush();
        assertTrue(store.getSizeInBytes() > 0);
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));

        // close and reopen
        this.tearDown();
        this.init(this.path);
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        assertTrue(store.getSizeInBytes() > 0);
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));
        this.assertMessages(store);

    }
View Full Code Here


    @Test
    public void testAddAddPrepareRollbackCloseRecover() throws Exception {
        final XATransactionId xid = XIDGenerator.createXID(99);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg1".getBytes(), xid, 0, 1), null);
        this.transactionStore.addMessage(store, 1, new PutCommand("topic1", 2, "msg2".getBytes(), xid, 0, 2), null);
        assertNotNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));
        // prepare
        this.transactionStore.prepare(xid);
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNotNull(this.transactionStore.getPreparedTx(xid));
        store.flush();
        // ȷ�ϻ�δд��
        assertEquals(0, store.getSizeInBytes());

        // rollback
        this.transactionStore.rollback(xid);
        store.flush();
        assertEquals(0, store.getSizeInBytes());
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));

        // close and reopen
        this.tearDown();
        this.init(this.path);
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        assertEquals(0, store.getSizeInBytes());
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNull(this.transactionStore.getPreparedTx(xid));

    }
View Full Code Here


    @Test
    public void testAddAddPrepareCloseRecover() throws Exception {
        final XATransactionId xid = XIDGenerator.createXID(99);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        final PutCommand cmd1 = new PutCommand("topic1", 2, "msg1".getBytes(), xid, 0, 1);
        this.transactionStore.addMessage(store, 1, cmd1, null);
        final PutCommand cmd2 = new PutCommand("topic1", 2, "msg2".getBytes(), xid, 0, 2);
        this.transactionStore.addMessage(store, 1, cmd2, null);

        // prepare
        this.transactionStore.prepare(xid);
        assertNull(this.transactionStore.getInflyTx(xid));
        assertNotNull(this.transactionStore.getPreparedTx(xid));
        store.flush();
        // ȷ�ϻ�δд��
        assertEquals(0, store.getSizeInBytes());

        // close and reopen
        this.tearDown();
        this.init(this.path);
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        assertEquals(0, store.getSizeInBytes());
        assertNull(this.transactionStore.getInflyTx(xid));
        // ��Ȼ����prepare״̬
        assertNotNull(this.transactionStore.getPreparedTx(xid));
        // ȷ�ϲ�������
        final Tx tx = this.transactionStore.getPreparedTx(xid);
View Full Code Here

    @Test
    public void testCheckpoint() throws Exception {
        // ����1
        final LocalTransactionId xid1 = new LocalTransactionId("session1", 1);
        final MessageStore store1 = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        this.transactionStore.addMessage(store1, 1, new PutCommand("topic1", 2, ("msg" + 2).getBytes(), xid1, 0, 1),
            null);

        // ����2
        final LocalTransactionId xid2 = new LocalTransactionId("session2", 1);
        final MessageStore store2 = this.messageStoreManager.getOrCreateMessageStore("topic1", 3);
        this.transactionStore.addMessage(store2, 1, new PutCommand("topic1", 3, ("msg" + 3).getBytes(), xid2, 0, 1),
            null);

        // ����3���Ѿ��ύ
        final LocalTransactionId xid3 = new LocalTransactionId("session3", 1);
        final MessageStore store3 = this.messageStoreManager.getOrCreateMessageStore("topic1", 0);
        this.transactionStore.addMessage(store3, 1, new PutCommand("topic1", 0, ("msg" + 0).getBytes(), xid3, 0, 1),
            null);
        this.transactionStore.commit(xid3, false);

        // ����checkpoint��Ӧ��Ϊ����1
View Full Code Here

            public void run(final int index, final int times) throws Exception {
                final int id = gen.incrementAndGet();
                final LocalTransactionId xid = new LocalTransactionId("test", id);
                for (int j = 0; j < rand.nextInt(3) + 1; j++) {
                    final int partition = rand.nextInt(10);
                    final MessageStore store =
                            JournalTransactionStoreUnitTest.this.messageStoreManager.getOrCreateMessageStore("topic1",
                                partition % 10);
                    JournalTransactionStoreUnitTest.this.transactionStore.addMessage(store, 1, new PutCommand("topic1",
                        partition, ("msg" + id).getBytes(), xid, 0, 1), null);
                }
                if (id % 100 == 0) {
                    JournalTransactionStoreUnitTest.this.journalStore.checkpoint();
                }
                // commit
                JournalTransactionStoreUnitTest.this.transactionStore.commit(xid, false);

            }
        });

        testCase.start();

        System.out.println("����ʱ�䣺" + testCase.getDurationInMillis() + "ms");

        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", i);
            assertTrue(store.getSizeInBytes() > 0);
        }
        assertEquals(0, this.transactionStore.getActiveTransactionCount());

        // �رմ�
        this.tearDown();
        final long start = System.currentTimeMillis();
        this.init(this.path);
        System.out.println("�ָ�����ʱ��:" + (System.currentTimeMillis() - start) + "ms");
        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", i);
            assertTrue(store.getSizeInBytes() > 0);
        }
        assertEquals(0, this.transactionStore.getActiveTransactionCount());
    }
View Full Code Here

            for (int i = 0; i < 10000; i++) {
                final LocalTransactionId xid = new LocalTransactionId("test", i);
                // �漴��Ӽ�����Ϣ
                for (int j = 0; j < rand.nextInt(3) + 1; j++) {
                    final int partition = rand.nextInt(10);
                    final MessageStore store =
                            this.messageStoreManager.getOrCreateMessageStore("topic1", partition % 10);
                    this.transactionStore.addMessage(store, 1,
                        new PutCommand("topic1", partition, ("msg" + i).getBytes(), xid, 0, 1), null);
                }
                // commit
View Full Code Here

            final LocalTransactionId xid = new LocalTransactionId("test", i);

            // �漴��Ӽ�����Ϣ
            for (int j = 0; j < rand.nextInt(3) + 1; j++) {
                final int partition = rand.nextInt(10);
                final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", partition % 10);
                this.transactionStore.addMessage(store, 1, new PutCommand("topic1", partition, ("msg" + i).getBytes(),
                    xid, 0, 1), null);
            }
            if (i % 100 == 0) {
                this.journalStore.checkpoint();
            }
            // commit
            this.transactionStore.commit(xid, false);
            if (i % 77 == 0) {
                this.journalStore.checkpoint();
            }
        }

        // �رմ�
        this.tearDown();
        final long start = System.currentTimeMillis();
        this.init(this.path);
        System.out.println("�ָ�����ʱ��:" + (System.currentTimeMillis() - start));
        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", i);
            assertTrue(store.getSizeInBytes() > 0);
        }
        assertEquals(0, this.transactionStore.getActiveTransactionCount());
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.server.store.MessageStore

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.