From 051527d44a758ba25b497dd30ba800f9b06ca823 Mon Sep 17 00:00:00 2001 From: Zhanhui Li Date: Wed, 12 Apr 2017 22:25:11 +0800 Subject: [PATCH] BugFix: WS_DOMAIN_NAME, SUBGROUP default values override custom values passed by java options options --- broker/pom.xml | 13 ++++++ .../apache/rocketmq/broker/BrokerStartup.java | 6 +-- .../rocketmq/broker/BrokerStartupTest.java | 40 +++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 broker/src/test/java/org/apache/rocketmq/broker/BrokerStartupTest.java diff --git a/broker/pom.xml b/broker/pom.xml index 4d0aae65..8cdafea3 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -65,4 +65,17 @@ javassist + + + + + maven-surefire-plugin + 2.19.1 + + 1 + false + + + + diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java index 39ee8dd2..98ff1365 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java @@ -232,12 +232,10 @@ public class BrokerStartup { private static void properties2SystemEnv(Properties properties) { if (properties == null) { - log.info("No properties to set system environment"); return; } - - String rmqAddressServerDomain = properties.getProperty("rmqAddressServerDomain", MixAll.DEFAULT_NAMESRV_ADDR_LOOKUP); - String rmqAddressServerSubGroup = properties.getProperty("rmqAddressServerSubGroup", "nsaddr"); + String rmqAddressServerDomain = properties.getProperty("rmqAddressServerDomain", MixAll.WS_DOMAIN_NAME); + String rmqAddressServerSubGroup = properties.getProperty("rmqAddressServerSubGroup", MixAll.WS_DOMAIN_SUBGROUP); System.setProperty("rocketmq.namesrv.domain", rmqAddressServerDomain); System.setProperty("rocketmq.namesrv.domain.subgroup", rmqAddressServerSubGroup); } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerStartupTest.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerStartupTest.java new file mode 100644 index 00000000..a5ad3ac3 --- /dev/null +++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerStartupTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.broker; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Properties; +import org.junit.Assert; +import org.junit.Test; + +public class BrokerStartupTest { + + @Test + public void testProperties2SystemEnv() throws NoSuchMethodException, InvocationTargetException, + IllegalAccessException { + Properties properties = new Properties(); + Class clazz = BrokerStartup.class; + Method method = clazz.getDeclaredMethod("properties2SystemEnv", Properties.class); + method.setAccessible(true); + System.setProperty("rocketmq.namesrv.domain", "value"); + method.invoke(null, properties); + Assert.assertEquals("value", System.getProperty("rocketmq.namesrv.domain")); + } + +} \ No newline at end of file -- GitLab