org.apache.rocketmq.namesrv.NamesrvController Java Examples

The following examples show how to use org.apache.rocketmq.namesrv.NamesrvController. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultRequestProcessorTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #2
Source File: DefaultRequestProcessorTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(InternalLogger.class);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #3
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(nextPort());
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed", e);
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #4
Source File: IntegrationTestBase.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #5
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #6
Source File: IntegrationTestBase.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #7
Source File: DefaultRequestProcessorTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(InternalLogger.class);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #8
Source File: IntegrationTestBase.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #9
Source File: DefaultRequestProcessorTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(InternalLogger.class);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #10
Source File: IntegrationTestBase.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #11
Source File: DefaultRequestProcessorTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #12
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #13
Source File: IntegrationTestBase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #14
Source File: DefaultRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #15
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #16
Source File: IntegrationTestBase.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #17
Source File: ClusterTestRequestProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) {
    super(namesrvController);
    this.productEnvName = productEnvName;
    adminExt = new DefaultMQAdminExt();
    adminExt.setInstanceName("CLUSTER_TEST_NS_INS_" + productEnvName);
    adminExt.setUnitName(productEnvName);
    try {
        adminExt.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
Example #18
Source File: ClusterTestRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
 
Example #19
Source File: AbstractTestCase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
/**
 * Start rocketmq name server
 * @throws Exception
 */
private static void startNamesrv() throws Exception {

    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(9876);

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);
    boolean initResult = namesrvController.initialize();
    if (!initResult) {
        namesrvController.shutdown();
        throw new Exception();
    }
    namesrvController.start();
}
 
Example #20
Source File: BrokerHousekeepingServiceTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );
    brokerHousekeepingService = new BrokerHousekeepingService(namesrvController);
}
 
Example #21
Source File: ClusterTestRequestProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
 
Example #22
Source File: ClusterTestRequestProcessor.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) {
    super(namesrvController);
    this.productEnvName = productEnvName;
    adminExt = new DefaultMQAdminExt();
    adminExt.setInstanceName("CLUSTER_TEST_NS_INS_" + productEnvName);
    adminExt.setUnitName(productEnvName);
    try {
        adminExt.start();
    } catch (MQClientException e) {
        log.error("Failed to start processor", e);
    }
}
 
Example #23
Source File: BrokerHousekeepingServiceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );
    brokerHousekeepingService = new BrokerHousekeepingService(namesrvController);
}
 
Example #24
Source File: ClusterTestRequestProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) {
    super(namesrvController);
    this.productEnvName = productEnvName;
    adminExt = new DefaultMQAdminExt();
    adminExt.setInstanceName("CLUSTER_TEST_NS_INS_" + productEnvName);
    adminExt.setUnitName(productEnvName);
    try {
        adminExt.start();
    } catch (MQClientException e) {
        log.error("Failed to start processor", e);
    }
}
 
Example #25
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override public void run() {
    for (NamesrvController namesrvController : NAMESRV_CONTROLLERS) {
        if (namesrvController != null) {
            namesrvController.shutdown();
        }
    }
    for (BrokerController brokerController : BROKER_CONTROLLERS) {
        if (brokerController != null) {
            brokerController.shutdown();
        }
    }
    for (File file : TMPE_FILES) {
        deleteFile(file);
    }
}
 
Example #26
Source File: ClusterTestRequestProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
 
Example #27
Source File: BrokerHousekeepingServiceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );
    brokerHousekeepingService = new BrokerHousekeepingService(namesrvController);
}
 
Example #28
Source File: NamesrvControllerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * namesrv 启动
 */
@Test
public void testStart() throws Exception {
    final NamesrvConfig namesrvConfig = new NamesrvConfig();
    final NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(9876);
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);
    namesrvController.initialize();
    namesrvController.start();
    Thread.sleep(DateUtils.MILLIS_PER_DAY);
}
 
Example #29
Source File: ClusterTestRequestProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) {
    super(namesrvController);
    this.productEnvName = productEnvName;
    adminExt = new DefaultMQAdminExt();
    adminExt.setInstanceName("CLUSTER_TEST_NS_INS_" + productEnvName);
    adminExt.setUnitName(productEnvName);
    try {
        adminExt.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: ClusterTestRequestProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}