Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 9fd035c04 -> 58bb80106


Replacing deprecated HBase APIs. Tests seem to run faster as a result


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

Branch: refs/heads/camel-2.17.x
Commit: 58bb8010608256cf967147987affbde40393e7df
Parents: 9fd035c
Author: Colm O hEigeartaigh <cohei...@apache.org>
Authored: Mon Jun 27 13:13:41 2016 +0100
Committer: Colm O hEigeartaigh <cohei...@apache.org>
Committed: Mon Jun 27 14:55:13 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/component/hbase/HBaseConsumer.java  | 15 ++++++++-------
 .../apache/camel/component/hbase/HBaseProducer.java  |  7 ++++---
 .../camel/component/hbase/CamelHBaseTestSupport.java |  2 +-
 .../camel/component/hbase/HBaseConvertionsTest.java  |  8 ++++++--
 .../camel/component/hbase/HBaseProducerTest.java     |  9 ++++++---
 5 files changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/58bb8010/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
 
b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
index b54b284..715b586 100644
--- 
a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
+++ 
b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
@@ -32,7 +32,8 @@ import org.apache.camel.component.hbase.model.HBaseRow;
 import org.apache.camel.impl.ScheduledBatchPollingConsumer;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
@@ -102,8 +103,8 @@ public class HBaseConsumer extends 
ScheduledBatchPollingConsumer {
                 byte[] row = result.getRow();
                 
resultRow.setId(endpoint.getCamelContext().getTypeConverter().convertTo(rowModel.getRowType(),
 row));
 
-                List<KeyValue> keyValues = result.list();
-                if (keyValues != null) {
+                List<Cell> cells = result.listCells();
+                if (cells != null) {
                     Set<HBaseCell> cellModels = rowModel.getCells();
                     if (cellModels.size() > 0) {
                         for (HBaseCell modelCell : cellModels) {
@@ -120,13 +121,13 @@ public class HBaseConsumer extends 
ScheduledBatchPollingConsumer {
                         }
                     } else {
                         // just need to put every key value into the result 
Cells
-                        for (KeyValue keyValue : keyValues) {
-                            String qualifier = new 
String(keyValue.getQualifier());
-                            String family = new String(keyValue.getFamily());
+                        for (Cell cell : cells) {
+                            String qualifier = new 
String(CellUtil.cloneQualifier(cell));
+                            String family = new 
String(CellUtil.cloneFamily(cell));
                             HBaseCell resultCell = new HBaseCell();
                             resultCell.setFamily(family);
                             resultCell.setQualifier(qualifier);
-                            
resultCell.setValue(endpoint.getCamelContext().getTypeConverter().convertTo(String.class,
 keyValue.getValue()));
+                            
resultCell.setValue(endpoint.getCamelContext().getTypeConverter().convertTo(String.class,
 CellUtil.cloneValue(cell)));
                             resultRow.getCells().add(resultCell); 
                         }
                     }

http://git-wip-us.apache.org/repos/asf/camel/blob/58bb8010/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
 
b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
index b09c829..0c6cd5b 100644
--- 
a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
+++ 
b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
@@ -31,6 +31,7 @@ import org.apache.camel.component.hbase.model.HBaseRow;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.Put;
@@ -155,7 +156,7 @@ public class HBaseProducer extends DefaultProducer 
implements ServicePoolAware {
         Result result = table.get(get);
 
         if (!result.isEmpty()) {
-            resultRow.setTimestamp(result.raw()[0].getTimestamp());
+            resultRow.setTimestamp(result.rawCells()[0].getTimestamp());
         }
 
         for (HBaseCell cellModel : cellModels) {
@@ -168,7 +169,7 @@ public class HBaseProducer extends DefaultProducer 
implements ServicePoolAware {
             List<Cell> kvs = 
result.getColumnCells(HBaseHelper.getHBaseFieldAsBytes(family), 
HBaseHelper.getHBaseFieldAsBytes(column));
             if (kvs != null && !kvs.isEmpty()) {
                 //Return the most recent entry.
-                
resultCell.setValue(endpoint.getCamelContext().getTypeConverter().convertTo(cellModel.getValueType(),
 kvs.get(0).getValue()));
+                
resultCell.setValue(endpoint.getCamelContext().getTypeConverter().convertTo(cellModel.getValueType(),
 CellUtil.cloneValue(kvs.get(0))));
                 resultCell.setTimestamp(kvs.get(0).getTimestamp());
             }
             resultCells.add(resultCell);
@@ -233,7 +234,7 @@ public class HBaseProducer extends DefaultProducer 
implements ServicePoolAware {
             HBaseRow resultRow = new HBaseRow();
             
resultRow.setId(endpoint.getCamelContext().getTypeConverter().convertTo(model.getRowType(),
 result.getRow()));
 
-            resultRow.setTimestamp(result.raw()[0].getTimestamp());
+            resultRow.setTimestamp(result.rawCells()[0].getTimestamp());
             cellModels = model.getCells();
             for (HBaseCell modelCell : cellModels) {
                 HBaseCell resultCell = new HBaseCell();

http://git-wip-us.apache.org/repos/asf/camel/blob/58bb8010/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java
 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java
index 343852d..55906a3 100644
--- 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java
+++ 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java
@@ -124,7 +124,7 @@ public abstract class CamelHBaseTestSupport extends 
CamelTestSupport {
 
         for (int r = 0; r < key.length; r++) {
             Put put = new Put(key[r].getBytes());
-            put.add(family[0].getBytes(), column[0][0].getBytes(), 
body[r][0][0].getBytes());
+            put.addColumn(family[0].getBytes(), column[0][0].getBytes(), 
body[r][0][0].getBytes());
             table.put(put);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/58bb8010/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseConvertionsTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseConvertionsTest.java
 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseConvertionsTest.java
index 3535ad4..29064ac 100644
--- 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseConvertionsTest.java
+++ 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseConvertionsTest.java
@@ -23,9 +23,12 @@ import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.util.IOHelper;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Table;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.Test;
 
@@ -61,7 +64,8 @@ public class HBaseConvertionsTest extends 
CamelHBaseTestSupport {
             template.sendBodyAndHeaders("direct:start", null, headers);
 
             Configuration configuration = 
hbaseUtil.getHBaseAdmin().getConfiguration();
-            HTable bar = new HTable(configuration, PERSON_TABLE.getBytes());
+            Connection conn = 
ConnectionFactory.createConnection(configuration);
+            Table bar = conn.getTable(TableName.valueOf(PERSON_TABLE));
             Get get = new Get(Bytes.toBytes((Integer) key[0]));
 
             //Check row 1

http://git-wip-us.apache.org/repos/asf/camel/blob/58bb8010/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseProducerTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseProducerTest.java
 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseProducerTest.java
index e53ff37..b3aa15c 100644
--- 
a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseProducerTest.java
+++ 
b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseProducerTest.java
@@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.Table;
 import org.junit.Test;
@@ -126,7 +125,8 @@ public class HBaseProducerTest extends 
CamelHBaseTestSupport {
             template.sendBodyAndHeaders("direct:start", null, headers);
 
             Configuration configuration = 
hbaseUtil.getHBaseAdmin().getConfiguration();
-            HTable bar = new HTable(configuration, PERSON_TABLE.getBytes());
+            Connection conn = 
ConnectionFactory.createConnection(configuration);
+            Table bar = conn.getTable(TableName.valueOf(PERSON_TABLE));
 
             //Check row 1
             for (int row = 0; row < key.length; row++) {
@@ -316,7 +316,10 @@ public class HBaseProducerTest extends 
CamelHBaseTestSupport {
             template.sendBodyAndHeaders("direct:start", null, headers);
 
             Configuration configuration = 
hbaseUtil.getHBaseAdmin().getConfiguration();
-            HTable bar = new HTable(configuration, PERSON_TABLE.getBytes());
+            
+            Connection conn = 
ConnectionFactory.createConnection(configuration);
+            Table bar = conn.getTable(TableName.valueOf(PERSON_TABLE));
+            
             Get get = new Get("1".getBytes());
             get.addColumn("info".getBytes(), "id".getBytes());
             Result result = bar.get(get);

Reply via email to