You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/04/16 09:54:43 UTC

[camel] 02/02: CAMEL-16500: Fix autowire of VertxKafkaClientFactory & VertxKafkaManualCommitFactory

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0e24b14adaff44749d70cbcf2fa47eb199860653
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Apr 16 09:44:28 2021 +0100

    CAMEL-16500: Fix autowire of VertxKafkaClientFactory & VertxKafkaManualCommitFactory
---
 .../component/vertx/kafka/VertxKafkaComponent.java | 12 ++++-
 .../vertx/kafka/VertxKafkaAutowireTest.java        | 61 ++++++++++++++++++++++
 .../vertx/kafka/VertxKafkaComponentTest.java       |  3 ++
 3 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponent.java b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponent.java
index 789929d..e7a414d 100644
--- a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponent.java
+++ b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponent.java
@@ -43,9 +43,9 @@ public class VertxKafkaComponent extends DefaultComponent {
     @Metadata(label = "advanced")
     private VertxOptions vertxOptions;
     @Metadata(label = "advanced", autowired = true)
-    private VertxKafkaClientFactory vertxKafkaClientFactory = new DefaultVertxKafkaClientFactory();
+    private VertxKafkaClientFactory vertxKafkaClientFactory;
     @Metadata(label = "consumer,advanced", autowired = true)
-    private VertxKafkaManualCommitFactory kafkaManualCommitFactory = new DefaultVertxKafkaManualCommitFactory();
+    private VertxKafkaManualCommitFactory kafkaManualCommitFactory;
 
     public VertxKafkaComponent() {
     }
@@ -92,6 +92,14 @@ public class VertxKafkaComponent extends DefaultComponent {
             }
             managedVertx = true;
         }
+
+        if (vertxKafkaClientFactory == null) {
+            vertxKafkaClientFactory = new DefaultVertxKafkaClientFactory();
+        }
+
+        if (kafkaManualCommitFactory == null) {
+            kafkaManualCommitFactory = new DefaultVertxKafkaManualCommitFactory();
+        }
     }
 
     @Override
diff --git a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaAutowireTest.java b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaAutowireTest.java
new file mode 100644
index 0000000..cc91433
--- /dev/null
+++ b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaAutowireTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.component.vertx.kafka;
+
+import io.vertx.core.Vertx;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.component.vertx.kafka.offset.DefaultVertxKafkaManualCommitFactory;
+import org.apache.camel.component.vertx.kafka.offset.VertxKafkaManualCommitFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+public class VertxKafkaAutowireTest extends CamelTestSupport {
+
+    @BindToRegistry
+    Vertx vertx = Vertx.vertx();
+
+    @BindToRegistry
+    VertxKafkaClientFactory clientFactory = new TestVertxKafkaClientFactory();
+
+    @BindToRegistry
+    VertxKafkaManualCommitFactory commitFactory = new TestVertxKafkaManualCommitFactory();
+
+    @Override
+    public void afterAll(ExtensionContext context) {
+        super.afterAll(context);
+        vertx.close();
+    }
+
+    @Test
+    public void testVertxKafkaComponentAutowiring() {
+        VertxKafkaComponent component = context.getComponent("vertx-kafka", VertxKafkaComponent.class);
+        assertSame(vertx, component.getVertx());
+        assertSame(clientFactory, component.getVertxKafkaClientFactory());
+        assertSame(commitFactory, component.getKafkaManualCommitFactory());
+    }
+
+    static final class TestVertxKafkaClientFactory extends DefaultVertxKafkaClientFactory {
+
+    }
+
+    static final class TestVertxKafkaManualCommitFactory extends DefaultVertxKafkaManualCommitFactory {
+
+    }
+}
diff --git a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponentTest.java b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponentTest.java
index 0a31ec1..260735c 100644
--- a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponentTest.java
+++ b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponentTest.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.camel.component.vertx.kafka.configuration.VertxKafkaConfiguration;
+import org.apache.camel.component.vertx.kafka.offset.DefaultVertxKafkaManualCommitFactory;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.kafka.clients.CommonClientConfigs;
 import org.apache.kafka.clients.producer.ProducerConfig;
@@ -55,6 +56,8 @@ class VertxKafkaComponentTest extends CamelTestSupport {
         assertEquals("broker1:12345,broker2:12566", endpoint.getComponent().getConfiguration().getBootstrapServers());
         assertEquals("mytopic", endpoint.getConfiguration().getTopic());
         assertEquals("com.class.Party", endpoint.getConfiguration().getPartitionerClass());
+        assertTrue(endpoint.getComponent().getVertxKafkaClientFactory() instanceof DefaultVertxKafkaClientFactory);
+        assertTrue(endpoint.getComponent().getKafkaManualCommitFactory() instanceof DefaultVertxKafkaManualCommitFactory);
     }
 
     @Test