metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickal...@apache.org
Subject [03/30] metron git commit: METRON-1706 HbaseClient.mutate should return the number of mutations (nickwallen) closes apache/metron#1147
Date Fri, 28 Sep 2018 13:08:59 GMT
METRON-1706 HbaseClient.mutate should return the number of mutations (nickwallen) closes apache/metron#1147


Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/401bd7a1
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/401bd7a1
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/401bd7a1

Branch: refs/heads/master
Commit: 401bd7a180dad4ff805fd6e5840ab826ee4e94b7
Parents: 5eff97f
Author: nickwallen <nick@nickallen.org>
Authored: Mon Aug 20 15:35:57 2018 -0400
Committer: nickallen <nickallen@apache.org>
Committed: Mon Aug 20 15:35:57 2018 -0400

----------------------------------------------------------------------
 .../apache/metron/hbase/client/HBaseClient.java |  8 ++++--
 .../metron/hbase/client/HBaseClientTest.java    | 30 +++++++++++++++++++-
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/401bd7a1/metron-platform/metron-hbase/src/main/java/org/apache/metron/hbase/client/HBaseClient.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-hbase/src/main/java/org/apache/metron/hbase/client/HBaseClient.java
b/metron-platform/metron-hbase/src/main/java/org/apache/metron/hbase/client/HBaseClient.java
index c027c5c..f0a0a10 100644
--- a/metron-platform/metron-hbase/src/main/java/org/apache/metron/hbase/client/HBaseClient.java
+++ b/metron-platform/metron-hbase/src/main/java/org/apache/metron/hbase/client/HBaseClient.java
@@ -133,9 +133,11 @@ public class HBaseClient implements Closeable {
 
   /**
    * Submits all queued Mutations.
+   * @return The number of mutation submitted.
    */
-  public void mutate() {
-    Object[] result = new Object[mutations.size()];
+  public int mutate() {
+    int mutationCount = mutations.size();
+    Object[] result = new Object[mutationCount];
     try {
       table.batch(mutations, result);
       mutations.clear();
@@ -144,6 +146,8 @@ public class HBaseClient implements Closeable {
       LOG.warn("Error performing a mutation to HBase.", e);
       throw new RuntimeException(e);
     }
+
+    return mutationCount;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/metron/blob/401bd7a1/metron-platform/metron-hbase/src/test/java/org/apache/metron/hbase/client/HBaseClientTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-hbase/src/test/java/org/apache/metron/hbase/client/HBaseClientTest.java
b/metron-platform/metron-hbase/src/test/java/org/apache/metron/hbase/client/HBaseClientTest.java
index 1849745..ca1f5a6 100644
--- a/metron-platform/metron-hbase/src/test/java/org/apache/metron/hbase/client/HBaseClientTest.java
+++ b/metron-platform/metron-hbase/src/test/java/org/apache/metron/hbase/client/HBaseClientTest.java
@@ -160,7 +160,10 @@ public class HBaseClientTest {
     // add two mutations to the queue
     client.addMutation(rowKey1, cols1, Durability.SYNC_WAL);
     client.addMutation(rowKey2, cols2, Durability.SYNC_WAL);
-    client.mutate();
+    int count = client.mutate();
+
+    // there were two mutations
+    Assert.assertEquals(2, count);
 
     HBaseProjectionCriteria criteria = new HBaseProjectionCriteria();
     criteria.addColumnFamily(WidgetMapper.CF_STRING);
@@ -180,6 +183,31 @@ public class HBaseClientTest {
   }
 
   /**
+   * What happens when there is nothing in the batch to write?
+   */
+  @Test
+  public void testEmptyBatch() throws Exception {
+
+    // do not add any mutations before attempting to write
+    int count = client.mutate();
+    Assert.assertEquals(0, count);
+
+    HBaseProjectionCriteria criteria = new HBaseProjectionCriteria();
+    criteria.addColumnFamily(WidgetMapper.CF_STRING);
+
+    // read back both
+    client.addGet(rowKey1, criteria);
+    client.addGet(rowKey2, criteria);
+    Result[] results = client.getAll();
+
+    // validate - there should be nothing to find
+    assertEquals(2, results.length);
+    for(Result result : results) {
+      Assert.assertTrue(result.isEmpty());
+    }
+  }
+
+  /**
    * Should be able to read back widgets that were written with a TTL 30 days out.
    */
   @Test


Mime
View raw message