flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject svn commit: r1359895 - in /flume/trunk: ./ flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
Date Tue, 10 Jul 2012 20:56:26 GMT
Author: mpercy
Date: Tue Jul 10 20:56:26 2012
New Revision: 1359895

URL: http://svn.apache.org/viewvc?rev=1359895&view=rev
Log:
FLUME-1310. Make Asynch hbase sink test work with other versions of Hbase.

(Hari Shreedharan via Mike Percy)

Modified:
    flume/trunk/   (props changed)
    flume/trunk/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java

Propchange: flume/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul 10 20:56:26 2012
@@ -1 +1,2 @@
 target
+.swp

Modified: flume/trunk/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
URL: http://svn.apache.org/viewvc/flume/trunk/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java?rev=1359895&r1=1359894&r2=1359895&view=diff
==============================================================================
--- flume/trunk/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
(original)
+++ flume/trunk/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
Tue Jul 10 20:56:26 2012
@@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.client.HT
 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.master.HMaster;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
 import org.junit.AfterClass;
@@ -55,6 +56,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.primitives.Longs;
+import java.lang.reflect.Method;
 
 public class TestAsyncHBaseSink {
   private static HBaseTestingUtility testUtility;
@@ -85,7 +87,6 @@ public class TestAsyncHBaseSink {
     Configuration hbaseConf =  HBaseConfiguration.create();
 
     hbaseConf.set(HConstants.HBASE_DIR, hbaseRoot);
-    hbaseConf.set("hbase.master", "local");
     hbaseConf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181);
     hbaseConf.set(HConstants.ZOOKEEPER_QUORUM, "0.0.0.0");
     hbaseConf.setInt("hbase.master.info.port", -1);
@@ -93,11 +94,42 @@ public class TestAsyncHBaseSink {
     String zookeeperDir = new File(workDir,"zk").getAbsolutePath();
     int zookeeperPort = 2181;
     zookeeperCluster = new MiniZooKeeperCluster();
-    zookeeperCluster.setDefaultClientPort(zookeeperPort);
+    Method m;
+    Class<?> zkParam[] = {Integer.TYPE};
+    try{
+      m = MiniZooKeeperCluster.class.getDeclaredMethod("setDefaultClientPort",
+          zkParam);
+    } catch (NoSuchMethodException e) {
+      m = MiniZooKeeperCluster.class.getDeclaredMethod("setClientPort",
+          zkParam);
+    }
+
+    m.invoke(zookeeperCluster, new Object[] {new Integer(zookeeperPort)});
     zookeeperCluster.startup(new File(zookeeperDir));
-    hbaseCluster= new MiniHBaseCluster(hbaseConf, 1);
-    hbaseConf.set("hbase.master",
-        hbaseCluster.getMaster().getServerName().getHostAndPort());
+    hbaseCluster = new MiniHBaseCluster(hbaseConf, 1);
+    HMaster master = hbaseCluster.getMaster();
+    Object serverName = master.getServerName();
+    String hostAndPort;
+    if(serverName instanceof String) {
+      System.out.println("Server name is string, using HServerAddress.");
+      m = HMaster.class.getDeclaredMethod("getMasterAddress",
+          new Class<?>[]{});
+      Class<?> clazz = Class.forName("org.apache.hadoop.hbase.HServerAddress");
+      /*
+       * Call method to get server address
+       */
+      Object serverAddr = clazz.cast(m.invoke(master, new Object[]{}));
+      //returns the address as hostname:port
+      hostAndPort = serverAddr.toString();
+    } else {
+      System.out.println("ServerName is org.apache.hadoop.hbase.ServerName," +
+          "using getHostAndPort()");
+      Class<?> clazz = Class.forName("org.apache.hadoop.hbase.ServerName");
+      m = clazz.getDeclaredMethod("getHostAndPort", new Class<?>[] {});
+      hostAndPort = m.invoke(serverName, new Object[]{}).toString();
+    }
+
+    hbaseConf.set("hbase.master", hostAndPort);
     testUtility = new HBaseTestingUtility(hbaseConf);
     testUtility.setZkCluster(zookeeperCluster);
     hbaseCluster.startMaster();



Mime
View raw message