hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1426729 [2/2] - in /hbase/trunk: hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/ hbase-protocol/src/main/protobuf/ hbase-server/src/main/java/org/apache/hadoop/hbase/io/ hbase-server/src/main/java/org/apache/hadoop...
Date Sat, 29 Dec 2012 09:27:24 GMT
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java?rev=1426729&r1=1426728&r2=1426729&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java
Sat Dec 29 09:27:24 2012
@@ -132,8 +132,7 @@ public class ZKPermissionWatcher extends
           LOG.debug("Updating permissions cache from node "+table+" with data: "+
               Bytes.toStringBinary(nodeData));
         }
-        authManager.refreshCacheFromWritable(Bytes.toBytes(table),
-          nodeData);
+        authManager.refreshCacheFromWritable(Bytes.toBytes(table), nodeData);
       } catch (IOException ioe) {
         LOG.error("Failed parsing permissions for table '" + table +
             "' from zk", ioe);

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java?rev=1426729&r1=1426728&r2=1426729&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
Sat Dec 29 09:27:24 2012
@@ -521,17 +521,6 @@ public class TestSerialization {
   }
   */
 
-  @Test public void testTimeRange() throws Exception{
-    TimeRange tr = new TimeRange(0,5);
-    byte [] mb = Writables.getBytes(tr);
-    TimeRange deserializedTr =
-      (TimeRange)Writables.getWritable(mb, new TimeRange());
-
-    assertEquals(tr.getMax(), deserializedTr.getMax());
-    assertEquals(tr.getMin(), deserializedTr.getMin());
-
-  }
-
   protected static final int MAXVERSIONS = 3;
   protected final static byte [] fam1 = Bytes.toBytes("colfamily1");
   protected final static byte [] fam2 = Bytes.toBytes("colfamily2");

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java?rev=1426729&r1=1426728&r2=1426729&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
Sat Dec 29 09:27:24 2012
@@ -24,19 +24,21 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
+import java.io.DataOutput;
 import java.io.DataOutputStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Abortable;
+import org.apache.hadoop.hbase.DeserializationException;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.LargeTests;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -45,6 +47,7 @@ import org.apache.hadoop.hbase.client.Pu
 import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.io.Text;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -104,6 +107,56 @@ public class TestTablePermissions {
     UTIL.shutdownMiniCluster();
   }
 
+
+  /**
+   * Test we can read permissions serialized with Writables.
+   * @throws DeserializationException
+   */
+  @Test
+  public void testMigration() throws DeserializationException {
+    Configuration conf = UTIL.getConfiguration();
+    ListMultimap<String,TablePermission> permissions = createPermissions();
+    byte [] bytes = writePermissionsAsBytes(permissions, conf);
+    AccessControlLists.readPermissions(bytes, conf);
+  }
+
+  /**
+   * Writes a set of permissions as {@link org.apache.hadoop.io.Writable} instances     
                                                                                         
                     
+   * and returns the resulting byte array.  Used to verify we can read stuff written
+   * with Writable.
+   */
+  public static byte[] writePermissionsAsBytes(ListMultimap<String,? extends Permission>
perms,
+      Configuration conf) {
+    try {
+       ByteArrayOutputStream bos = new ByteArrayOutputStream();
+       writePermissions(new DataOutputStream(bos), perms, conf);
+       return bos.toByteArray();
+    } catch (IOException ioe) {
+      // shouldn't happen here
+      throw new RuntimeException("Error serializing permissions", ioe);
+    }
+  }
+
+  /**
+   * Writes a set of permissions as {@link org.apache.hadoop.io.Writable} instances
+   * to the given output stream.
+   * @param out
+   * @param perms
+   * @param conf
+   * @throws IOException
+  */
+  public static void writePermissions(DataOutput out,                                   
                                                                                         
                     
+      ListMultimap<String,? extends Permission> perms, Configuration conf)
+  throws IOException {
+    Set<String> keys = perms.keySet();
+    out.writeInt(keys.size());
+    for (String key : keys) {
+      Text.writeString(out, key);
+      HbaseObjectWritableFor96Migration.writeObject(out, perms.get(key), List.class, conf);
+    }
+  }
+
+
   @Test
   public void testBasicWrite() throws Exception {
     Configuration conf = UTIL.getConfiguration();
@@ -243,6 +296,16 @@ public class TestTablePermissions {
   @Test
   public void testSerialization() throws Exception {
     Configuration conf = UTIL.getConfiguration();
+    ListMultimap<String,TablePermission> permissions = createPermissions();
+    byte[] permsData = AccessControlLists.writePermissionsAsBytes(permissions, conf);
+
+    ListMultimap<String,TablePermission> copy =
+        AccessControlLists.readPermissions(permsData, conf);
+
+    checkMultimapEqual(permissions, copy);
+  }
+
+  private ListMultimap<String,TablePermission> createPermissions() {
     ListMultimap<String,TablePermission> permissions = ArrayListMultimap.create();
     permissions.put("george", new TablePermission(TEST_TABLE, null,
         TablePermission.Action.READ));
@@ -252,13 +315,7 @@ public class TestTablePermissions {
         TablePermission.Action.READ));
     permissions.put("hubert", new TablePermission(TEST_TABLE2, null,
         TablePermission.Action.READ, TablePermission.Action.WRITE));
-
-    byte[] permsData = AccessControlLists.writePermissionsAsBytes(permissions, conf);
-
-    ListMultimap<String,TablePermission> copy =
-        AccessControlLists.readPermissions(permsData, conf);
-
-    checkMultimapEqual(permissions, copy);
+    return permissions;
   }
 
   public void checkMultimapEqual(ListMultimap<String,TablePermission> first,



Mime
View raw message