htrace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject incubator-htrace git commit: HTRACE-272. TracerPool must not load multiple instances of the same receiver class when a simple classname is given (Masatake Iwasaki via Colin P. McCabe)
Date Tue, 06 Oct 2015 16:57:23 GMT
Repository: incubator-htrace
Updated Branches:
  refs/heads/master 9ebdafb45 -> 2a77c8801


HTRACE-272. TracerPool must not load multiple instances of the same receiver class when a
simple classname is given (Masatake Iwasaki via Colin P. McCabe)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/2a77c880
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/2a77c880
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/2a77c880

Branch: refs/heads/master
Commit: 2a77c88017d632d140f8d630eba6b807ed5515ac
Parents: 9ebdafb
Author: Colin P. Mccabe <cmccabe@apache.org>
Authored: Tue Oct 6 09:49:32 2015 -0700
Committer: Colin P. Mccabe <cmccabe@apache.org>
Committed: Tue Oct 6 09:57:11 2015 -0700

----------------------------------------------------------------------
 .../org/apache/htrace/core/SpanReceiver.java    |  2 +-
 .../java/org/apache/htrace/core/TracerPool.java |  6 ++-
 .../org/apache/htrace/core/TestTracerPool.java  | 44 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2a77c880/htrace-core4/src/main/java/org/apache/htrace/core/SpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/main/java/org/apache/htrace/core/SpanReceiver.java b/htrace-core4/src/main/java/org/apache/htrace/core/SpanReceiver.java
index a955ddf..026685e 100644
--- a/htrace-core4/src/main/java/org/apache/htrace/core/SpanReceiver.java
+++ b/htrace-core4/src/main/java/org/apache/htrace/core/SpanReceiver.java
@@ -39,7 +39,7 @@ public abstract class SpanReceiver implements Closeable {
   public static class Builder {
     private static final Log LOG = LogFactory.getLog(Builder.class);
 
-    private final static String DEFAULT_PACKAGE = "org.apache.htrace.core";
+    final static String DEFAULT_PACKAGE = "org.apache.htrace.core";
     private final HTraceConfiguration conf;
     private boolean logErrors;
     private String className;

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2a77c880/htrace-core4/src/main/java/org/apache/htrace/core/TracerPool.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/main/java/org/apache/htrace/core/TracerPool.java b/htrace-core4/src/main/java/org/apache/htrace/core/TracerPool.java
index 26e39f5..26acc64 100644
--- a/htrace-core4/src/main/java/org/apache/htrace/core/TracerPool.java
+++ b/htrace-core4/src/main/java/org/apache/htrace/core/TracerPool.java
@@ -226,9 +226,11 @@ public class TracerPool {
    */
   public synchronized SpanReceiver loadReceiverType(String className,
       HTraceConfiguration conf, ClassLoader classLoader) {
+    String receiverClass = className.contains(".") ?
+        className : SpanReceiver.Builder.DEFAULT_PACKAGE + "." + className;
     SpanReceiver[] receivers = curReceivers;
     for (SpanReceiver receiver : receivers) {
-      if (receiver.getClass().getName().equals(className)) {
+      if (receiver.getClass().getName().equals(receiverClass)) {
         LOG.trace(toString() + ": returning a reference to receiver " +
                   receiver.toString());
         return receiver;
@@ -282,4 +284,4 @@ public class TracerPool {
   public String toString() {
     return "TracerPool(" + name + ")";
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2a77c880/htrace-core4/src/test/java/org/apache/htrace/core/TestTracerPool.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/test/java/org/apache/htrace/core/TestTracerPool.java b/htrace-core4/src/test/java/org/apache/htrace/core/TestTracerPool.java
new file mode 100644
index 0000000..daf8ac1
--- /dev/null
+++ b/htrace-core4/src/test/java/org/apache/htrace/core/TestTracerPool.java
@@ -0,0 +1,44 @@
+/*
+ * 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.htrace.core;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+public class TestTracerPool {
+  HTraceConfiguration conf = HTraceConfiguration.EMPTY;
+  ClassLoader loader = TestTracerPool.class.getClassLoader();
+
+  @Test
+  public void testLoadReceiver() {
+    addThenLoadReceiverType("org.apache.htrace.core.POJOSpanReceiver");
+  }
+
+  @Test
+  public void testLoadReceiverWithSimpleName() {
+    addThenLoadReceiverType("POJOSpanReceiver");
+  }
+
+  public void addThenLoadReceiverType(String className) {
+    TracerPool pool = new TracerPool(className);
+    SpanReceiver receiver = new SpanReceiver.Builder(conf).
+        className(className).
+        build();
+    pool.addReceiver(receiver);
+    assertTrue(receiver == pool.loadReceiverType(className, conf, loader));
+  }
+}


Mime
View raw message