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

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


The following commit(s) were added to refs/heads/main by this push:
     new 6e5560d  (chores) minor camel-kudu fixes and cleanups (#6464)
6e5560d is described below

commit 6e5560db58cb5eb8cc03cd5ee3dd3dff1371ee2f
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Tue Nov 23 11:38:41 2021 +0100

    (chores) minor camel-kudu fixes and cleanups (#6464)
    
    * (chores) camel-kudu: prevent the test from executing if the client is
    not runnable
    
    * (chores) camel-kudu: minor test cleanups
---
 .../camel/component/kudu/AbstractKuduTest.java     | 21 +++++++++-------
 .../kudu/IntegrationKuduConfiguration.java         | 28 +++++++++++++++++-----
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git 
a/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/AbstractKuduTest.java
 
b/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/AbstractKuduTest.java
index abb4b5c..34b9a20 100644
--- 
a/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/AbstractKuduTest.java
+++ 
b/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/AbstractKuduTest.java
@@ -31,12 +31,13 @@ import org.apache.kudu.client.KuduException;
 import org.apache.kudu.client.KuduTable;
 import org.apache.kudu.client.PartialRow;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class AbstractKuduTest extends CamelTestSupport {
+public abstract class AbstractKuduTest extends CamelTestSupport {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(AbstractKuduTest.class);
 
@@ -49,7 +50,7 @@ public class AbstractKuduTest extends CamelTestSupport {
     private Integer id = 1;
 
     protected void createTestTable(String tableName) {
-        LOG.trace("Creating table " + tableName + ".");
+        LOG.trace("Creating table {}.", tableName);
         KuduClient client = ikc.getClient();
 
         List<ColumnSchema> columns = new ArrayList<>(5);
@@ -78,29 +79,33 @@ public class AbstractKuduTest extends CamelTestSupport {
 
     @BeforeEach
     public void setUp() throws Exception {
+        Assumptions.assumeTrue(ikc.hasKuduHarness(), "Skipping the test 
because the Kudu harness is not runnable");
+
         super.setUp();
         ikc.setupCamelContext(this.context);
     }
 
     @AfterEach
     public void tearDown() throws Exception {
-        deleteTestTable("TestTable");
-        super.tearDown();
+        if (ikc.hasKuduHarness()) {
+            deleteTestTable("TestTable");
+            super.tearDown();
+        }
     }
 
     protected void deleteTestTable(String tableName) {
-        LOG.trace("Removing table " + tableName + ".");
+        LOG.trace("Removing table {}.", tableName);
         KuduClient client = ikc.getClient();
         try {
             client.deleteTable(tableName);
         } catch (Exception e) {
             LOG.error(e.getMessage(), e);
         }
-        LOG.trace("Table " + tableName + " removed.");
+        LOG.trace("Table {} removed.", tableName);
     }
 
     protected void insertRowInTestTable(String tableName) {
-        LOG.trace("Inserting row on table " + tableName + ".");
+        LOG.trace("Inserting row on table {}.", tableName);
         KuduClient client = ikc.getClient();
 
         try {
@@ -120,6 +125,6 @@ public class AbstractKuduTest extends CamelTestSupport {
 
             LOG.error(e.getMessage(), e);
         }
-        LOG.trace("Row inserted on table " + tableName + ".");
+        LOG.trace("Row inserted on table {}.", tableName);
     }
 }
diff --git 
a/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/IntegrationKuduConfiguration.java
 
b/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/IntegrationKuduConfiguration.java
index ec37ff8..8539419 100644
--- 
a/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/IntegrationKuduConfiguration.java
+++ 
b/components/camel-kudu/src/test/java/org/apache/camel/component/kudu/IntegrationKuduConfiguration.java
@@ -24,16 +24,20 @@ import org.apache.kudu.test.KuduTestHarness;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
- * Use this class to run tests agains a local basic Kudu server. This local 
kudu server is spinned up by
+ * Use this class to run tests against a local basic Kudu server. This local 
kudu server is spinned up by
  * https://kudu.apache.org/docs/developing.html#_using_the_kudu_binary_test_jar
  */
 public class IntegrationKuduConfiguration implements BeforeEachCallback, 
AfterEachCallback {
+    private static final Logger LOG = 
LoggerFactory.getLogger(IntegrationKuduConfiguration.class);
 
-    Internal internal = new Internal();
+    private final Internal internal = new Internal();
+    private boolean hasKuduHarness;
 
     public IntegrationKuduConfiguration() {
     }
@@ -47,13 +51,25 @@ public class IntegrationKuduConfiguration implements 
BeforeEachCallback, AfterEa
     }
 
     @Override
-    public void afterEach(ExtensionContext context) throws Exception {
-        internal.after();
+    public void afterEach(ExtensionContext context) {
+        if (hasKuduHarness) {
+            internal.after();
+        }
     }
 
     @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
-        internal.before();
+    public void beforeEach(ExtensionContext context) {
+        try {
+            internal.before();
+            hasKuduHarness = true;
+        } catch (Exception e) {
+            hasKuduHarness = false;
+            LOG.debug("Kudu harness is not runnable because: {}", 
e.getMessage(), e);
+        }
+    }
+
+    public boolean hasKuduHarness() {
+        return hasKuduHarness;
     }
 
     static class Internal extends KuduTestHarness {

Reply via email to