From d8c0d52ef5eef95ea891b2290fed70053c1165f6 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sun, 15 Oct 2017 09:00:25 +0800 Subject: [PATCH 1/4] Fix the component name. Relate to https://github.com/OpenSkywalking/skywalking-ui/pull/75 --- .../apm/network/trace/component/ComponentsDefine.java | 6 +++--- .../plugin/spymemcached/v2/MemcachedMethodInterceptor.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java index 672d6d14f..0582108bf 100644 --- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -63,7 +63,7 @@ public class ComponentsDefine { public static final OfficialComponent JETTY_SERVER = new OfficialComponent(19, "JettyServer"); - public static final OfficialComponent MEMCACHE = new OfficialComponent(20, "Memcache"); + public static final OfficialComponent MEMCACHED = new OfficialComponent(20, "Memcached"); public static final OfficialComponent SHARDING_JDBC = new OfficialComponent(21, "ShardingJDBC"); @@ -96,7 +96,7 @@ public class ComponentsDefine { addComponent(NUTZ_HTTP); addComponent(JETTY_CLIENT); addComponent(JETTY_SERVER); - addComponent(MEMCACHE); + addComponent(MEMCACHED); addComponent(SHARDING_JDBC); } @@ -111,4 +111,4 @@ public class ComponentsDefine { return components[componentId]; } } -} \ No newline at end of file +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java index cac14c777..3bdfd8802 100644 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java @@ -37,8 +37,8 @@ public class MemcachedMethodInterceptor implements InstanceMethodsAroundIntercep Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan(SPY_MEMCACHE + method.getName(), peer); - span.setComponent(ComponentsDefine.MEMCACHE); - Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHE.getName()); + span.setComponent(ComponentsDefine.MEMCACHED); + Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName()); SpanLayer.asDB(span); Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); } From 8bf5e00c3cc6fb9acd0a1e742d5b4c81a6da76f7 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sun, 15 Oct 2017 09:20:52 +0800 Subject: [PATCH 2/4] Fix test case. --- .../plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java index 17f1885ea..d7cbdd862 100644 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java @@ -112,7 +112,7 @@ public class MemcachedMethodInterceptorTest { assertThat(span.isExit(), is(true)); assertThat(SpanHelper.getComponentId(span), is(20)); List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("Memcache")); + assertThat(tags.get(0).getValue(), is("Memcached")); assertThat(tags.get(1).getValue(), is("set OperationKey")); assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); } From 9a574641fef31e8e57a2758feee853020b3bfb22 Mon Sep 17 00:00:00 2001 From: neeuq Date: Tue, 17 Oct 2017 09:45:33 +0800 Subject: [PATCH 3/4] fixed bug:ResourceUtils can't read resoucre from jar. --- .../core/module/ModuleConfigLoader.java | 6 +++--- .../collector/core/util/ResourceUtils.java | 11 ++++++----- .../module/ModuleConfigLoaderTestCase.java | 19 +++++++++++++++++++ .../core/utils/ResourceUtilsTestCase.java | 19 +++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleConfigLoaderTestCase.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/utils/ResourceUtilsTestCase.java 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..eb878f57a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleConfigLoaderTestCase.java @@ -0,0 +1,19 @@ +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; + +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..8aecf5d94 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/utils/ResourceUtilsTestCase.java @@ -0,0 +1,19 @@ +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; + +public class ResourceUtilsTestCase { + + @Test + public void testRead() throws IOException { + Reader reader = ResourceUtils.read("application.yml"); + Assert.assertNotNull(reader); + reader.close(); + } + +} From a081c4b1ca64485c6880d3e80d75f4e7fb4111cb Mon Sep 17 00:00:00 2001 From: neeuq Date: Tue, 17 Oct 2017 10:08:21 +0800 Subject: [PATCH 4/4] format unit case for maven-checkstyle-plugin --- .../module/ModuleConfigLoaderTestCase.java | 35 +++++++++++++++---- .../core/utils/ResourceUtilsTestCase.java | 21 +++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) 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 index eb878f57a..546e39dcd 100644 --- 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 @@ -1,3 +1,21 @@ +/* + * 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; @@ -6,14 +24,17 @@ 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(); + @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")); - } + 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 index 8aecf5d94..851050c11 100644 --- 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 @@ -1,3 +1,21 @@ +/* + * 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; @@ -7,6 +25,9 @@ import org.junit.Assert; import org.junit.Test; import org.skywalking.apm.collector.core.util.ResourceUtils; +/** + * @author neeuq + */ public class ResourceUtilsTestCase { @Test