Package com.taobao.metamorphosis.server.store

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



    @Test
    public void testAddAddCommit_CloseReplayAppend_CloseRecover() 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);
        assertNotNull(this.transactionStore.getInflyTx(xid));

        // commit
        this.transactionStore.commit(xid, false);
        store.flush();
        final long sizeInBytes = store.getSizeInBytes();
        assertTrue(sizeInBytes > 0);
        this.assertMessages(store);

        this.tearDown();
        // delete data
        System.out.println("ɾ��Ŀ¼:" + this.path + File.separator + store.getDescription());
        FileUtils.deleteDirectory(new File(this.path + File.separator + store.getDescription()));
        this.init(this.path);

        // Ӧ���طŲ���������,ȷ��������ȷ
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertTrue(store.getSizeInBytes() > 0);
        assertEquals(sizeInBytes, store.getSizeInBytes());
        this.assertMessages(store);
        assertNull(this.transactionStore.getInflyTx(xid));

        // �ٴιرմ򿪣�״̬��ȷ
        this.tearDown();
        this.init(this.path);
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        assertTrue(store.getSizeInBytes() > 0);
        assertEquals(sizeInBytes, store.getSizeInBytes());
        this.assertMessages(store);
        assertNull(this.transactionStore.getInflyTx(xid));

    }
View Full Code Here


    public void testHandleRequestNormal() throws Exception {
        final int partition = 1;
        final int opaque = 0;
        final long offset = 1024;
        final long resultOffset = 1536;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        EasyMock.expect(store.getNearestOffset(offset)).andReturn(resultOffset);
        this.conn.response(new BooleanCommand(HttpStatus.Success, String.valueOf(resultOffset), opaque));
        this.mocksControl.replay();
        this.offsetProcessor.handleRequest(new OffsetCommand(this.topic, this.group, partition, offset, opaque),
            this.conn);
        this.mocksControl.verify();
View Full Code Here

        final long offset = 1024L;
        final byte[] data = new byte[1024];
        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request = new PutCommand(this.topic, partition, data, null, flag, opaque);
        final long msgId = 100000L;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        EasyMock.expect(this.storeManager.getOrCreateMessageStore(this.topic, partition)).andReturn(store);
        final BooleanCommand expectResp =
                new BooleanCommand(HttpStatus.Success, msgId + " " + partition + " " + offset, opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        final PutCallback cb = new PutCallback() {

            @Override
            public void putComplete(final ResponseCommand resp) {
                invoked.set(true);
                if (!expectResp.equals(resp)) {
                    throw new RuntimeException();
                }
            }
        };
        store.append(msgId, request,
            this.commandProcessor.new StoreAppendCallback(partition, this.metaConfig.getBrokerId() + "-" + partition,
                request, msgId, cb));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
View Full Code Here

        final int opaque = -1;
        final byte[] data = new byte[1024];
        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request = new PutCommand(this.topic, partition, data, null, flag, opaque);
        final long msgId = 100000L;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        EasyMock.expect(this.storeManager.getOrCreateMessageStore(this.topic, partition)).andReturn(store);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        final BooleanCommand expectResp =
                new BooleanCommand(HttpStatus.InternalServerError,
                    "Put message to [broker 'meta://localhost:8123'] [partition 'PutProcessorUnitTest-1'] failed.",
                    request.getOpaque());
        final PutCallback cb = new PutCallback() {

            @Override
            public void putComplete(final ResponseCommand resp) {
                invoked.set(true);
                System.out.println(((BooleanCommand) resp).getErrorMsg());
                if (!expectResp.equals(resp)) {
                    throw new RuntimeException();
                }
            }
        };
        store.append(msgId, request,
            this.commandProcessor.new StoreAppendCallback(partition, this.metaConfig.getBrokerId() + "-" + partition,
                request, msgId, cb));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
View Full Code Here

        final int partition = 1;
        final int opaque = 0;
        final int maxSize = -1;
        this.metaConfig.setMaxTransferSize(1024);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(
            new MessageStore(this.topic, partition, this.metaConfig, null));
        this.conn
        .response(new BooleanCommand(HttpStatus.BadRequest, "Bad request,invalid max size:" + maxSize, opaque));
        EasyMock.expectLastCall();
        this.mocksControl.replay();
View Full Code Here

    public void testHandleRequestEquelsMaxOffsetSliceNull() throws Exception {
        final int partition = 1;
        final int opaque = 0;
        final int maxSize = 1024;
        final long offset = 10;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        EasyMock.expect(store.slice(offset, maxSize)).andReturn(null);
        this.conn.response(new BooleanCommand(HttpStatus.NotFound, "Could not find message at position "
                + offset, opaque));
        EasyMock.expect(store.getMaxOffset()).andReturn(offset);
        EasyMock.expectLastCall();
        this.mocksControl.replay();

        final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
        this.getProcessor.handleRequest(request, this.conn);
View Full Code Here

    public void testHandleRequestGreatThanMaxOffsetSliceNull() throws Exception {
        final int partition = 1;
        final int opaque = 0;
        final int maxSize = 1024;
        final long offset = 10;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        EasyMock.expect(store.slice(offset, maxSize)).andReturn(null);
        this.conn.response(new BooleanCommand(HttpStatus.NotFound, "Could not find message at position "
                + offset, opaque));
        EasyMock.expect(store.getMaxOffset()).andReturn(offset - 1);
        EasyMock.expectLastCall();
        this.mocksControl.replay();

        final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
        this.getProcessor.handleRequest(request, this.conn);
View Full Code Here

        final int partition = 1;
        final int opaque = 0;
        final int maxSize = 1024;
        final long offset = Long.MAX_VALUE;
        final long realMaxOffset = 100;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        EasyMock.expect(store.slice(offset, maxSize)).andReturn(null);
        this.conn.response(new BooleanCommand(HttpStatus.Moved, String.valueOf(realMaxOffset), opaque));
        EasyMock.expect(store.getMaxOffset()).andReturn(realMaxOffset);
        EasyMock.expectLastCall();
        this.mocksControl.replay();

        final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
        this.getProcessor.handleRequest(request, this.conn);
View Full Code Here

        final int partition = 1;
        final int opaque = 0;
        final int maxSize = 1024;
        final long offset = 10;
        final long newOffset = 512;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        EasyMock.expect(store.slice(offset, maxSize)).andThrow(new ArrayIndexOutOfBoundsException());
        EasyMock.expect(store.getNearestOffset(offset)).andReturn(newOffset);
        this.conn.response(new BooleanCommand(HttpStatus.Moved, String.valueOf(newOffset), opaque));
        EasyMock.expectLastCall();
        this.mocksControl.replay();

        final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
View Full Code Here

    public void testHandleRequestNormal() throws Exception {
        final int partition = 1;
        final int opaque = 0;
        final int maxSize = 1024;
        final long offset = 10;
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
        final MessageSet set = this.mocksControl.createMock(MessageSet.class);
        EasyMock.expect(store.slice(offset, maxSize)).andReturn(set);
        final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
        set.write(request, this.sessionContext);
        EasyMock.expectLastCall();
        this.mocksControl.replay();
View Full Code Here

TOP

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

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.