Repository: camel
Updated Branches:
  refs/heads/master 45710b3fd -> e74975e8f


CAMEL-10920: lookup zipkin span collector from registry


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e74975e8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e74975e8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e74975e8

Branch: refs/heads/master
Commit: e74975e8fd0197d85e48999c1e1be191f5c42da1
Parents: f6b495b
Author: Nicola Ferraro <ni.ferr...@gmail.com>
Authored: Wed Mar 15 13:56:07 2017 +0100
Committer: Nicola Ferraro <ni.ferr...@gmail.com>
Committed: Wed Mar 15 13:56:43 2017 +0100

----------------------------------------------------------------------
 .../org/apache/camel/zipkin/ZipkinTracer.java   |  8 +++
 .../ZipkinSpanCollectorInRegistryTest.java      | 51 ++++++++++++++++++++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e74975e8/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
 
b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
index fc6fb7e..9e5878f 100644
--- 
a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
+++ 
b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
@@ -323,6 +323,14 @@ public class ZipkinTracer extends ServiceSupport 
implements RoutePolicyFactory,
             }
         }
 
+        if (spanCollector == null) {
+            // Try to lookup the span collector from the registry if only one 
instance is present
+            Set<SpanCollector> collectors = 
camelContext.getRegistry().findByType(SpanCollector.class);
+            if (collectors.size() == 1) {
+                spanCollector = collectors.iterator().next();
+            }
+        }
+
         ObjectHelper.notNull(spanCollector, "SpanCollector", this);
 
         if (clientServiceMappings.isEmpty() && 
serverServiceMappings.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e74975e8/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSpanCollectorInRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSpanCollectorInRegistryTest.java
 
b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSpanCollectorInRegistryTest.java
new file mode 100644
index 0000000..f696c41
--- /dev/null
+++ 
b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSpanCollectorInRegistryTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.camel.zipkin;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinSpanCollectorInRegistryTest extends CamelTestSupport {
+
+    private ZipkinTracer zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinTracer();
+        zipkin.init(context);
+
+        return context;
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("span", new ZipkinLoggingSpanCollector());
+        return registry;
+    }
+
+    @Test
+    public void testZipkinConfiguration() throws Exception {
+        assertNotNull(zipkin.getSpanCollector());
+        assertTrue(zipkin.getSpanCollector() instanceof 
ZipkinLoggingSpanCollector);
+    }
+
+}

Reply via email to