Skip to content

Commit

Permalink
[ISSUE apache#3949] Add UT for configuration package.
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopjin authored and drpmma committed Apr 28, 2022
1 parent b16d308 commit 3e12d43
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.commons.lang3.StringUtils;

public class ConfigurationManager {
private static final String RMQ_PROXY_HOME = "RMQ_PROXY_HOME";
private static final String DEFAULT_RMQ_PROXY_HOME = System.getProperty("user.home") + File.separator + "rmq-proxy";
protected static final String RMQ_PROXY_HOME = "RMQ_PROXY_HOME";
protected static final String DEFAULT_RMQ_PROXY_HOME = System.getProperty("user.home") + File.separator + "rmq-proxy";
private static String proxyHome;
private static Configuration configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@

public interface StartAndShutdown {
void start() throws Exception;

void shutdown() throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.proxy.configuration;

import java.net.URL;
import org.apache.rocketmq.proxy.grpc.common.ProxyMode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.apache.rocketmq.proxy.configuration.ConfigurationManager.RMQ_PROXY_HOME;
import static org.assertj.core.api.Assertions.assertThat;

public class ConfigurationManagerTest {
public String mockProxyHome = "/mock/rmq/proxy/home";

@Before
public void before() throws Exception {
URL mockProxyHomeURL = getClass().getClassLoader().getResource("rmq-proxy-home");
if (mockProxyHomeURL != null) {
mockProxyHome = mockProxyHomeURL.toURI().getPath();
}
System.setProperty(RMQ_PROXY_HOME, mockProxyHome);
ConfigurationManager.initEnv();
ConfigurationManager.intConfig();
}

@After
public void after() {
System.clearProperty(RMQ_PROXY_HOME);
}

@Test
public void testInitEnv() {
// configure proxy home by system env.
assertThat(ConfigurationManager.getProxyHome()).isEqualTo(mockProxyHome);
}

@Test
public void testIntConfig() {
assertThat(ConfigurationManager.getProxyConfig()).isNotNull();
assertThat(ConfigurationManager.getProxyConfig().getProxyMode()).isEqualToIgnoringCase(ProxyMode.CLUSTER.toString());

String brokerConfig = ConfigurationManager.getProxyConfig().getBrokerConfigPath();
assertThat(brokerConfig).isEqualTo(ConfigurationManager.getProxyHome() + "/conf/broker.conf");
}

@Test
public void testGetProxyHome() {
// test configured proxy home
assertThat(ConfigurationManager.getProxyHome()).isEqualTo(mockProxyHome);
}

@Test
public void testGetProxyConfig() {
assertThat(ConfigurationManager.getProxyConfig()).isNotNull();
}

}
22 changes: 22 additions & 0 deletions proxy/src/test/resources/rmq-proxy-home/conf/broker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
3 changes: 3 additions & 0 deletions proxy/src/test/resources/rmq-proxy-home/conf/rmq-proxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"proxyMode": "cluster"
}

0 comments on commit 3e12d43

Please sign in to comment.