hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r1438790 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/HTableDescriptor.java test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
Date Sat, 26 Jan 2013 00:21:01 GMT
Author: apurtell
Date: Sat Jan 26 00:21:01 2013
New Revision: 1438790

URL: http://svn.apache.org/viewvc?rev=1438790&view=rev
Log:
HBASE-7654. Add List<String> getCoprocessors() to HTableDescriptor (Jean-Marc Spaggiari)

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java?rev=1438790&r1=1438789&r2=1438790&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java Sat Jan
26 00:21:01 2013
@@ -22,10 +22,12 @@ package org.apache.hadoop.hbase;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
@@ -1033,10 +1035,10 @@ public class HTableDescriptor implements
     setValue(key, value);
   }
 
-  
+
   /**
    * Check if the table has an attached co-processor represented by the name className
-   * 
+   *
    * @param className - Class name of the co-processor
    * @return true of the table has a co-processor className
    */
@@ -1067,6 +1069,30 @@ public class HTableDescriptor implements
   }
 
   /**
+   * Return the list of attached co-processor represented by their name className
+   *
+   * @return The list of co-processors classNames
+   */
+  public List<String> getCoprocessors() {
+    List<String> result = new ArrayList<String>();
+    Matcher keyMatcher;
+    Matcher valueMatcher;
+    for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : this.values.entrySet())
{
+      keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get()));
+      if (!keyMatcher.matches()) {
+        continue;
+      }
+      valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes
+          .toString(e.getValue().get()));
+      if (!valueMatcher.matches()) {
+        continue;
+      }
+      result.add(valueMatcher.group(2).trim()); // classname is the 2nd field
+    }
+    return result;
+  }
+
+  /**
    * Remove a coprocessor from those set on the table
    * @param className Class name of the co-processor
    */

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java?rev=1438790&r1=1438789&r2=1438790&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java Sat
Jan 26 00:21:01 2013
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
+import org.apache.hadoop.hbase.coprocessor.SampleRegionWALObserver;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -49,6 +50,43 @@ public class TestHTableDescriptor {
   }
 
   /**
+   * Test cps in the table description
+   * @throws Exception
+   */
+  @Test
+  public void testSetListRemoveCP() throws Exception {
+    HTableDescriptor desc = new HTableDescriptor("testGetSetRemoveCP");
+    // simple CP
+    String className1 = BaseRegionObserver.class.getName();
+    String className2 = SampleRegionWALObserver.class.getName();
+    // Check that any coprocessor is present.
+    assertTrue(desc.getCoprocessors().size() == 0);
+
+    // Add the 1 coprocessor and check if present.
+    desc.addCoprocessor(className1);
+    assertTrue(desc.getCoprocessors().size() == 1);
+    assertTrue(desc.getCoprocessors().contains(className1));
+
+    // Add the 2nd coprocessor and check if present.
+    // remove it and check that it is gone
+    desc.addCoprocessor(className2);
+    assertTrue(desc.getCoprocessors().size() == 2);
+    assertTrue(desc.getCoprocessors().contains(className2));
+
+    // Remove one and check
+    desc.removeCoprocessor(className1);
+    assertTrue(desc.getCoprocessors().size() == 1);
+    assertFalse(desc.getCoprocessors().contains(className1));
+    assertTrue(desc.getCoprocessors().contains(className2));
+
+    // Remove the last and check
+    desc.removeCoprocessor(className2);
+    assertTrue(desc.getCoprocessors().size() == 0);
+    assertFalse(desc.getCoprocessors().contains(className1));
+    assertFalse(desc.getCoprocessors().contains(className2));
+  }
+
+  /**
    * Test that we add and remove strings from settings properly.
    * @throws Exception
    */



Mime
View raw message