geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] branch feature/GEODE-3781 updated: test now validates insert, update, and destroy
Date Thu, 26 Oct 2017 00:47:31 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3781 by this push:
     new 0b6e410  test now validates insert, update, and destroy
0b6e410 is described below

commit 0b6e410521d62df0f1a4fd51416e79d2103fa057
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Wed Oct 25 17:47:08 2017 -0700

    test now validates insert, update, and destroy
---
 .../apache/geode/connectors/jdbc/JDBCManager.java  | 25 +++++++++--
 .../jdbc/JDBCAsyncWriterIntegrationTest.java       | 51 +++++++++++++++++++++-
 2 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
index 49c948d..fceb8dc 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
@@ -107,13 +107,29 @@ public class JDBCManager {
   }
 
   private String getDestroyQueryString(String tableName, List<ColumnValue> columnList)
{
-    // TODO Auto-generated method stub
-    return null;
+    assert columnList.size() == 1;
+    ColumnValue keyCV = columnList.get(0);
+    StringBuilder query =
+        new StringBuilder("DELETE FROM " + tableName + " WHERE " + keyCV.getColumnName()
+ " = ?");
+    return query.toString();
   }
 
   private String getUpdateQueryString(String tableName, List<ColumnValue> columnList)
{
-    // TODO Auto-generated method stub
-    return null;
+    StringBuilder query = new StringBuilder("UPDATE " + tableName + " SET ");
+    int idx = 0;
+    for (ColumnValue cv : columnList) {
+      if (cv.isKey()) {
+        query.append(" WHERE ");
+      } else {
+        idx++;
+        if (idx > 1) {
+          query.append(", ");
+        }
+      }
+      query.append(cv.getColumnName());
+      query.append(" = ?");
+    }
+    return query.toString();
   }
 
   private String getInsertQueryString(String tableName, List<ColumnValue> columnList)
{
@@ -180,6 +196,7 @@ public class JDBCManager {
     // }
     // });
     String query = getQueryString(tableName, columnList, operation);
+    System.out.println("query=" + query);
     Connection con = getConnection();
     try {
       return con.prepareStatement(query);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCAsyncWriterIntegrationTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCAsyncWriterIntegrationTest.java
index 173ec62..fdfd218 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCAsyncWriterIntegrationTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCAsyncWriterIntegrationTest.java
@@ -65,7 +65,8 @@ public class JDBCAsyncWriterIntegrationTest {
       // ignore
     }
     if (null == cache) {
-      cache = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").create();
+      cache = (GemFireCacheImpl) new CacheFactory().setPdxReadSerialized(true).set(MCAST_PORT,
"0")
+          .create();
     }
     setupDB();
   }
@@ -122,7 +123,7 @@ public class JDBCAsyncWriterIntegrationTest {
   }
 
   @Test
-  public void jdbcAsyncWriterCanWriteToDatabase() throws Exception {
+  public void jdbcAsyncWriterCanInsertIntoDatabase() throws Exception {
     Region employees = createRegionWithJDBCAsyncWriter(regionTableName, getRequiredProperties());
     PdxInstance pdx1 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp1")
         .writeInt("age", 55).writeInt("id", 3).create();
@@ -138,6 +139,52 @@ public class JDBCAsyncWriterIntegrationTest {
     printTable();
   }
 
+  @Test
+  public void jdbcAsyncWriterCanDestroyFromDatabase() throws Exception {
+    Region employees = createRegionWithJDBCAsyncWriter(regionTableName, getRequiredProperties());
+    PdxInstance pdx1 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp1")
+        .writeInt("age", 55).create();
+    PdxInstance pdx2 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp2")
+        .writeInt("age", 21).create();
+    employees.put("1", pdx1);
+    employees.put("2", pdx2);
+
+    Awaitility.await().atMost(30, TimeUnit.SECONDS)
+        .until(() -> assertThat(jdbcWriter.getSuccessfulEvents()).isEqualTo(2));
+
+    employees.destroy("1");
+
+    Awaitility.await().atMost(30, TimeUnit.SECONDS)
+        .until(() -> assertThat(jdbcWriter.getSuccessfulEvents()).isEqualTo(3));
+
+    validateTableRowCount(1);
+    printTable();
+  }
+
+  @Test
+  public void jdbcAsyncWriterCanUpdateDatabase() throws Exception {
+    Region employees = createRegionWithJDBCAsyncWriter(regionTableName, getRequiredProperties());
+    PdxInstance pdx1 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp1")
+        .writeInt("age", 55).create();
+    PdxInstance pdx2 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp2")
+        .writeInt("age", 21).create();
+    employees.put("1", pdx1);
+    employees.put("2", pdx2);
+
+    Awaitility.await().atMost(30, TimeUnit.SECONDS)
+        .until(() -> assertThat(jdbcWriter.getSuccessfulEvents()).isEqualTo(2));
+
+    PdxInstance pdx3 = cache.createPdxInstanceFactory("Employee").writeString("name", "Emp1")
+        .writeInt("age", 72).create();
+    employees.put("1", pdx3);
+
+    Awaitility.await().atMost(30, TimeUnit.SECONDS)
+        .until(() -> assertThat(jdbcWriter.getSuccessfulEvents()).isEqualTo(3));
+
+    validateTableRowCount(2);
+    printTable();
+  }
+
   private Region createRegionWithJDBCAsyncWriter(String regionName, Properties props) {
     jdbcWriter = new JDBCAsyncWriter();
     jdbcWriter.init(props);

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message