Package com.taobao.metamorphosis.network

Examples of com.taobao.metamorphosis.network.PutCommand


        final int partition = 1;
        final int opaque = -1;
        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, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        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();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
                    .create(offset, 1024));
                return null;
            }

        });
        this.remotingClient.sendToGroup(this.slaveUrl, new SyncCommand(request.getTopic(), partition,
            request.getData(), request.getFlag(), msgId, CheckSum.crc32(data), OpaqueGenerator.getNextOpaque()), apdcb,
            this.commandProcessor.getSendToSlaveTimeoutInMills(), TimeUnit.MILLISECONDS);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
View Full Code Here


        final int partition = 1;
        final int opaque = -1;
        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;
        // Slave is disconnected
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(false);
        final BooleanCommand expectResp =
                new BooleanCommand(HttpStatus.InternalServerError, "Slave is disconnected ", opaque);
View Full Code Here

        final int partition = 1;
        final int opaque = -1;
        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, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        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.InternalServerError,
                    "Put message to [slave 'meta://localhost:8124'] [partition 'SamsaCommandProcessorUnitTest-1'] failed",
                    opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        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();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
                    .create(offset, 1024));
                return null;
            }

        });
        this.remotingClient.sendToGroup(this.slaveUrl, new SyncCommand(request.getTopic(), partition,
            request.getData(), request.getFlag(), msgId, CheckSum.crc32(data), OpaqueGenerator.getNextOpaque()), apdcb,
            this.commandProcessor.getSendToSlaveTimeoutInMills(), TimeUnit.MILLISECONDS);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
View Full Code Here

        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);// .times(3);
        OpaqueGenerator.resetOpaque();
        final int flag = MessageFlagUtils.getFlag(null);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data), null,
                    Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                        new BooleanCommand(500, "server error", Integer.MIN_VALUE));
        // EasyMock.expect(
        // this.remotingClient.invokeToGroup(url, new PutCommand(topic,
        // partition.getPartition(), data, null, flag,
View Full Code Here

                partition);
            EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
            OpaqueGenerator.resetOpaque();
            final int flag = MessageFlagUtils.getFlag(null);
            EasyMock.expect(
                this.remotingClient.invokeToGroup(url, new PutCommand(topic, partition.getPartition(), data, flag,
                    CheckSum.crc32(data), null, Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andThrow(
                        new InterruptedException());
            this.mocksControl.replay();
            this.producer.sendMessage(message);
        }
View Full Code Here

        final int partition = 1;
        final int opaque = -1;
        final long offset = -1;
        final byte[] data = new byte[1024];
        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request =
                new PutCommand(this.topic, partition, data, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        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.InternalServerError,
                    "Put message to [master 'meta://localhost:8123'] [partition 'SamsaCommandProcessorUnitTest-1'] failed",
                    opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        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();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
                    .create(offset, 1024));
                return null;
            }

        });
        this.remotingClient.sendToGroup(this.slaveUrl, new SyncCommand(request.getTopic(), partition,
            request.getData(), request.getFlag(), msgId, CheckSum.crc32(data), OpaqueGenerator.getNextOpaque()), apdcb,
            this.commandProcessor.getSendToSlaveTimeoutInMills(), TimeUnit.MILLISECONDS);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
View Full Code Here

public class MessageUtilsUnitTest {
    @Test
    public void testMakeBufferDecode() throws Exception {
        final long msgId = 10000L;
        final String topic = "test";
        final PutCommand req = new PutCommand(topic, 1, "hello".getBytes(), null, 0, -1);
        final ByteBuffer buf = MessageUtils.makeMessageBuffer(msgId, req);

        final DecodedMessage decodedMsg = MessageUtils.decodeMessage(topic, buf.array(), 0);
        assertNotNull(decodedMsg);
        assertEquals(topic, decodedMsg.message.getTopic());
View Full Code Here

        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
        EasyMock.expect(this.localMessageStorageManager.getMessageCount(topic, partition)).andReturn(0);
        OpaqueGenerator.resetOpaque();
        final int flag = MessageFlagUtils.getFlag(null);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url, new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data),
                null, Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                    new BooleanCommand(200, "1111 1 1024", Integer.MIN_VALUE));
        this.mocksControl.replay();
        assertEquals(0, message.getId());
        final SendResult sendResult = this.producer.sendMessage(message);
View Full Code Here


    private int appendMsg(final int number, final long offset, final TxCommand cmd, final DataFile dataFile)
            throws InvalidProtocolBufferException, IOException {
        final AppendMessageCommand appendCmd = AppendMessageCommand.parseFrom(cmd.getCmdContent());
        final PutCommand putCmd =
                (PutCommand) decoer.decode(IoBuffer.wrap(appendCmd.getPutCommand().toByteArray()), null);
        final MessageStore store = this.storeManager.getOrCreateMessageStore(putCmd.getTopic(), putCmd.getPartition());

        if (this.transactionStore.getInflyTx(putCmd.getTransactionId()) == null) {
            dataFile.increment();
        }
        this.transactionStore.addMessage(store, appendCmd.getMessageId(), putCmd, new JournalLocation(number, offset));
        return 0;
    }
View Full Code Here

                // ��һ�η��ͣ���Ҫ��������
                this.beforeSendMessageFirstTime(serverUrl);
            }

            final int flag = MessageFlagUtils.getFlag(message);
            final PutCommand putCommand =
                    new PutCommand(topic, partition.getPartition(), encodedData, flag, CheckSum.crc32(encodedData),
                        this.getTransactionId(), OpaqueGenerator.getNextOpaque());
            final BooleanCommand resp = this.invokeToGroup(serverUrl, partition, putCommand, message, timeout, unit);
            return this.genSendResult(message, partition, serverUrl, resp);
        }
        catch (final TimeoutException e) {
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.network.PutCommand

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.