directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r904479 - in /directory/sandbox/seelmann/hbase-partition/src: main/java/org/apache/directory/server/core/partition/hbase/cursor/ main/java/org/apache/directory/server/core/partition/hbase/index/ main/java/org/apache/directory/server/core/pa...
Date Fri, 29 Jan 2010 12:07:55 GMT
Author: seelmann
Date: Fri Jan 29 12:07:52 2010
New Revision: 904479

URL: http://svn.apache.org/viewvc?rev=904479&view=rev
Log:
More test coverage

Added:
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/index/
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java
Modified:
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBaseOneLevelIndexCursor.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBasePresenceIndexCursor.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/index/HBasePresenceIndex.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTable.java
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBaseOneLevelIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBaseOneLevelIndexCursor.java?rev=904479&r1=904478&r2=904479&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBaseOneLevelIndexCursor.java
(original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBaseOneLevelIndexCursor.java
Fri Jan 29 12:07:52 2010
@@ -39,8 +39,10 @@
  */
 public class HBaseOneLevelIndexCursor extends BaseHBaseIndexCursor<Long>
 {
-
+    /** The entry ID of the search base. */
     private Long baseId;
+
+    /** The filter to apply while scanning. */
     private ExprNode filter;
 
 

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBasePresenceIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBasePresenceIndexCursor.java?rev=904479&r1=904478&r2=904479&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBasePresenceIndexCursor.java
(original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/cursor/HBasePresenceIndexCursor.java
Fri Jan 29 12:07:52 2010
@@ -20,13 +20,6 @@
 package org.apache.directory.server.core.partition.hbase.cursor;
 
 
-/**
- * HBase specific implementation of the presence index cursor.
- * There is no special presence index table, but the index tables are used.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.partition.hbase.HBaseStore;
 import org.apache.directory.server.core.partition.hbase.table.HBasePresenceIndexTable;
@@ -36,6 +29,13 @@
 import org.apache.hadoop.hbase.util.Bytes;
 
 
+/**
+ * HBase specific implementation of the presence index cursor.
+ * There is no special presence index table, but the index tables are used.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class HBasePresenceIndexCursor extends BaseHBaseIndexCursor<String>
 {
 

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/index/HBasePresenceIndex.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/index/HBasePresenceIndex.java?rev=904479&r1=904478&r2=904479&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/index/HBasePresenceIndex.java
(original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/index/HBasePresenceIndex.java
Fri Jan 29 12:07:52 2010
@@ -46,7 +46,6 @@
 
     public void close() throws Exception
     {
-        // TODO Auto-generated method stub
     }
 
 
@@ -69,7 +68,6 @@
     @Override
     public IndexCursor<String, ServerEntry> forwardCursor( String key ) throws Exception
     {
-        // TODO Auto-generated method stub
         return new HBasePresenceIndexCursor( key, store );
     }
 

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTable.java?rev=904479&r1=904478&r2=904479&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTable.java
(original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTable.java
Fri Jan 29 12:07:52 2010
@@ -81,12 +81,14 @@
     public void add( Long id ) throws Exception
     {
         add( Bytes.toBytes( id ) );
+        countCache.clear();
     }
 
 
     public void delete( Long id ) throws Exception
     {
         delete( Bytes.toBytes( id ) );
+        countCache.clear();
     }
 
 

Modified: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java?rev=904479&r1=904478&r2=904479&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java
(original)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java
Fri Jan 29 12:07:52 2010
@@ -24,6 +24,7 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.List;
 import java.util.NavigableMap;
 
 import org.apache.directory.server.core.entry.DefaultServerEntry;
@@ -48,10 +49,14 @@
  */
 public class HBaseIndexTableTest extends AbstractHBaseTableTest
 {
-    private static final String CN_INDEX_TABLE_NAME = TABLE_PREFIX + "index_cn";
     private static final String OBJECTCLASS_INDEX_TABLE_NAME = TABLE_PREFIX + "index_objectClass";
+    private static final String JPEGPHOTO_INDEX_TABLE_NAME = TABLE_PREFIX + "index_jpegPhoto";
+    private static final String CN_INDEX_TABLE_NAME = TABLE_PREFIX + "index_cn";
+    private static final String USERCERTIFICATE_INDEX_TABLE_NAME = TABLE_PREFIX + "index_userCertificate";
     private HBaseRowIndexTable objectClassIndexTable;
+    private HBaseRowIndexTable jpegPhotoIndexTable;
     private HBaseColumnIndexTable cnIndexTable;
+    private HBaseColumnIndexTable userCertificateIndexTable;
 
 
     /**
@@ -83,8 +88,10 @@
             }
         }
 
-        cnIndexTable = new HBaseColumnIndexTable( "2.5.4.3", schemaManager, TABLE_PREFIX
);
         objectClassIndexTable = new HBaseRowIndexTable( "2.5.4.0", schemaManager, TABLE_PREFIX
);
+        jpegPhotoIndexTable = new HBaseRowIndexTable( "0.9.2342.19200300.100.1.60", schemaManager,
TABLE_PREFIX );
+        cnIndexTable = new HBaseColumnIndexTable( "2.5.4.3", schemaManager, TABLE_PREFIX
);
+        userCertificateIndexTable = new HBaseColumnIndexTable( "2.5.4.36", schemaManager,
TABLE_PREFIX );
     }
 
 
@@ -375,6 +382,93 @@
 
 
     @Test
+    public void testGetScanKey() throws Exception
+    {
+        byte[] scanKey = objectClassIndexTable.getScanKey( "bar", Bytes.toBytes( 0L ) );
+        assertEquals( "=barAAAAAAAAAAA=", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassIndexTable.getScanKey( "foo", Bytes.toBytes( Long.MAX_VALUE
) );
+        assertEquals( "=foof/////////8=", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassIndexTable.getScanKey( "foobar", null );
+        assertEquals( "=foobar", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassIndexTable.getScanKey( "", Bytes.toBytes( 1L ) );
+        assertEquals( "=AAAAAAAAAAE=", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassIndexTable.getScanKey( HBaseIndexTable.FULL_SCAN_START, HBaseIndexTable.VALUE_SCAN_START
);
+        assertTrue( Bytes.equals( new byte[]
+            { '=', 0x00, 0x00 }, scanKey ) );
+
+        scanKey = objectClassIndexTable.getScanKey( HBaseIndexTable.FULL_SCAN_STOP, HBaseIndexTable.VALUE_SCAN_STOP
);
+        assertTrue( Bytes.equals( new byte[]
+            { '=', ( byte ) 0xFF, ( byte ) 0xFF }, scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( "bar", Bytes.toBytes( 0L ) );
+        assertEquals( "#bar", Bytes.toString( scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( "foo", Bytes.toBytes( Long.MAX_VALUE ) );
+        assertEquals( "#foo", Bytes.toString( scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( "foobar", null );
+        assertEquals( "#foobar", Bytes.toString( scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( "", Bytes.toBytes( 1L ) );
+        assertEquals( "#", Bytes.toString( scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( HBaseIndexTable.FULL_SCAN_START, HBaseIndexTable.VALUE_SCAN_START
);
+        assertTrue( Bytes.equals( new byte[]
+            { '#', 0x00, 0x00 }, scanKey ) );
+
+        scanKey = cnIndexTable.getScanKey( HBaseIndexTable.FULL_SCAN_STOP, HBaseIndexTable.VALUE_SCAN_STOP
);
+        assertTrue( Bytes.equals( new byte[]
+            { '#', ( byte ) 0xFF, ( byte ) 0xFF }, scanKey ) );
+    }
+
+
+    @Test
+    public void testGetValue() throws Exception
+    {
+        Object value = objectClassIndexTable.getValueFromEqualsKey( Bytes.toBytes( "=barAAAAAAAAAAA="
) );
+        assertEquals( "bar", value );
+
+        value = jpegPhotoIndexTable.getValueFromEqualsKey( new byte[]
+            { '=', 0x00, 0x01, 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', '='
} );
+        assertTrue( Bytes.equals( new byte[]
+            { 0x00, 0x01 }, ( byte[] ) value ) );
+
+        value = objectClassIndexTable.getValueFromCountKey( Bytes.toBytes( "#foo" ) );
+        assertEquals( "foo", value );
+
+        value = jpegPhotoIndexTable.getValueFromCountKey( new byte[]
+            { '#', ( byte ) 0xEF, ( byte ) 0xFF } );
+        assertTrue( Bytes.equals( new byte[]
+            { ( byte ) 0xEF, ( byte ) 0xFF }, ( byte[] ) value ) );
+
+        value = cnIndexTable.getValueFromCountKey( Bytes.toBytes( "#foobar" ) );
+        assertEquals( "foobar", value );
+
+        value = userCertificateIndexTable.getValueFromCountKey( new byte[]
+            { '#', 0x00, 0x01 } );
+        assertTrue( Bytes.equals( new byte[]
+            { 0x00, 0x01 }, ( byte[] ) value ) );
+    }
+
+
+    @Test
+    public void testGetColumnCandidates() throws Exception
+    {
+        DefaultServerEntry cnEntry = buildCnJohnnyWalkerEntry();
+        cnIndexTable.add( cnEntry.get( "cn" ), 3L );
+
+        List<Long> candidates = cnIndexTable.getColumnCandidates( "johnny \u65E5\u672C
walker" );
+        assertNotNull( candidates );
+        assertEquals( 1, candidates.size() );
+        assertTrue( candidates.contains( 3L ) );
+    }
+
+
+    @Test
     public void last() throws Exception
     {
     }

Added: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java?rev=904479&view=auto
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java
(added)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java
Fri Jan 29 12:07:52 2010
@@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.partition.hbase.table;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.NavigableMap;
+
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+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.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests for {@link HBaseIndexTableBase}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HBasePresenceIndexTableTest extends AbstractHBaseTableTest
+{
+    private static final String OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME = TABLE_PREFIX + "index_objectClass";
+    private static final String JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME = TABLE_PREFIX + "index_jpegPhoto";
+    private HBasePresenceIndexTable objectClassPresenceIndexTable;
+    private HBasePresenceIndexTable jpegPhotoPresenceIndexTable;
+
+
+    /**
+     * Cleanup HBase tables before each test.
+     * 
+     */
+    @Before
+    public void setup() throws Exception
+    {
+        HBaseAdmin admin = new HBaseAdmin( adapter.getHBaseConfigurtion() );
+        if ( admin.tableExists( OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME ) )
+        {
+            HTable objectClassIndexHTable = new HTable( OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME
);
+            ResultScanner treeScanner = objectClassIndexHTable.getScanner( new Scan() );
+            Result treeResult;
+            while ( ( treeResult = treeScanner.next() ) != null )
+            {
+                objectClassIndexHTable.delete( new Delete( treeResult.getRow() ) );
+            }
+        }
+        if ( admin.tableExists( JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME ) )
+        {
+            HTable objectClassIndexHTable = new HTable( JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME
);
+            ResultScanner treeScanner = objectClassIndexHTable.getScanner( new Scan() );
+            Result treeResult;
+            while ( ( treeResult = treeScanner.next() ) != null )
+            {
+                objectClassIndexHTable.delete( new Delete( treeResult.getRow() ) );
+            }
+        }
+
+        objectClassPresenceIndexTable = new HBasePresenceIndexTable( "2.5.4.0", schemaManager,
TABLE_PREFIX );
+        jpegPhotoPresenceIndexTable = new HBasePresenceIndexTable( "0.9.2342.19200300.100.1.60",
schemaManager,
+            TABLE_PREFIX );
+    }
+
+
+    @Test
+    public void first() throws Exception
+    {
+        objectClassPresenceIndexTable.add( 1L );
+    }
+
+
+    @Test
+    public void testAdd() throws Exception
+    {
+        // 1st entry
+        objectClassPresenceIndexTable.add( 1L );
+
+        HTable objectClassPresenceIndexHTable = new HTable( OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME
);
+
+        Get presenceGet = new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes.toBytes( Base64.encodeBytes(
Bytes
+            .toBytes( 1L ) ) ) ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( presenceGet ) );
+        Result presenceResult = objectClassPresenceIndexHTable.get( presenceGet );
+        Get countGet = new Get( Bytes.toBytes( "!" ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( countGet ) );
+        Result countResult = objectClassPresenceIndexHTable.get( countGet );
+
+        NavigableMap<byte[], byte[]> presenceInfoMap = presenceResult.getFamilyMap(
Bytes.toBytes( "info" ) );
+        assertNotNull( presenceInfoMap );
+        assertEquals( 1, presenceInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( presenceInfoMap.get( Bytes.toBytes( "id" ) ) ) );
+
+        NavigableMap<byte[], byte[]> countInfoMap = countResult.getFamilyMap( Bytes.toBytes(
"info" ) );
+        assertNotNull( countInfoMap );
+        assertEquals( 1, countInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( countInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        // 2nd entry
+        objectClassPresenceIndexTable.add( 2L );
+
+        // 3rd entry
+        objectClassPresenceIndexTable.add( 3L );
+        jpegPhotoPresenceIndexTable.add( 3L );
+
+        HTable jpegPhotoPresenceIndexHTable = new HTable( JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME
);
+
+        assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertTrue( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+
+        countGet = new Get( Bytes.toBytes( "!" ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( countGet ) );
+        countResult = objectClassPresenceIndexHTable.get( countGet );
+        countInfoMap = countResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( countInfoMap );
+        assertEquals( 1, countInfoMap.size() );
+        assertEquals( 3L, Bytes.toLong( countInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        countGet = new Get( Bytes.toBytes( "!" ) );
+        assertTrue( jpegPhotoPresenceIndexHTable.exists( countGet ) );
+        countResult = jpegPhotoPresenceIndexHTable.get( countGet );
+        countInfoMap = countResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( countInfoMap );
+        assertEquals( 1, countInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( countInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+    }
+
+
+    @Test
+    public void testDelete() throws Exception
+    {
+        // 1st entry
+        objectClassPresenceIndexTable.add( 1L );
+        // 2nd entry
+        objectClassPresenceIndexTable.add( 2L );
+        // 3rd entry
+        objectClassPresenceIndexTable.add( 3L );
+        jpegPhotoPresenceIndexTable.add( 3L );
+
+        HTable objectClassPresenceIndexHTable = new HTable( OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME
);
+        HTable jpegPhotoPresenceIndexHTable = new HTable( JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME
);
+
+        // detete 3rd entry
+        objectClassPresenceIndexTable.delete( 3L );
+        jpegPhotoPresenceIndexTable.delete( 3L );
+
+        assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertFalse( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+
+        Get countGet = new Get( Bytes.toBytes( "!" ) );
+        assertTrue( objectClassPresenceIndexHTable.exists( countGet ) );
+        Result countResult = objectClassPresenceIndexHTable.get( countGet );
+        NavigableMap<byte[], byte[]> countInfoMap = countResult.getFamilyMap( Bytes.toBytes(
"info" ) );
+        assertNotNull( countInfoMap );
+        assertEquals( 1, countInfoMap.size() );
+        assertEquals( 2L, Bytes.toLong( countInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        countGet = new Get( Bytes.toBytes( "!" ) );
+        assertTrue( jpegPhotoPresenceIndexHTable.exists( countGet ) );
+        countResult = jpegPhotoPresenceIndexHTable.get( countGet );
+        countInfoMap = countResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( countInfoMap );
+        assertEquals( 1, countInfoMap.size() );
+        assertEquals( 0L, Bytes.toLong( countInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        // detete 2nd and 1st entry
+        objectClassPresenceIndexTable.delete( 2L );
+        objectClassPresenceIndexTable.delete( 1L );
+
+        assertFalse( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertFalse( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertFalse( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes(
"*" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+    }
+
+
+    @Test
+    public void testCount() throws Exception
+    {
+        assertEquals( 0, objectClassPresenceIndexTable.count() );
+
+        // 1st entry
+        objectClassPresenceIndexTable.add( 1L );
+
+        assertEquals( 1, objectClassPresenceIndexTable.count() );
+
+        // 2nd entry
+        objectClassPresenceIndexTable.add( 2L );
+
+        assertEquals( 2, objectClassPresenceIndexTable.count() );
+
+        // 3rd entry
+        objectClassPresenceIndexTable.add( 3L );
+        jpegPhotoPresenceIndexTable.add( 3L );
+
+        assertEquals( 3, objectClassPresenceIndexTable.count() );
+        assertEquals( 1, jpegPhotoPresenceIndexTable.count() );
+
+        // delete 3rd and 2nd
+        objectClassPresenceIndexTable.delete( 3L );
+        jpegPhotoPresenceIndexTable.delete( 3L );
+        objectClassPresenceIndexTable.delete( 2L );
+
+        assertEquals( 1, objectClassPresenceIndexTable.count() );
+        assertEquals( 0, jpegPhotoPresenceIndexTable.count() );
+
+        // delete 1st
+        objectClassPresenceIndexTable.delete( 1L );
+
+        assertEquals( 0, objectClassPresenceIndexTable.count() );
+    }
+
+
+    @Test
+    public void testExists() throws Exception
+    {
+        assertFalse( objectClassPresenceIndexTable.exists( 1L ) );
+        assertFalse( objectClassPresenceIndexTable.exists( 2L ) );
+        assertFalse( objectClassPresenceIndexTable.exists( 3L ) );
+        assertFalse( jpegPhotoPresenceIndexTable.exists( 3L ) );
+
+        // 1st entry
+        objectClassPresenceIndexTable.add( 1L );
+
+        assertTrue( objectClassPresenceIndexTable.exists( 1L ) );
+
+        // 2nd entry
+        objectClassPresenceIndexTable.add( 2L );
+
+        assertTrue( objectClassPresenceIndexTable.exists( 2L ) );
+
+        // 3rd entry
+        objectClassPresenceIndexTable.add( 3L );
+        jpegPhotoPresenceIndexTable.add( 3L );
+        assertTrue( objectClassPresenceIndexTable.exists( 3L ) );
+        assertTrue( jpegPhotoPresenceIndexTable.exists( 3L ) );
+
+        // delete 3rd and 2nd
+        objectClassPresenceIndexTable.delete( 3L );
+        jpegPhotoPresenceIndexTable.delete( 3L );
+        objectClassPresenceIndexTable.delete( 2L );
+
+        assertTrue( objectClassPresenceIndexTable.exists( 1L ) );
+        assertFalse( objectClassPresenceIndexTable.exists( 2L ) );
+        assertFalse( objectClassPresenceIndexTable.exists( 3L ) );
+        assertFalse( jpegPhotoPresenceIndexTable.exists( 3L ) );
+
+        // delete 1st
+        objectClassPresenceIndexTable.delete( 1L );
+
+        assertFalse( objectClassPresenceIndexTable.exists( 1L ) );
+    }
+
+
+    @Test
+    public void testGetScanKey() throws Exception
+    {
+        byte[] scanKey = objectClassPresenceIndexTable.getPresenceKey( Bytes.toBytes( 0L
) );
+        assertEquals( "*AAAAAAAAAAA=", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassPresenceIndexTable.getPresenceKey( Bytes.toBytes( Long.MAX_VALUE
) );
+        assertEquals( "*f/////////8=", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassPresenceIndexTable.getPresenceKey( null );
+        assertEquals( "*", Bytes.toString( scanKey ) );
+
+        scanKey = objectClassPresenceIndexTable.getPresenceKey( HBasePresenceIndexTable.VALUE_SCAN_FIRST_ENTRYID
);
+        assertTrue( Bytes.equals( new byte[]
+            { '*', 0x00 }, scanKey ) );
+
+        scanKey = objectClassPresenceIndexTable.getPresenceKey( HBasePresenceIndexTable.VALUE_SCAN_LAST_ENTRYID
);
+        assertTrue( Bytes.equals( new byte[]
+            { '*', ( byte ) 0xFF }, scanKey ) );
+    }
+
+
+    @Test
+    public void last() throws Exception
+    {
+    }
+
+}



Mime
View raw message