Package com.taobao.metamorphosis.network

Examples of com.taobao.metamorphosis.network.BooleanCommand


        if ("config".equals(item)) {
            return this.processStatsConfig(request, ctx);
        }
        else {
            final String statsInfo = this.statsManager.getStatsInfo(item);
            return new BooleanCommand(HttpStatus.Success, statsInfo, request.getOpaque());
        }
    }
View Full Code Here


                }
            }, 5000, TimeUnit.MILLISECONDS);
        }
        catch (FileNotFoundException e) {
            log.error("Config file not found:" + this.metaConfig.getConfigFilePath(), e);
            return new BooleanCommand(HttpStatus.InternalServerError, "Config file not found:"
                    + this.metaConfig.getConfigFilePath(), request.getOpaque());
        }
        catch (IOException e) {
            log.error("IOException while stats config", e);
            return new BooleanCommand(HttpStatus.InternalServerError, "Read config file error:" + e.getMessage(),
                request.getOpaque());
        }
        catch (NotifyRemotingException e) {
            log.error("NotifyRemotingException while stats config", e);
        }
View Full Code Here

            if (location.isValid()) {
                final String resultStr =
                        BrokerCommandProcessor.this.genPutResultString(this.partition, this.messageId,
                            location.getOffset());
                if (this.cb != null) {
                    this.cb.putComplete(new BooleanCommand(HttpStatus.Success, resultStr, this.request.getOpaque()));
                }
            }
            else {
                BrokerCommandProcessor.this.statsManager.statsPutFailed(this.request.getTopic(), this.partitionString,
                    1);
                if (this.cb != null) {
                    String error = BrokerCommandProcessor.this.genErrorMessage(this.request.getTopic(), this.partition);
                    this.cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError, error, this.request
                        .getOpaque()));
                }
            }

        }
View Full Code Here

                            RemotingUtils.response(context.getConnection(), resp);
                        }
                    });
                }
                catch (final Exception e) {
                    RemotingUtils.response(context.getConnection(), new BooleanCommand(HttpStatus.InternalServerError,
                        e.getMessage(), request.getOpaque()));
                }

            }
View Full Code Here

    @Test
    public void testLoad_fromMaster() throws Exception {
        final String topic = "topictest";
        final int partition = 1;
        final String masterUrl = "meta://testhost:8123";
        final BooleanCommand resp = new BooleanCommand(HttpStatus.Success, "555", 0);
        // EasyMock.expect(this.broker.getCommandProcessor()).andReturn(this.brokerCommandProcessor).anyTimes();
        EasyMock.expect(this.broker.getStoreManager()).andReturn(this.storeManager);
        EasyMock.expect(this.storeManager.getMessageStore(topic, partition)).andReturn(null);
        EasyMock.expect(this.slaveZooKeeper.getMasterServerUrl()).andReturn(masterUrl);
        EasyMock.expect(this.remotingClient.isConnected(masterUrl)).andReturn(true);
View Full Code Here

    @Test
    public void testLoad_failQuery() throws Exception {
        final String topic = "topictest";
        final int partition = 1;
        final String masterUrl = "meta://testhost:8123";
        final BooleanCommand resp = new BooleanCommand(HttpStatus.NotFound, "", 0);
        // EasyMock.expect(this.broker.getCommandProcessor()).andReturn(this.brokerCommandProcessor).anyTimes();
        EasyMock.expect(this.broker.getStoreManager()).andReturn(this.storeManager);
        EasyMock.expect(this.storeManager.getMessageStore(topic, partition)).andReturn(null);
        EasyMock.expect(this.slaveZooKeeper.getMasterServerUrl()).andReturn(masterUrl);
        EasyMock.expect(this.remotingClient.isConnected(masterUrl)).andReturn(true);
View Full Code Here

        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 {
                ((SingleRequestCallBackListener) EasyMock.getCurrentArguments()[2]).onResponse(new BooleanCommand(
                    HttpStatus.Success, null, OpaqueGenerator.getNextOpaque()), SamsaCommandProcessorUnitTest.this.conn);
                return null;
            }

        });
View Full Code Here

        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);
        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();
                }
            }
        };
        this.brokerZooKeeper.registerTopicInZk(this.topic, false);
View Full Code Here

        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 {
                ((SingleRequestCallBackListener) EasyMock.getCurrentArguments()[2]).onResponse(new BooleanCommand(
                    HttpStatus.InternalServerError, "Put to slave failed", OpaqueGenerator.getNextOpaque()),
                    SamsaCommandProcessorUnitTest.this.conn);
                return null;
            }
View Full Code Here

        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 {
                ((SingleRequestCallBackListener) EasyMock.getCurrentArguments()[2]).onResponse(new BooleanCommand(
                    HttpStatus.Success, null, OpaqueGenerator.getNextOpaque()), SamsaCommandProcessorUnitTest.this.conn);
                return null;
            }

        });
View Full Code Here

TOP

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

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.