zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abe...@apache.org
Subject [incubator-zipkin-brave-karaf] 07/46: Add unit test for kafka builder, support overrides
Date Thu, 31 Jan 2019 11:19:29 GMT
This is an automated email from the ASF dual-hosted git repository.

abesto pushed a commit to branch dont-sign-snapshots
in repository https://gitbox.apache.org/repos/asf/incubator-zipkin-brave-karaf.git

commit 349f7eac23dfc356d272ac0c2d1fd692c0bb1dc5
Author: Christian Schneider <chris@die-schneider.net>
AuthorDate: Wed Dec 14 13:52:20 2016 +0100

    Add unit test for kafka builder, support overrides
---
 brave-exporter-kafka08/pom.xml                     |  7 ++++
 .../osgi/exporter/kafka/KafkaReporterExporter.java | 25 +++++++++---
 .../exporter/kafka/KafkaReporterExporterTest.java  | 44 ++++++++++++++++++++++
 brave-exporter/pom.xml                             |  2 +
 pom.xml                                            |  5 +++
 5 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/brave-exporter-kafka08/pom.xml b/brave-exporter-kafka08/pom.xml
index 8dc9b93..1ad63a1 100644
--- a/brave-exporter-kafka08/pom.xml
+++ b/brave-exporter-kafka08/pom.xml
@@ -34,11 +34,13 @@
 			<groupId>org.osgi</groupId>
 			<artifactId>osgi.core</artifactId>
 			<version>6.0.0</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.osgi</groupId>
 			<artifactId>osgi.cmpn</artifactId>
 			<version>6.0.0</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>io.zipkin.brave</groupId>
@@ -52,6 +54,11 @@
 			<groupId>io.zipkin.reporter</groupId>
 			<artifactId>zipkin-sender-kafka08</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-core</artifactId>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 
 	<build>
diff --git a/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
b/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
index 46dc6a4..4c48df2 100644
--- a/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
+++ b/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
@@ -40,6 +40,7 @@ import zipkin.reporter.kafka08.KafkaSender;
 @Designate(ocd = KafkaReporterExporter.Config.class)
 public class KafkaReporterExporter {
 
+    private static final String OVERRIDE_PREFIX = "kafka.";
     @SuppressWarnings("rawtypes")
     private ServiceRegistration<Reporter> reg;
     private AsyncReporter<Span> reporter;
@@ -50,22 +51,34 @@ public class KafkaReporterExporter {
         Encoding encoding() default Encoding.THRIFT;
         int messageMaxBytes() default 1000000;
         String topic() default "zipkin";
-        String overrides();
     }
 
     @Activate
     public void activate(Config config, BundleContext context, Map<String,String> properties)
{
-        config.overrides();
-        Map<String, String> overrides = new HashMap<String, String>();
+        KafkaSender sender = createSender(config, properties);
+        reporter = AsyncReporter.builder(sender).build();
+        reg = context.registerService(Reporter.class, reporter, new Hashtable<String,
String>(properties));
+    }
+
+    KafkaSender createSender(Config config, Map<String, String> properties) {
         KafkaSender sender = KafkaSender.builder() //
             .bootstrapServers(config.bootstrapServers()) //
             .encoding(config.encoding()) //
             .messageMaxBytes(config.messageMaxBytes()) //
-            .overrides(overrides) //
+            .overrides(getOverrides(properties)) //
             .topic(config.topic()) //
             .build();
-        reporter = AsyncReporter.builder(sender).build();
-        reg = context.registerService(Reporter.class, reporter, new Hashtable<String,
String>(properties));
+        return sender;
+    }
+
+    private HashMap<String, String> getOverrides(Map<String, String> properties)
{
+        HashMap<String, String> overrides = new HashMap<String, String>();
+        for (String key : properties.keySet()) {
+            if (key.startsWith(OVERRIDE_PREFIX)) {
+                overrides.put(key.substring(OVERRIDE_PREFIX.length() - 1), properties.get(key));
+            }
+        }
+        return overrides;
     }
     
     @Deactivate
diff --git a/brave-exporter-kafka08/src/test/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporterTest.java
b/brave-exporter-kafka08/src/test/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporterTest.java
new file mode 100644
index 0000000..8b6b10e
--- /dev/null
+++ b/brave-exporter-kafka08/src/test/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporterTest.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2016 The OpenZipkin Authors
+ *
+ * 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.
+ */
+package io.zipkin.brave.osgi.exporter.kafka;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.zipkin.brave.osgi.exporter.kafka.KafkaReporterExporter.Config;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import zipkin.reporter.Encoding;
+
+
+@Config(bootstrapServers = "server1", messageMaxBytes = 10, topic="mytopic")
+public class KafkaReporterExporterTest {
+
+    @Test
+    public void testConfig() {
+        KafkaReporterExporter exporter = new KafkaReporterExporter();
+        Map<String, String> properties = new HashMap<String, String>();
+        properties.put("kafka.myprop", "myvalue");
+        BundleContext context = mock(BundleContext.class);
+        Config config = mock(Config.class);
+        when(config.bootstrapServers()).thenReturn("server1");
+        when(config.encoding()).thenReturn(Encoding.THRIFT);
+        when(config.topic()).thenReturn("mytopic");
+        exporter.activate(config, context, properties);
+    }
+
+}
diff --git a/brave-exporter/pom.xml b/brave-exporter/pom.xml
index e1b38b5..dbc38ac 100644
--- a/brave-exporter/pom.xml
+++ b/brave-exporter/pom.xml
@@ -34,11 +34,13 @@
 			<groupId>org.osgi</groupId>
 			<artifactId>osgi.core</artifactId>
 			<version>6.0.0</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.osgi</groupId>
 			<artifactId>osgi.cmpn</artifactId>
 			<version>6.0.0</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>io.zipkin.brave</groupId>
diff --git a/pom.xml b/pom.xml
index ff559c9..8bf7248 100644
--- a/pom.xml
+++ b/pom.xml
@@ -131,6 +131,11 @@
 				<artifactId>awaitility</artifactId>
 				<version>2.0.0</version>
 			</dependency>
+			<dependency>
+				<groupId>org.mockito</groupId>
+				<artifactId>mockito-core</artifactId>
+				<version>2.3.0</version>
+			</dependency>
 		</dependencies>
 	</dependencyManagement>
 


Mime
View raw message