You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2010/01/26 01:12:54 UTC

svn commit: r903024 - in /directory/sandbox/seelmann/hbase-partition: ./ src/main/java/org/apache/directory/server/core/partition/hbase/table/ src/test/java/org/apache/directory/server/core/partition/hbase/ src/test/java/org/apache/directory/server/cor...

Author: seelmann
Date: Tue Jan 26 00:12:54 2010
New Revision: 903024

URL: http://svn.apache.org/viewvc?rev=903024&view=rev
Log:
Added more tests, some bug fixes

Added:
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/AbstractHBaseTableTest.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/pom.xml
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseColumnIndexTable.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableBase.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTable.java
    directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseRowIndexTable.java
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/HBaseClusterTestCaseAdapter.java
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/it/AbstractHBasePartitionIT.java
    directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java

Modified: directory/sandbox/seelmann/hbase-partition/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/pom.xml?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/pom.xml (original)
+++ directory/sandbox/seelmann/hbase-partition/pom.xml Tue Jan 26 00:12:54 2010
@@ -139,6 +139,7 @@
 
   <build>
     <plugins>
+      <!-- 
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
@@ -147,6 +148,7 @@
           </includes>
         </configuration>
       </plugin>
+       -->
       <!-- Delete build and test directories that were crated by hbase tests -->
       <plugin>
         <artifactId>maven-clean-plugin</artifactId>

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseColumnIndexTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseColumnIndexTable.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseColumnIndexTable.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseColumnIndexTable.java Tue Jan 26 00:12:54 2010
@@ -63,7 +63,12 @@
 
     public int count( Object value ) throws Exception
     {
-        Info info = fetchInfo( getCountKey( value ) );
+        byte[] countKey = getCountKey( value );
+        Info info = fetchInfo( countKey );
+        if ( info == null )
+        {
+            return 0;
+        }
         return info.count.intValue();
     }
 
@@ -106,7 +111,12 @@
 
     public List<Long> getColumnCandidates( Object value ) throws Exception
     {
-        Info info = fetchInfo( getCountKey( value ) );
+        byte[] countKey = getCountKey( value );
+        Info info = fetchInfo( countKey );
+        if ( info == null )
+        {
+            return null;
+        }
         return info.candidates;
     }
 
@@ -129,7 +139,12 @@
      */
     public boolean exists( Object value, Long id ) throws Exception
     {
-        Info info = fetchInfo( getCountKey( value ) );
+        byte[] countKey = getCountKey( value );
+        Info info = fetchInfo( countKey );
+        if ( info == null )
+        {
+            return false;
+        }
         boolean exists = info.candidates.contains( id );
         return exists;
     }
@@ -137,6 +152,10 @@
 
     private Info fetchInfo( byte[] row ) throws Exception
     {
+        if ( row == null )
+        {
+            return null;
+        }
         String key = String.valueOf( Base64.encode( row ) );
         if ( infoCache.contains( key ) )
         {
@@ -146,6 +165,10 @@
         Get get = new Get( row );
         get.addFamily( INFO_FAMILY );
         Result result = HBaseTableHelper.get( getIndexTablePool(), indexTableName, get );
+        if ( result.getRow() == null )
+        {
+            return null;
+        }
         return extractInfo( result );
     }
 
@@ -183,7 +206,7 @@
 
     protected void add( byte[] value, Long id ) throws Exception
     {
-        // exact match (attribute=value): #value -> count, value, id
+        // exact match (attribute=value): #value -> count, id
         // check first if the index already exists because we won't increment the index count
         byte[] exactCountRow = getCountKey( value );
         Get exactGet = new Get( exactCountRow );
@@ -192,20 +215,23 @@
         {
             // get+put+put is not atomic!
             Put exactPut = new Put( exactCountRow );
-            exactPut.setWriteToWAL( false );
+            //exactPut.setWriteToWAL( false );
             exactPut.add( INFO_FAMILY, Bytes.toBytes( id ), Bytes.toBytes( id ) );
             HBaseTableHelper.put( getIndexTablePool(), indexTableName, exactPut );
 
-            // increment exact match count: value: -> count
+            // increment exact match count: #value -> count
             HBaseTableHelper.increment( getIndexTablePool(), indexTableName, exactCountRow, INFO_FAMILY,
                 COUNT_QUALIFIER );
         }
+
+        // TODO: optimize - don't need to clear the ẃhole cache
+        infoCache.clear();
     }
 
 
     protected void delete( byte[] value, Long id ) throws Exception
     {
-        // exact match (attribute=value): #value -> count, value, id
+        // exact match (attribute=value): #value -> count, id
         // check first if the index exists because we won't decrement the index count otherwise
         byte[] exactCountRow = getCountKey( value );
         Get exactGet = new Get( exactCountRow );
@@ -216,10 +242,14 @@
             exactDel.deleteColumn( INFO_FAMILY, Bytes.toBytes( id ) );
             HBaseTableHelper.delete( getIndexTablePool(), indexTableName, exactDel );
 
-            // decrement exact match count: #value:0 -> count
+            // decrement exact match count: #value -> count
             HBaseTableHelper.decrement( getIndexTablePool(), indexTableName, exactCountRow, INFO_FAMILY,
                 COUNT_QUALIFIER );
+            // TODO: delete column if count is 0?
         }
+
+        // TODO: optimize - don't need to clear the ẃhole cache
+        infoCache.clear();
     }
 
     class Info

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableBase.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableBase.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableBase.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableBase.java Tue Jan 26 00:12:54 2010
@@ -80,6 +80,10 @@
         {
             add( value.getBytes(), id );
         }
