camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [06/13] camel git commit: CAMEL-8478: IdempotentRepository - Add clear operation, align HBaseIdempotentRepository
Date Fri, 03 Jul 2015 20:23:50 GMT
CAMEL-8478: IdempotentRepository - Add clear operation, align HBaseIdempotentRepository


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

Branch: refs/heads/master
Commit: c93ef1d4e0b97606b257a8e6a210b8660303c667
Parents: da71c7b
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Jul 3 17:07:58 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Jul 3 17:07:58 2015 +0200

----------------------------------------------------------------------
 .../idempotent/HBaseIdempotentRepository.java    | 19 +++++++++++++++++++
 .../HBaseIdempotentRepositoryTest.java           | 17 +++++++++++++++++
 2 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c93ef1d4/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepository.java
b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepository.java
index 4459bba..05900a1 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepository.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepository.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.hbase.processor.idempotent;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
+
 import org.apache.camel.component.hbase.HBaseHelper;
 import org.apache.camel.spi.IdempotentRepository;
 import org.apache.camel.support.ServiceSupport;
@@ -28,6 +29,9 @@ import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -103,6 +107,21 @@ public class HBaseIdempotentRepository extends ServiceSupport implements
Idempot
     public boolean confirm(Object o) {
         return true;
     }
+    
+    @Override
+    public void clear() {
+        Scan s = new Scan();
+        ResultScanner scanner;
+        try {
+            scanner = table.getScanner(s);
+            for (Result rr : scanner) {
+                Delete d = new Delete(rr.getRow());
+                table.delete(d);
+            } 
+        } catch (Exception e) {
+            LOG.warn("Error clear HBase repository {}", table);
+        }
+    }    
 
     @Override
     protected void doStart() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/c93ef1d4/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java
index 352c59c..1baf1de 100644
--- a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java
+++ b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java
@@ -102,6 +102,23 @@ public class HBaseIdempotentRepositoryTest extends CamelHBaseTestSupport
{
             assertFalse(repository.remove(key02));
         }
     }
+    
+    @Test
+    public void testClear() throws Exception {
+        if (systemReady) {
+            // add key to remove
+            assertTrue(repository.add(key01));
+            assertTrue(repository.add(key02));
+            assertTrue(repository.contains(key01));
+            assertTrue(repository.contains(key02));
+
+            // remove key
+            repository.clear();
+
+            assertFalse(repository.contains(key01));
+            assertFalse(repository.contains(key02));
+        }
+    }
 
     @Test
     public void testConfirm() throws Exception {


Mime
View raw message