@Test
  public void testSlaveAsMaster() throws Exception {
    // 先发送100条消息到master和slave
    // start slave
    this.testOneMasterOneSlaveOneProducerOneConsumer();
    try {
      this.stopMasterSlave();
      this.queue.clear();
      Thread.sleep(5000);
      // 然后slave作为master启动,master作为slave启动,再发送100条
      this.slave =
          this.startEnhanceBroker("samsa_server1", false, false, this.getSlaveProperties());
      final Map<String, Properties> masterProperties = this.getMasterProperties();
      // 现在slave是8123端口
      masterProperties.get("samsa").put("slave", "localhost:8123");
      this.master = this.startEnhanceBroker("gregor_server1", false, false, masterProperties);
      // 等待producer和consumer重连
      Thread.sleep(2000);
      final byte[] data = "testSlaveAsMaster".getBytes();
      this.createProducer();
      this.producer.publish(this.topic);
      this.sendMessage(100, data, this.topic);
      final String group = "GregorMasterSlaveTest";
      this.createConsumer(group);
      this.subscribe(this.topic, 1024 * 1024, 100);

    } finally {
      Utils.shutdown(this.producer);
      Utils.shutdown(this.consumer);
      Utils.shutdown(this.producerList);
      Utils.shutdown(this.consumerList);
    }
  }
 @Test
 public void testOneMasterOneSlaveNProducerNConsumer() throws Exception {
   // start slave
   this.slave = this.startEnhanceBroker("gregor_server1", true, true, this.getSlaveProperties());
   // start master
   this.master = this.startEnhanceBroker("samsa_server1", true, true, this.getMasterProperties());
   try {
     this.create_nProducer(10);
     this.sendMessage_nProducer(100, "testOneMasterOneSlaveNProducerNConsumer", this.topic, 10);
     this.subscribe_nConsumer(this.topic, 1024 * 1024, 100, 10, 10);
     // this.subscribe(this.topic, 1024 * 1024, 100);
   } finally {
     Utils.shutdown(this.producerList);
     Utils.shutdown(this.consumerList);
   }
 }
  @Override
  @After
  public void tearDown() throws Exception {
    int count = 0;
    count = Utils.shutdown(this.producer);
    this.log.info(count > 0 ? count : "No" + " producer have been shutdown");

    count = Utils.shutdown(this.consumer);
    this.log.info(count > 0 ? count : "No" + " producer have been shutdown");

    count = Utils.shutdown(super.producerList);
    this.log.info(count + " producers have been shutdown");

    count = Utils.shutdown(super.consumerList);
    this.log.info(count + " consumers have been shutdown");

    super.tearDown();
    this.stopMasterSlave();
  }
 protected EnhancedBroker startEnhanceBroker(
     final String name,
     final boolean isClearConsumerInfo,
     final boolean isClearMsg,
     final Map<String, Properties> pluginsInfo)
     throws Exception {
   final MetaConfig metaConfig = this.metaConfig(name);
   if (isClearMsg) {
     Utils.clearDataDir(metaConfig);
   }
   final EnhancedBroker broker = new EnhancedBroker(metaConfig, pluginsInfo);
   if (isClearConsumerInfo) {
     Utils.clearConsumerInfoInZk(
         broker.getBroker().getBrokerZooKeeper().getZkClient(),
         broker.getBroker().getBrokerZooKeeper().getMetaZookeeper());
   }
   broker.start();
   // this.slaveBrokers.add(broker);
   return broker;
 }