+
+        // TODO: optimize - don't need to clear the ẃhole cache
+        countCache.clear();
+        existsCache.clear();
     }
 
 
@@ -92,6 +96,10 @@
         {
             delete( value.getBytes(), id );
         }
+
+        // TODO: optimize - don't need to clear the ẃhole cache
+        countCache.clear();
+        existsCache.clear();
     }
 
 
@@ -155,6 +163,11 @@
      */
     protected byte[] getCountKey( Object value ) throws Exception
     {
+        if ( value == null )
+        {
+            return null;
+        }
+
         ByteBuffer bb = new ByteBuffer();
 
         bb.append( '#' );

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTable.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTable.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTable.java Tue Jan 26 00:12:54 2010
@@ -688,7 +688,7 @@
             this.normName = normName;
             this.upName = upName;
             this.treeTableKey = Bytes.add( Bytes.toBytes( parentId ), KEY_DELIMITER_BYTES, Bytes.toBytes( normName ) );
-            this.string = parentId + KEY_DELIMITER + normName;
+            this.string = "" + parentId + KEY_DELIMITER + normName;
         }
     }
 

Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseRowIndexTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseRowIndexTable.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseRowIndexTable.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/table/HBaseRowIndexTable.java Tue Jan 26 00:12:54 2010
@@ -67,6 +67,11 @@
      */
     private byte[] getEqualsKey( Object value, Long id ) throws Exception
     {
+        if ( value == null || id == null )
+        {
+            return null;
+        }
+
         ByteBuffer bb = new ByteBuffer();
 
         bb.append( '=' );
@@ -141,6 +146,10 @@
         }
 
         byte[] row = getCountKey( value );
+        if ( row == null )
+        {
+            return 0;
+        }
         Long count = HBaseTableHelper.getLongValue( getIndexTablePool(), indexTableName, row, INFO_FAMILY,
             COUNT_QUALIFIER, 0L );
         countCache.put( value, count );
@@ -157,6 +166,10 @@
         }
 
         byte[] row = getEqualsKey( value, id );
+        if ( row == null )
+        {
+            return false;
+        }
         Get get = new Get( row );
         boolean exists = HBaseTableHelper.exists( getIndexTablePool(), indexTableName, get );
         existsCache.put( key, exists );
@@ -174,7 +187,7 @@
         {
             // get+put+put is not atomic!
             Put exactPut = new Put( exactRow );
-            exactPut.setWriteToWAL( false );
+            //exactPut.setWriteToWAL( false );
             exactPut.add( INFO_FAMILY, ID_QUALIFIER, Bytes.toBytes( id ) );
             HBaseTableHelper.put( getIndexTablePool(), indexTableName, exactPut );
 
@@ -188,7 +201,7 @@
 
     protected void delete( byte[] value, Long id ) throws Exception
     {
-        // exact match (attribute=value): =value<id> -> id, value
+        // exact match (attribute=value): =value<id> -> id
         // check first if the index exists because we won't decrement the index count otherwise
         byte[] exactRow = getEqualsKey( value, id );
         Get exactGet = new Get( exactRow );
@@ -201,6 +214,7 @@
             byte[] exactCountRow = getCountKey( value );
             HBaseTableHelper.decrement( getIndexTablePool(), indexTableName, exactCountRow, INFO_FAMILY,
                 COUNT_QUALIFIER );
+            // TODO: delete column if count is 0?
         }
     }
 

Modified: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/HBaseClusterTestCaseAdapter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/HBaseClusterTestCaseAdapter.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/HBaseClusterTestCaseAdapter.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/HBaseClusterTestCaseAdapter.java Tue Jan 26 00:12:54 2010
@@ -20,8 +20,11 @@
 package org.apache.directory.server.core.partition.hbase;
 
 
