Repository: Vantiq/vantiq-extension-sources (language: python)

Issue:
Update to current Vantiq SDK.



Discussion / hints:

Fix patch:
diff --git a/build.gradle b/build.gradle
index 0fab3692..ff62ae7c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -42,7 +42,7 @@ group 'io.vantiq'
 ext {
     slf4jApiVersion = '1.7.25'
     eclipseMiloVersion = '0.2.1'
-    vantiqSDKVersion = '1.0.31'
+    vantiqSDKVersion = '1.1.1'
     log4jVersion = '2.17.0'
     lombokVersion = '1.18.24'
 }
diff --git a/jdbcSource/build.gradle b/jdbcSource/build.gradle
index 2d1a3882..516bfbd4 100644
--- a/jdbcSource/build.gradle
+++ b/jdbcSource/build.gradle
@@ -74,6 +74,7 @@ dependencies {
     // Use JUnit test framework
     testImplementation 'junit:junit:4.12'
     testImplementation project(path:":extjsdk", configuration:"testArtifacts")
+    testImplementation "com.fasterxml.jackson.core:jackson-databind:2.9.3"
 
     // Used to create a connection pool if asynchronous processing has been specified for publish/query handlers
     implementation group: 'com.zaxxer', name: 'HikariCP', version: '3.3.1'


Test patch:
diff --git a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
index ae58f696..7e38d98b 100644
--- a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
+++ b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
@@ -8,6 +8,7 @@
 
 package io.vantiq.extsrc.jdbcSource;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -187,6 +188,11 @@ public void setup() {
         jdbc = new JDBC();
         vantiq = new io.vantiq.client.Vantiq(testVantiqServer);
         vantiq.setAccessToken(testAuthToken);
+        try {
+            createSourceImpl(vantiq);
+        } catch (Exception e) {
+            fail("Could not create sourceImpl: " + e.getMessage());
+        }
     }
 
     @BeforeClass
@@ -299,6 +305,8 @@ public static void tearDown() throws VantiqSQLException {
             deleteTopic();
             deleteProcedure();
             deleteRule();
+
+            deleteSourceImpl(vantiq);
         }
 
         // Close JDBCCore if still open
@@ -801,7 +809,7 @@ public void testMaxMessageSize() {
         createParams.put("query", CREATE_TABLE_MAX_MESSAGE_SIZE);
         vantiq.publish("sources", testSourceName, createParams);
 
-        // Insert 2000 rows into the the table
+        // Insert 2000 rows into the table
         Map<String, Object> insertParams = new LinkedHashMap<>();
         insertParams.put("query", INSERT_ROW_MAX_MESSAGE_SIZE);
         for (int i = 0; i < numRows; i ++) {
@@ -920,8 +928,8 @@ public void doAsynchronousProcessing(boolean useCustomTaskConfig) throws Interru
         // Execute Procedure to trigger asynchronous publish/queries (assign to variable to ensure that procedure has finished before selecting from type)
         VantiqResponse response = vantiq.execute(testProcedureName, new LinkedHashMap<>());
 
-        // Sleep for 6 seconds to allow all queries to finish
-        Thread.sleep(6000);
+        // Sleep for 10 seconds to allow all queries to finish
+        Thread.sleep(10000);
 
         // Select from the type and make sure all of our results are there as expected
         response = vantiq.select(testTypeName, null, null, null);
@@ -1162,7 +1170,10 @@ public static void setupSource(Map<String, Object> sourceDef) {
 
         Map<String, String> where = new LinkedHashMap<>();
         where.put("name", "JDBC");
-        VantiqResponse implResp = vantiq.select("system.sourceimpls", null, where, null);
+        VantiqResponse implResp = vantiq.select(VANTIQ_SOURCE_IMPL, null, where, null);
+        assertFalse("Errors from fetching source impl", implResp.hasErrors());
+        ArrayList responseBody = (ArrayList) implResp.getBody();
+        assertEquals("Missing sourceimpl -- expected a count of 1", 1, responseBody.size());
 
         VantiqResponse insertResponse = vantiq.insert("system.sources", sourceDef);
         if (insertResponse.isSuccess()) {
diff --git a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBCBase.java b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBCBase.java
index 927e0f14..f5cba73f 100644
--- a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBCBase.java
+++ b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBCBase.java
@@ -8,9 +8,29 @@
 
 package io.vantiq.extsrc.jdbcSource;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.vantiq.client.Vantiq;
+import io.vantiq.client.VantiqError;
+import io.vantiq.client.VantiqResponse;
 import org.junit.BeforeClass;
 
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
 public class TestJDBCBase {
+
+    public static final String JDBC_SRC_TYPE = "JDBC";
+    public static final String JDBC_IMPL_DEF = "jdbcImpl.json";
+    private static final Integer JDBC_IMPL_MAX_SIZE = 1000;
+
+    static final String VANTIQ_SOURCE_IMPL = "system.sourceimpls";
     static String testDBUsername;
     static String testDBPassword;
     static String testDBURL;
@@ -37,4 +57,53 @@ public static void getProps() {
         testRuleName = System.getProperty("EntConTestRuleName", "testRuleName");
         testTopicName = System.getProperty("EntConTestTopicName", "/test/topic/name");
     }
+
+    private static boolean createdImpl = false;
+    @SuppressWarnings("unchecked")
+    protected static void createSourceImpl(Vantiq vantiq) throws Exception {
+        VantiqResponse resp = vantiq.selectOne(VANTIQ_SOURCE_IMPL, JDBC_SRC_TYPE);
+        if (!resp.isSuccess()) {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            byte[] implDef = new byte[JDBC_IMPL_MAX_SIZE];
+            try (InputStream is = loader.getResourceAsStream(JDBC_IMPL_DEF))
+            {
+                assert is != null;
+                int implSize = is.read(implDef);
+                assert implSize > 0;
+                assert implSize < JDBC_IMPL_MAX_SIZE;
+            }
+
+            ObjectMapper mapper = new ObjectMapper();
+            Map<String, Object> implMap = new LinkedHashMap<>();
+            implMap = mapper.readValue(implDef, implMap.getClass());
+            resp = vantiq.insert(VANTIQ_SOURCE_IMPL, implMap);
+            assert resp.isSuccess();
+
+            Map<String, String> where = new LinkedHashMap<>();
+            where.put("name", "JDBC");
+            VantiqResponse implResp = vantiq.select(VANTIQ_SOURCE_IMPL, null, where, null);
+            assertFalse("Errors from fetching source impl", implResp.hasErrors());
+            @SuppressWarnings({"rawtypes"})
+            ArrayList responseBody = (ArrayList) implResp.getBody();
+            assertEquals("Missing sourceImpl -- expected a count of 1", 1, responseBody.size());
+            createdImpl = true;
+        }
+    }
+
+    protected static void deleteSourceImpl(Vantiq vantiq) {
+        if (createdImpl) {
+            vantiq.deleteOne(VANTIQ_SOURCE_IMPL, JDBC_SRC_TYPE);
+            createdImpl = false;
+        }
+
+        VantiqResponse resp = vantiq.selectOne(VANTIQ_SOURCE_IMPL, JDBC_SRC_TYPE);
+        if (resp.hasErrors()) {
+            List<VantiqError> errors = resp.getErrors();
+            if (errors.size() != 1 || !errors.get(0).getCode().equals("io.vantiq.resource.not.found")) {
+                fail("Error deleting source impl" + resp.getErrors());
+            }
+        } else {
+            fail(JDBC_SRC_TYPE + " source impl found after deletion.");
+        }
+    }
 }