diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleConfigLoader.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleConfigLoader.java index afda1299f..42238dc84 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleConfigLoader.java +++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleConfigLoader.java @@ -19,7 +19,7 @@ package org.skywalking.apm.collector.core.module; import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.Reader; import java.util.Map; import org.skywalking.apm.collector.core.config.ConfigLoader; import org.skywalking.apm.collector.core.framework.DefineException; @@ -39,8 +39,8 @@ public class ModuleConfigLoader implements ConfigLoader> { Yaml yaml = new Yaml(); try { try { - FileReader applicationFileReader = ResourceUtils.read("application.yml"); - return (Map)yaml.load(applicationFileReader); + Reader applicationReader = ResourceUtils.read("application.yml"); + return (Map)yaml.load(applicationReader); } catch (FileNotFoundException e) { logger.info("Could not found application.yml file, use default"); return (Map)yaml.load(ResourceUtils.read("application-default.yml")); diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java index 3c86ac494..0ec0f83a4 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java +++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java @@ -18,9 +18,10 @@ package org.skywalking.apm.collector.core.util; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.net.URL; /** @@ -28,12 +29,12 @@ import java.net.URL; */ public class ResourceUtils { - public static FileReader read(String fileName) throws FileNotFoundException { + public static Reader read(String fileName) throws FileNotFoundException { URL url = ResourceUtils.class.getClassLoader().getResource(fileName); if (url == null) { throw new FileNotFoundException("file not found: " + fileName); } - File file = new File(ResourceUtils.class.getClassLoader().getResource(fileName).getFile()); - return new FileReader(file); + InputStream inputStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName); + return new InputStreamReader(inputStream); } } diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleConfigLoaderTestCase.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleConfigLoaderTestCase.java new file mode 100644 index 000000000..546e39dcd --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleConfigLoaderTestCase.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.module; + +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.skywalking.apm.collector.core.framework.DefineException; + +/** + * @author neeuq + */ +public class ModuleConfigLoaderTestCase { + + @SuppressWarnings({ "rawtypes" }) + @Test + public void testLoad() throws DefineException { + ModuleConfigLoader configLoader = new ModuleConfigLoader(); + Map configuration = configLoader.load(); + Assert.assertNotNull(configuration.get("cluster")); + Assert.assertNotNull(configuration.get("cluster").get("zookeeper")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/utils/ResourceUtilsTestCase.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/utils/ResourceUtilsTestCase.java new file mode 100644 index 000000000..851050c11 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/utils/ResourceUtilsTestCase.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.utils; + +import java.io.IOException; +import java.io.Reader; + +import org.junit.Assert; +import org.junit.Test; +import org.skywalking.apm.collector.core.util.ResourceUtils; + +/** + * @author neeuq + */ +public class ResourceUtilsTestCase { + + @Test + public void testRead() throws IOException { + Reader reader = ResourceUtils.read("application.yml"); + Assert.assertNotNull(reader); + reader.close(); + } + +}