+import java.io.File;
+
 import org.apache.hadoop.hbase.HBaseClusterTestCase;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HConstants;
 import org.junit.Ignore;
 
 
@@ -40,19 +43,42 @@
     /**
      * Instantiates a new HBaseClusterTestCase.
      * 
-     * @param clazz the clazz
+     * @param clazz the class
+     * @param startDfs true to start a MiniDFS (distributed file system)
      */
-    public HBaseClusterTestCaseAdapter( Class<?> clazz )
+    public HBaseClusterTestCaseAdapter( Class<?> clazz, boolean startDfs ) throws Exception
     {
-        super();
+        super( 1, startDfs );
         setName( clazz.getName() );
+
+        // use target as test  directory base
+        File testDir = new File( "target/data" );
+        conf.set( TEST_DIRECTORY_KEY, testDir.getAbsolutePath() );
+
+        // setup local file system if no DFS is used
+        if ( !startDfs )
+        {
+            String unitTestDir = getUnitTestdir( getName() ).toString();
+            String hbaseRootDirUrl = new File( unitTestDir, "hbase" ).toURI().toURL().toString();
+            conf.set( HConstants.HBASE_DIR, hbaseRootDirUrl );
+        }
     }
 
 
     @Override
     public void setUp() throws Exception
     {
+        // don't open META table in setUp, sometimes timeouts occurs...
+        if ( !startDfs )
+        {
+            super.setOpenMetaTable( false );
+        }
+
         super.setUp();
+
+        // opening the META table ensures that cluster is running
+        //Thread.sleep( 10000 );
+        //new HTable(conf, HConstants.META_TABLE_NAME);
     }
 
 

Modified: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/it/AbstractHBasePartitionIT.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/it/AbstractHBasePartitionIT.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/it/AbstractHBasePartitionIT.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/it/AbstractHBasePartitionIT.java Tue Jan 26 00:12:54 2010
@@ -51,7 +51,7 @@
     @BeforeClass
     public static void before() throws Exception
     {
-        adapter = new HBaseClusterTestCaseAdapter( AbstractHBasePartitionIT.class );
+        adapter = new HBaseClusterTestCaseAdapter( AbstractHBasePartitionIT.class, true );
         adapter.setUp();
     }
 

Added: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/AbstractHBaseTableTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/AbstractHBaseTableTest.java?rev=903024&view=auto
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/AbstractHBaseTableTest.java (added)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/AbstractHBaseTableTest.java Tue Jan 26 00:12:54 2010
@@ -0,0 +1,161 @@
+/*
+ * 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.fail;
+
+import java.io.File;
+import java.util.UUID;
+
+import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.partition.hbase.HBaseClusterTestCaseAdapter;
+import org.apache.directory.server.core.partition.hbase.it.AbstractHBasePartitionIT;
+import org.apache.directory.shared.ldap.csn.CsnFactory;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+
+/**
+ * Basic class for table tests.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractHBaseTableTest
+{
+    protected static final String TABLE_PREFIX = "apacheds_test_";
+    protected static final CsnFactory CSN_FACTORY = new CsnFactory( 0 );
+    protected static HBaseClusterTestCaseAdapter adapter;
+    protected static SchemaManager schemaManager;
+    protected static LdapDN suffixDn;
+
+
+    /**
+     * Startup mini HBase cluster.
+     */
+    @BeforeClass
+    public static void statupMiniCluster() throws Exception
+    {
+        adapter = new HBaseClusterTestCaseAdapter( AbstractHBasePartitionIT.class, false );
+        adapter.setUp();
+    }
+
+
+    /**
+     * Shutdown mini HBase cluster.
+     */
+    @AfterClass
+    public static void shutdownMiniCluster() throws Exception
+    {
+        adapter.tearDown();
+    }
+
+
+    /**
+     * Init schema manager and suffix
+     */
+    @BeforeClass
+    public static void initSchemaManager() throws Exception
+    {
+        String workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = AbstractHBaseTableTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+
+        File schemaRepository = new File( workingDirectory, "schema" );
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+        extractor.extractOrCopy( true );
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        schemaManager = new DefaultSchemaManager( loader );
+
+        boolean loaded = schemaManager.loadAllEnabled();
+
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+
+        suffixDn = new LdapDN( "o=Good Times Co." );
+        suffixDn.normalize( schemaManager.getNormalizerMapping() );
+    }
+
+
+    protected DefaultServerEntry buildContextEntry() throws NamingException
+    {
+        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, suffixDn );
+        entry.add( "objectClass", "organization" );
+        entry.add( "o", "Good Times Co." );
+        entry.add( "postalCode", "1" );
+        entry.add( "postOfficeBox", "1" );
+        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
+        entry.add( "entryUUID", UUID.randomUUID().toString() );
+        return entry;
+    }
+
+
+    protected DefaultServerEntry buildOuSalesEntry() throws InvalidNameException, NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=Sales \\E6\\97\\A5\\E6\\9C\\AC,o=Good Times Co." );
+        dn.normalize( schemaManager.getNormalizerMapping() );
+        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
+        entry.add( "objectClass", "top", "organizationalUnit" );
+        entry.add( "ou", "Sales \u65E5\u672C" );
+        entry.add( "postalCode", "1" );
+        entry.add( "postOfficeBox", "1" );
+        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
+        entry.add( "entryUUID", UUID.randomUUID().toString() );
+        return entry;
+    }
+
+
+    protected DefaultServerEntry buildCnJohnnyWalkerEntry() throws InvalidNameException, NamingException
+    {
+        LdapDN dn = new LdapDN(
+            "cn=JOhnny \\E6\\97\\A5\\E6\\9C\\AC WAlkeR,ou=Sales \\E6\\97\\A5\\E6\\9C\\AC,o=Good Times Co." );
+        dn.normalize( schemaManager.getNormalizerMapping() );
+        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
+        entry.add( "objectClass", "top", "person", "organizationalPerson" );
+        entry.add( "ou", "Sales" );
+        entry.add( "cn", "JOhnny \u65E5\u672C WAlkeR" );
+        entry.add( "sn", "WAlkeR" );
+        entry.add( "postalCode", "3" );
+        entry.add( "postOfficeBox", "3" );
+        entry.add( "jpegPhoto", new byte[]
+            { 0x00, 0x01, 0x7F, ( byte ) 0x80, ( byte ) 0x81, ( byte ) 0xFF, } );
+        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
+        entry.add( "entryUUID", UUID.randomUUID().toString() );
+        return entry;
+    }
+
+}

Added: 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=903024&view=auto
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java (added)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseIndexTableTest.java Tue Jan 26 00:12:54 2010
@@ -0,0 +1,382 @@
+/*
+ * 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.directory.server.core.entry.DefaultServerEntry;
+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 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 HBaseRowIndexTable objectClassIndexTable;
+    private HBaseColumnIndexTable cnIndexTable;
+
+
+    /**
+     * Cleanup HBase tables before each test.
+     * 
+     */
+    @Before
+    public void setup() throws Exception
+    {
+        HBaseAdmin admin = new HBaseAdmin( adapter.getHBaseConfigurtion() );
+        if ( admin.tableExists( CN_INDEX_TABLE_NAME ) )
+        {
+            HTable cnIndexHTable = new HTable( CN_INDEX_TABLE_NAME );
+            ResultScanner masterScanner = cnIndexHTable.getScanner( new Scan() );
+            Result masterResult;
+            while ( ( masterResult = masterScanner.next() ) != null )
+            {
+                cnIndexHTable.delete( new Delete( masterResult.getRow() ) );
+            }
+        }
+        if ( admin.tableExists( OBJECTCLASS_INDEX_TABLE_NAME ) )
+        {
+            HTable objectClassIndexHTable = new HTable( OBJECTCLASS_INDEX_TABLE_NAME );
+            ResultScanner treeScanner = objectClassIndexHTable.getScanner( new Scan() );
+            Result treeResult;
+            while ( ( treeResult = treeScanner.next() ) != null )
+            {
+                objectClassIndexHTable.delete( new Delete( treeResult.getRow() ) );
+            }
+        }
+
+        cnIndexTable = new HBaseColumnIndexTable( "2.5.4.3", schemaManager, TABLE_PREFIX );
+        objectClassIndexTable = new HBaseRowIndexTable( "2.5.4.0", schemaManager, TABLE_PREFIX );
+    }
+
+
+    @Test
+    public void first() throws Exception
+    {
+        DefaultServerEntry entry = buildContextEntry();
+        //cnIndexTable.add( entry.get( "cn" ), 1L );
+        objectClassIndexTable.add( entry.get( "objectClass" ), 1L );
+    }
+
+
+    @Test
+    public void testAdd() throws Exception
+    {
+        // 1st entry
+        DefaultServerEntry entry = buildContextEntry();
+        objectClassIndexTable.add( entry.get( "objectClass" ), 1L );
+
+        HTable objectClassIndexHTable = new HTable( OBJECTCLASS_INDEX_TABLE_NAME );
+
+        Get equalGet = new Get( Bytes.add( Bytes.toBytes( "=organization" ), Bytes.toBytes( Base64.encodeBytes( Bytes
+            .toBytes( 1L ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( equalGet ) );
+        Result equalResult = objectClassIndexHTable.get( equalGet );
+        Get countGet = new Get( Bytes.toBytes( "#organization" ) );
+        assertTrue( objectClassIndexHTable.exists( countGet ) );
+        Result countResult = objectClassIndexHTable.get( countGet );
+
+        NavigableMap<byte[], byte[]> equalInfoMap = equalResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( equalInfoMap );
+        assertEquals( 1, equalInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( equalInfoMap.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
+        entry = buildOuSalesEntry();
+        objectClassIndexTable.add( entry.get( "objectClass" ), 2L );
+
+        // 3rd entry
+        entry = buildCnJohnnyWalkerEntry();
+        objectClassIndexTable.add( entry.get( "objectClass" ), 3L );
+        cnIndexTable.add( entry.get( "cn" ), 3L );
+
+        HTable cnIndexHTable = new HTable( CN_INDEX_TABLE_NAME );
+
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organization" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalunit" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalperson" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=person" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organization" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organizationalunit" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#top" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organizationalperson" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#person" ) ) ) );
+
+        assertTrue( cnIndexHTable.exists( new Get( Bytes.toBytes( "#johnny \u65E5\u672C walker" ) ) ) );
+
+        Result topCountResult = objectClassIndexHTable.get( new Get( Bytes.toBytes( "#top" ) ) );
+        NavigableMap<byte[], byte[]> topCountInfoMap = topCountResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( topCountInfoMap );
+        assertEquals( 1, topCountInfoMap.size() );
+        assertEquals( 2L, Bytes.toLong( topCountInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        Result cnCountResult = cnIndexHTable.get( new Get( Bytes.toBytes( "#johnny \u65E5\u672C walker" ) ) );
+        NavigableMap<byte[], byte[]> cnCountInfoMap = cnCountResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( cnCountInfoMap );
+        assertEquals( 2, cnCountInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( cnCountInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+        assertEquals( 3L, Bytes.toLong( cnCountInfoMap.get( Bytes.toBytes( 3L ) ) ) );
+    }
+
+
+    @Test
+    public void testDelete() throws Exception
+    {
+        // 1st entry
+        DefaultServerEntry contextEntry = buildContextEntry();
+        objectClassIndexTable.add( contextEntry.get( "objectClass" ), 1L );
+
+        // 2nd entry
+        DefaultServerEntry ouSalesEntry = buildOuSalesEntry();
+        objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ), 2L );
+
+        // 3rd entry
+        DefaultServerEntry cnEntry = buildCnJohnnyWalkerEntry();
+        objectClassIndexTable.add( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.add( cnEntry.get( "cn" ), 3L );
+
+        HTable objectClassIndexHTable = new HTable( OBJECTCLASS_INDEX_TABLE_NAME );
+        HTable cnIndexHTable = new HTable( CN_INDEX_TABLE_NAME );
+
+        // detete 3rd entry
+        objectClassIndexTable.delete( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.delete( cnEntry.get( "cn" ), 3L );
+
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organization" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalunit" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalperson" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=person" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organization" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organizationalunit" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#top" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#organizationalperson" ) ) ) );
+        assertTrue( objectClassIndexHTable.exists( new Get( Bytes.toBytes( "#person" ) ) ) );
+
+        assertTrue( cnIndexHTable.exists( new Get( Bytes.toBytes( "#johnny \u65E5\u672C walker" ) ) ) );
+
+        Result topCountResult = objectClassIndexHTable.get( new Get( Bytes.toBytes( "#top" ) ) );
+        NavigableMap<byte[], byte[]> topCountInfoMap = topCountResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( topCountInfoMap );
+        assertEquals( 1, topCountInfoMap.size() );
+        assertEquals( 1L, Bytes.toLong( topCountInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        Result cnCountResult = cnIndexHTable.get( new Get( Bytes.toBytes( "#johnny \u65E5\u672C walker" ) ) );
+        NavigableMap<byte[], byte[]> cnCountInfoMap = cnCountResult.getFamilyMap( Bytes.toBytes( "info" ) );
+        assertNotNull( cnCountInfoMap );
+        assertEquals( 1, cnCountInfoMap.size() );
+        assertEquals( 0L, Bytes.toLong( cnCountInfoMap.get( Bytes.toBytes( "count" ) ) ) );
+
+        // detete 2nd and 1st entry
+        objectClassIndexTable.delete( ouSalesEntry.get( "objectClass" ), 2L );
+        objectClassIndexTable.delete( contextEntry.get( "objectClass" ), 1L );
+
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organization" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 1L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalunit" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 2L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=organizationalperson" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=person" ), Bytes
+            .toBytes( Base64.encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+        assertFalse( objectClassIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "=top" ), Bytes.toBytes( Base64
+            .encodeBytes( Bytes.toBytes( 3L ) ) ) ) ) ) );
+    }
+
+
+    @Test
+    public void testCount() throws Exception
+    {
+        assertEquals( 0, objectClassIndexTable.count( "organization" ) );
+        assertEquals( 0, objectClassIndexTable.count( "organizationalunit" ) );
+        assertEquals( 0, objectClassIndexTable.count( "top" ) );
+        assertEquals( 0, objectClassIndexTable.count( "person" ) );
+        assertEquals( 0, cnIndexTable.count( "johnny \u65E5\u672C walker" ) );
+
+        // 1st entry
+        DefaultServerEntry contextEntry = buildContextEntry();
+        objectClassIndexTable.add( contextEntry.get( "objectClass" ), 1L );
+
+        assertEquals( 1, objectClassIndexTable.count( "organization" ) );
+
+        // 2nd entry
+        DefaultServerEntry ouSalesEntry = buildOuSalesEntry();
+        objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ), 2L );
+
+        assertEquals( 1, objectClassIndexTable.count( "top" ) );
+        assertEquals( 1, objectClassIndexTable.count( "organizationalunit" ) );
+
+        // 3rd entry
+        DefaultServerEntry cnEntry = buildCnJohnnyWalkerEntry();
+        objectClassIndexTable.add( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.add( cnEntry.get( "cn" ), 3L );
+
+        assertEquals( 2, objectClassIndexTable.count( "top" ) );
+        assertEquals( 1, objectClassIndexTable.count( "person" ) );
+        assertEquals( 1, cnIndexTable.count( "johnny \u65E5\u672C walker" ) );
+
+        // delete 3rd and 2nd
+        objectClassIndexTable.delete( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.delete( cnEntry.get( "cn" ), 3L );
+        objectClassIndexTable.delete( ouSalesEntry.get( "objectClass" ), 2L );
+
+        assertEquals( 0, objectClassIndexTable.count( "organizationalunit" ) );
+        assertEquals( 0, objectClassIndexTable.count( "top" ) );
+        assertEquals( 0, objectClassIndexTable.count( "person" ) );
+        assertEquals( 0, cnIndexTable.count( "johnny \u65E5\u672C walker" ) );
+        assertEquals( 1, objectClassIndexTable.count( "organization" ) );
+
+        // delete 1st
+        objectClassIndexTable.delete( contextEntry.get( "objectClass" ), 1L );
+
+        assertEquals( 0, objectClassIndexTable.count( "organization" ) );
+
+        // test non-existing values
+        assertEquals( 0, objectClassIndexTable.count( null ) );
+        assertEquals( 0, cnIndexTable.count( null ) );
+        assertEquals( 0, objectClassIndexTable.count( "" ) );
+        assertEquals( 0, cnIndexTable.count( "" ) );
+        assertEquals( 0, objectClassIndexTable.count( "abc" ) );
+        assertEquals( 0, cnIndexTable.count( "abc" ) );
+        assertEquals( 0, objectClassIndexTable.count( "\u65E5\u672C" ) );
+        assertEquals( 0, cnIndexTable.count( "\u65E5\u672C" ) );
+        assertEquals( 0, objectClassIndexTable.count( new byte[]
+            { 0x00, 0x01, 0x02 } ) );
+        assertEquals( 0, cnIndexTable.count( new byte[]
+            { 0x00, 0x01, 0x02 } ) );
+    }
+
+
+    @Test
+    public void testExists() throws Exception
+    {
+        assertFalse( objectClassIndexTable.exists( "organization", 1L ) );
+        assertFalse( objectClassIndexTable.exists( "organizationalunit", 2L ) );
+        assertFalse( objectClassIndexTable.exists( "top", 2L ) );
+        assertFalse( objectClassIndexTable.exists( "top", 3L ) );
+        assertFalse( objectClassIndexTable.exists( "person", 3L ) );
+        assertFalse( cnIndexTable.exists( "johnny \u65E5\u672C walker", 3L ) );
+
+        // 1st entry
+        DefaultServerEntry contextEntry = buildContextEntry();
+        objectClassIndexTable.add( contextEntry.get( "objectClass" ), 1L );
+
+        assertTrue( objectClassIndexTable.exists( "organization", 1L ) );
+
+        // 2nd entry
+        DefaultServerEntry ouSalesEntry = buildOuSalesEntry();
+        objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ), 2L );
+
+        assertTrue( objectClassIndexTable.exists( "organizationalunit", 2L ) );
+        assertTrue( objectClassIndexTable.exists( "top", 2L ) );
+
+        // 3rd entry
+        DefaultServerEntry cnEntry = buildCnJohnnyWalkerEntry();
+        objectClassIndexTable.add( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.add( cnEntry.get( "cn" ), 3L );
+
+        assertTrue( objectClassIndexTable.exists( "top", 3L ) );
+        assertTrue( objectClassIndexTable.exists( "person", 3L ) );
+        assertTrue( cnIndexTable.exists( "johnny \u65E5\u672C walker", 3L ) );
+
+        // delete 3rd and 2nd
+        objectClassIndexTable.delete( cnEntry.get( "objectClass" ), 3L );
+        cnIndexTable.delete( cnEntry.get( "cn" ), 3L );
+        objectClassIndexTable.delete( ouSalesEntry.get( "objectClass" ), 2L );
+
+        assertTrue( objectClassIndexTable.exists( "organization", 1L ) );
+        assertFalse( objectClassIndexTable.exists( "organizationalunit", 2L ) );
+        assertFalse( objectClassIndexTable.exists( "top", 2L ) );
+        assertFalse( objectClassIndexTable.exists( "top", 3L ) );
+        assertFalse( objectClassIndexTable.exists( "person", 3L ) );
+        assertFalse( cnIndexTable.exists( "johnny \u65E5\u672C walker", 3L ) );
+
+        // delete 1st
+        objectClassIndexTable.delete( contextEntry.get( "objectClass" ), 1L );
+
+        assertFalse( objectClassIndexTable.exists( "organization", 1L ) );
+
+        // test non-existing values
+        assertFalse( objectClassIndexTable.exists( null, null ) );
+        assertFalse( cnIndexTable.exists( null, null ) );
+        assertFalse( objectClassIndexTable.exists( "", -1L ) );
+        assertFalse( cnIndexTable.exists( "", -1L ) );
+        assertFalse( objectClassIndexTable.exists( "abc", 0L ) );
+        assertFalse( cnIndexTable.exists( "abc", 0L ) );
+        assertFalse( objectClassIndexTable.exists( "\u65E5\u672C", Long.MAX_VALUE ) );
+        assertFalse( cnIndexTable.exists( "\u65E5\u672C", Long.MAX_VALUE ) );
+        assertFalse( objectClassIndexTable.exists( new byte[]
+            { 0x00, 0x01, 0x02 }, 10L ) );
+        assertFalse( cnIndexTable.exists( new byte[]
+            { 0x00, 0x01, 0x02 }, 10L ) );
+    }
+
+
+    @Test
+    public void last() throws Exception
+    {
+    }
+
+}

Modified: directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java?rev=903024&r1=903023&r2=903024&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java Tue Jan 26 00:12:54 2010
@@ -24,26 +24,11 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.NavigableMap;
-import java.util.UUID;
-
-import javax.naming.InvalidNameException;
-import javax.naming.NamingException;
 
 import org.apache.directory.server.core.entry.DefaultServerEntry;
-import org.apache.directory.server.core.partition.hbase.HBaseClusterTestCaseAdapter;
-import org.apache.directory.server.core.partition.hbase.it.AbstractHBasePartitionIT;
-import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -52,9 +37,7 @@
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 
@@ -64,71 +47,15 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class HBaseMasterTableTest
+public class HBaseMasterTableTest extends AbstractHBaseTableTest
 {
-    protected static HBaseClusterTestCaseAdapter adapter;
-
-
-    /**
-     * Startup mini HBase cluster.
-     */
-    @BeforeClass
-    public static void before() throws Exception
-    {
-        adapter = new HBaseClusterTestCaseAdapter( AbstractHBasePartitionIT.class );
-        adapter.setUp();
-    }
-
-
-    /**
-     * Shutdown mini HBase cluster.
-     */
-    @AfterClass
-    public static void after() throws Exception
-    {
-        adapter.tearDown();
-    }
 
-    private static final String TABLE_PREFIX = "apacheds_test_";
     private static final String MASTER_TABLE_NAME = TABLE_PREFIX + "master";
     private static final String TREE_TABLE_NAME = TABLE_PREFIX + "tree";
-    private static final CsnFactory CSN_FACTORY = new CsnFactory( 0 );
-    private static SchemaManager schemaManager;
-    private LdapDN suffixDn;
     private HBaseMasterTable masterTable;
 
 
     /**
-     * Init schema manager
-     */
-    @BeforeClass
-    public static void init() throws Exception
-    {
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = HBaseMasterTableTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
-        }
-    }
-
-
-    /**
      * Cleanup HBase tables before each test.
      * 
      */
@@ -145,7 +72,9 @@
             {
                 masterHTable.delete( new Delete( masterResult.getRow() ) );
             }
-
+        }
+        if ( admin.tableExists( TREE_TABLE_NAME ) )
+        {
             HTable treeHTable = new HTable( TREE_TABLE_NAME );
             ResultScanner treeScanner = treeHTable.getScanner( new Scan() );
             Result treeResult;
@@ -155,8 +84,6 @@
             }
         }
 
-        suffixDn = new LdapDN( "o=Good Times Co." );
-        suffixDn.normalize( schemaManager.getNormalizerMapping() );
         masterTable = new HBaseMasterTable( schemaManager, suffixDn, TABLE_PREFIX );
     }
 
@@ -246,7 +173,8 @@
         // check in HBase tables
         masterGet = new Get( Bytes.toBytes( 2L ) );
         assertTrue( masterHTable.exists( masterGet ) );
-        treeGet = new Get( Bytes.add( Bytes.toBytes( 1L ), Bytes.toBytes( "," ), Bytes.toBytes( "2.5.4.11=sales" ) ) );
+        treeGet = new Get( Bytes.add( Bytes.toBytes( 1L ), Bytes.toBytes( "," ), Bytes
+            .toBytes( "2.5.4.11=sales \u65E5\u672C" ) ) );
         assertTrue( treeHTable.exists( treeGet ) );
     }
 
@@ -269,7 +197,8 @@
         masterTable.delete( 2L, entry );
         Get masterGet = new Get( Bytes.toBytes( 2L ) );
         assertFalse( masterHTable.exists( masterGet ) );
-        Get treeGet = new Get( Bytes.add( Bytes.toBytes( 1L ), Bytes.toBytes( "," ), Bytes.toBytes( "2.5.4.11=sales" ) ) );
+        Get treeGet = new Get( Bytes.add( Bytes.toBytes( 1L ), Bytes.toBytes( "," ), Bytes
+            .toBytes( "2.5.4.11=sales \u65E5\u672C" ) ) );
         assertFalse( treeHTable.exists( treeGet ) );
         assertTrue( masterHTable.exists( new Get( Bytes.toBytes( 1L ) ) ) );
 
@@ -461,7 +390,10 @@
         // fetch second entry
         long count3 = HBaseTableHelper.RPC_COUNT;
         assertNotNull( masterTable.fetchEntry( 2L ) );
-        assertEquals( "ou=Sales,o=Good Times Co.", masterTable.fetchEntry( 2L ).getDn().getName() );
+        assertEquals( "ou=Sales \\E6\\97\\A5\\E6\\9C\\AC,o=Good Times Co.", masterTable.fetchEntry( 2L ).getDn()
+            .getName() );
+        assertEquals( "2.5.4.11=sales \u65E5\u672C,2.5.4.10=good times co.", masterTable.fetchEntry( 2L ).getDn()
+            .getNormName() );
         assertEquals( ouSalesEntry, masterTable.fetchEntry( 2L ) );
         long count4 = HBaseTableHelper.RPC_COUNT;
         assertEquals( 1, count4 - count3 );
@@ -554,51 +486,6 @@
     }
 
 
-    private DefaultServerEntry buildContextEntry() throws NamingException
-    {
-        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, suffixDn );
-        entry.add( "objectClass", "organization" );
-        entry.add( "o", "Good Times Co." );
-        entry.add( "postalCode", "1" );
-        entry.add( "postOfficeBox", "1" );
-        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
-        entry.add( "entryUUID", UUID.randomUUID().toString() );
-        return entry;
-    }
-
-
-    private DefaultServerEntry buildOuSalesEntry() throws InvalidNameException, NamingException
-    {
-        LdapDN dn = new LdapDN( "ou=Sales,o=Good Times Co." );
-        dn.normalize( schemaManager.getNormalizerMapping() );
-        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "organizationalUnit" );
-        entry.add( "ou", "Sales" );
-        entry.add( "postalCode", "1" );
-        entry.add( "postOfficeBox", "1" );
-        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
-        entry.add( "entryUUID", UUID.randomUUID().toString() );
-        return entry;
-    }
-
-
-    private DefaultServerEntry buildCnJohnnyWalkerEntry() throws InvalidNameException, NamingException
-    {
-        LdapDN dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
-        dn.normalize( schemaManager.getNormalizerMapping() );
-        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "person", "organizationalPerson" );
-        entry.add( "ou", "Sales" );
-        entry.add( "cn", "JOhnny WAlkeR" );
-        entry.add( "sn", "WAlkeR" );
-        entry.add( "postalCode", "3" );
-        entry.add( "postOfficeBox", "3" );
-        entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
-        entry.add( "entryUUID", UUID.randomUUID().toString() );
-        return entry;
-    }
-
-
     @Test
     public void last() throws Exception
     {