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/11/06 18:38:42 UTC
svn commit: r1032121 - in /directory/sandbox/seelmann/hbase-partition: ./
src/main/java/org/apache/directory/server/core/partition/hbase/
src/test/java/org/apache/directory/server/core/partition/hbase/table/
src/test/resources/
Author: seelmann
Date: Sat Nov 6 17:38:41 2010
New Revision: 1032121
URL: http://svn.apache.org/viewvc?rev=1032121&view=rev
Log:
Fixed table prefix. Moved tests.
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
directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java
directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBasePresenceIndexTableTest.java
Modified:
directory/sandbox/seelmann/hbase-partition/pom.xml
directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/HBaseDistributedPartition.java
directory/sandbox/seelmann/hbase-partition/src/test/resources/log4j.properties
Modified: directory/sandbox/seelmann/hbase-partition/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/pom.xml?rev=1032121&r1=1032120&r2=1032121&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/pom.xml (original)
+++ directory/sandbox/seelmann/hbase-partition/pom.xml Sat Nov 6 17:38:41 2010
@@ -30,7 +30,7 @@
<packaging>jar</packaging>
<description>
- A partition (based on XDBM) that stores entries and indices in an Apache Hadoop HBase database.
+ A partition (based on XDBM) that stores entries and indices in an Apache HBase database.
</description>
<dependencies>
@@ -77,7 +77,12 @@
<version>0.89.0-SNAPSHOT</version>
<classifier>tests</classifier>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-test</artifactId>
+ <version>0.20.3-append-r964955-1240</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -97,16 +102,9 @@
</classpathContainers>
</configuration>
</plugin>
- <!--
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <include>**/*IT.java</include>
- </includes>
- </configuration>
</plugin>
- -->
<!-- Delete build and test directories that were crated by hbase tests -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
@@ -122,110 +120,9 @@
</configuration>
</plugin>
- <!-- Install hadoop hbase artifacts, they are not available in maven repo -->
- <!--
- <plugin>
- <artifactId>maven-install-plugin</artifactId>
- <version>2.3</version>
- <executions>
- <execution>
- <id>install-hadoop-core</id>
- <phase>validate</phase>
- <goals>
- <goal>install-file</goal>
- </goals>
- <configuration>
- <file>lib/hadoop-0.20.1-hdfs127-core.jar</file>
- <localRepositoryPath>repo</localRepositoryPath>
- <groupId>org.apache.directory.hbase</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>0.20.1-hdfs127</version>
- <packaging>jar</packaging>
- </configuration>
- </execution>
- <execution>
- <id>install-hadoop-test</id>
- <phase>validate</phase>
- <goals>
- <goal>install-file</goal>
- </goals>
- <configuration>
- <file>lib/hadoop-0.20.1-test.jar</file>
- <localRepositoryPath>repo</localRepositoryPath>
- <groupId>org.apache.directory.hbase</groupId>
- <artifactId>hadoop-test</artifactId>
- <version>0.20.1</version>
- <packaging>jar</packaging>
- </configuration>
- </execution>
- <execution>
- <id>install-hbase</id>
- <phase>validate</phase>
- <goals>
- <goal>install-file</goal>
- </goals>
- <configuration>
- <file>lib/hbase-0.20.3-RC3.jar</file>
- <localRepositoryPath>repo</localRepositoryPath>
- <groupId>org.apache.directory.hbase</groupId>
- <artifactId>hbase</artifactId>
- <version>0.20.3-RC3</version>
- <packaging>jar</packaging>
- </configuration>
- </execution>
- <execution>
- <id>install-hbase-test</id>
- <phase>validate</phase>
- <goals>
- <goal>install-file</goal>
- </goals>
- <configuration>
- <file>lib/hbase-0.20.3-RC3-test.jar</file>
- <localRepositoryPath>repo</localRepositoryPath>
- <groupId>org.apache.directory.hbase</groupId>
- <artifactId>hbase-test</artifactId>
- <version>0.20.3-RC3</version>
- <packaging>jar</packaging>
- </configuration>
- </execution>
- <execution>
- <id>install-zookeeper</id>
- <phase>validate</phase>
- <goals>
- <goal>install-file</goal>
- </goals>
- <configuration>
- <file>lib/zookeeper-3.2.2.jar</file>
- <localRepositoryPath>repo</localRepositoryPath>
- <groupId>org.apache.directory.hbase</groupId>
- <artifactId>zookeeper</artifactId>
- <version>3.2.2</version>
- <packaging>jar</packaging>
- </configuration>
- </execution>
- </executions>
- </plugin>
- -->
</plugins>
</build>
- <repositories>
- <!--
- Unfortunately HBase artifacts are not yet available in public maven repo.
- So I created a private repo under p.a.o/~seelmann and use groupId
- "org.apache.directory.hbase" to avoid conflicts.
- -->
- <!--
- <repository>
- <id>hbase-partition-private-repository</id>
- <url>http://people.apache.org/~seelmann/hbase-partition/repository</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- -->
- </repositories>
-
</project>
Modified: directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/HBaseDistributedPartition.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/HBaseDistributedPartition.java?rev=1032121&r1=1032120&r2=1032121&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/HBaseDistributedPartition.java (original)
+++ directory/sandbox/seelmann/hbase-partition/src/main/java/org/apache/directory/server/core/partition/hbase/HBaseDistributedPartition.java Sat Nov 6 17:38:41 2010
@@ -76,7 +76,7 @@ public class HBaseDistributedPartition e
store.setSuffixDn( suffix );
store.setCacheSize( cacheSize );
store.setId( id );
- String directoryServiceInstanceName = getPartitionDir().getParentFile().getName();
+ String directoryServiceInstanceName = getPartitionDir().getParentFile().getParentFile().getName();
( ( HBaseStore ) store ).setTablePrefix( "apacheds" + "_" + directoryServiceInstanceName + "_" + id + "_" );
for ( Index<?, Entry, UUID> index : getIndexedAttributes() )
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=1032121&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 Sat Nov 6 17:38:41 2010
@@ -0,0 +1,152 @@
+/*
+ * 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 org.apache.directory.server.core.partition.hbase.HBaseStore;
+import org.apache.directory.shared.ldap.csn.CsnFactory;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
+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.LdapExceptionUtils;
+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 SchemaManager schemaManager;
+ protected static DN suffixDn;
+ protected static String workingDirectory;
+
+ protected static final UUID CONTEXT_ENTRY_ID = UUID.fromString( "00000000-0000-0000-0000-000000000001" );
+ protected static final UUID OU_SALES_ID = UUID.fromString( "00000000-0000-0000-0000-000000000002" );
+ protected static final UUID CN_JOHNNY_WALKER_UUID = UUID.fromString( "00000000-0000-0000-0000-000000000003" );
+
+
+ /**
+ * Init schema manager and suffix
+ */
+ @BeforeClass
+ public static void initSchemaManager() throws Exception
+ {
+ 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 : " + LdapExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+
+ suffixDn = new DN( "o=Good Times Co." );
+ suffixDn.normalize( schemaManager.getNormalizerMapping() );
+ }
+
+
+ protected Entry buildContextEntry() throws LdapException
+ {
+ Entry entry = new DefaultEntry( 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", CONTEXT_ENTRY_ID.toString() );
+ return entry;
+ }
+
+
+ protected Entry buildOuSalesEntry() throws LdapException
+ {
+ DN dn = new DN( "ou=Sales \\E6\\97\\A5\\E6\\9C\\AC,o=Good Times Co." );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ Entry entry = new DefaultEntry( 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", OU_SALES_ID.toString() );
+ return entry;
+ }
+
+
+ protected Entry buildCnJohnnyWalkerEntry() throws LdapException
+ {
+ DN dn = new DN(
+ "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() );
+ Entry entry = new DefaultEntry( 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[]
+ {
+ (byte)0xFF,
+ (byte)0xD8,
+ (byte)0xFF,
+ (byte)0xE0,
+ 0x00,
+ 0x10,
+ 'J',
+ 'F',
+ 'I',
+ 'F',
+ 0x00
+ } );
+ entry.add( "entryCsn", CSN_FACTORY.newInstance().toString() );
+ entry.add( "entryUUID", CN_JOHNNY_WALKER_UUID.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=1032121&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 Sat Nov 6 17:38:41 2010
@@ -0,0 +1,537 @@
+/*
+ * 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.io.File;
+import java.util.List;
+import java.util.NavigableMap;
+import java.util.UUID;
+
+import org.apache.directory.server.core.partition.hbase.HBaseStore;
+import org.apache.directory.server.core.partition.hbase.Utils;
+import org.apache.directory.server.core.partition.hbase.index.HBaseUserColumnIndex;
+import org.apache.directory.server.core.partition.hbase.index.HBaseUserRowIndex;
+import org.apache.directory.shared.ldap.entry.Entry;
+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.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 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;
+ private HBaseStore store;
+
+
+ /**
+ * Cleanup HBase tables before each test.
+ *
+ */
+ @Before
+ public void setup() throws Exception
+ {
+ store = new HBaseStore();
+ store.setPartitionDir( new File( workingDirectory, "store" ) );
+ store.setSuffixDn( suffixDn );
+ store.setCacheSize( 100 );
+ store.setTablePrefix( TABLE_PREFIX );
+
+ HBaseUserRowIndex index1 = new HBaseUserRowIndex();
+ index1.setAttributeId( "2.5.4.0" );
+ index1.setCacheSize( 100 );
+ index1.setStore( store );
+ store.addIndex( index1 );
+
+ HBaseUserRowIndex index2 = new HBaseUserRowIndex();
+ index2.setAttributeId( "0.9.2342.19200300.100.1.60" );
+ index2.setStore( store );
+ store.addIndex( index2 );
+
+ HBaseUserColumnIndex index3 = new HBaseUserColumnIndex();
+ index3.setAttributeId( "2.5.4.3" );
+ index3.setStore( store );
+ store.addIndex( index3 );
+
+ HBaseUserColumnIndex index4 = new HBaseUserColumnIndex();
+ index4.setAttributeId( "2.5.4.36" );
+ index4.setStore( store );
+ store.addIndex( index4 );
+
+ store.init( schemaManager );
+
+ HBaseAdmin admin = new HBaseAdmin( store.getConfiguration() );
+ if ( admin.tableExists( CN_INDEX_TABLE_NAME ) )
+ {
+ HTable cnIndexHTable = new HTable( store.getConfiguration(), 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( store.getConfiguration(), OBJECTCLASS_INDEX_TABLE_NAME );
+ ResultScanner treeScanner = objectClassIndexHTable.getScanner( new Scan() );
+ Result treeResult;
+ while ( ( treeResult = treeScanner.next() ) != null )
+ {
+ objectClassIndexHTable.delete( new Delete( treeResult.getRow() ) );
+ }
+ }
+
+ objectClassIndexTable = index1.getIndexTable();
+ jpegPhotoIndexTable = index2.getIndexTable();
+ cnIndexTable = index3.getIndexTable();
+ userCertificateIndexTable = index4.getIndexTable();
+ }
+
+
+ @Test
+ public void testAdd() throws Exception
+ {
+ // 1st entry
+ Entry entry = buildContextEntry();
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ HTable objectClassIndexHTable = new HTable( store.getConfiguration(), OBJECTCLASS_INDEX_TABLE_NAME );
+
+ Get equalGet = new Get( Bytes.toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) );
+ assertTrue( objectClassIndexHTable.exists( equalGet ) );
+ Result equalResult = objectClassIndexHTable.get( equalGet );
+
+ NavigableMap<byte[], byte[]> equalInfoMap = equalResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( equalInfoMap );
+ assertEquals( 1, equalInfoMap.size() );
+ assertEquals( "e", Bytes.toString( equalInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+
+ // 2nd entry
+ entry = buildOuSalesEntry();
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ // 3rd entry
+ entry = buildCnJohnnyWalkerEntry();
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.add( entry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ HTable cnIndexHTable = new HTable( store.getConfiguration(), CN_INDEX_TABLE_NAME );
+
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalunit\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=person\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalperson\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+
+ assertTrue( cnIndexHTable.exists( new Get( Bytes.toBytes( "=johnny \u65E5\u672C walker" ) ) ) );
+
+ 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() );
+ }
+
+
+ @Test
+ public void testDelete() throws Exception
+ {
+ // 1st entry
+ Entry contextEntry = buildContextEntry();
+ objectClassIndexTable.add( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ // 2nd entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ // 3rd entry
+ Entry cnEntry = buildCnJohnnyWalkerEntry();
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.add( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ HTable objectClassIndexHTable = new HTable( store.getConfiguration(), OBJECTCLASS_INDEX_TABLE_NAME );
+ HTable cnIndexHTable = new HTable( store.getConfiguration(), CN_INDEX_TABLE_NAME );
+
+ // detete 3rd entry
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.drop( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalunit\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=person\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalperson\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+
+ assertTrue( cnIndexHTable.exists( new Get( Bytes.toBytes( "=johnny \u65E5\u672C walker" ) ) ) );
+
+ // detete 2nd and 1st entry
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.drop( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalunit\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000002" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=person\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=organizationalperson\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ assertTrue( objectClassIndexHTable.exists( new Get( Bytes
+ .toBytes( "=top\u000000000000-0000-0000-0000-000000000003" ) ) ) );
+ }
+
+
+ @Test
+ public void testAddDelete() throws Exception
+ {
+ for ( int i = 0; i < 100; i++ )
+ {
+ // add + verify
+ Entry entry = buildContextEntry();
+ objectClassIndexTable.add( entry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+ HTable objectClassIndexHTable = new HTable( store.getConfiguration(), OBJECTCLASS_INDEX_TABLE_NAME );
+
+ Get existsGet = new Get( Bytes.toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) );
+ assertTrue( objectClassIndexHTable.exists( existsGet ) );
+ Result existsResult = objectClassIndexHTable.get( existsGet );
+ NavigableMap<byte[], byte[]> existsInfoMap = existsResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( existsInfoMap );
+ assertEquals( 1, existsInfoMap.size() );
+ assertEquals( "e", Bytes.toString( existsInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+
+ // delete + verify
+ objectClassIndexTable.drop( entry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ Get deletedGet = new Get( Bytes.toBytes( "=organization\u000000000000-0000-0000-0000-000000000001" ) );
+ assertTrue( objectClassIndexHTable.exists( deletedGet ) );
+ Result deletedResult = objectClassIndexHTable.get( deletedGet );
+ NavigableMap<byte[], byte[]> deletedInfoMap = deletedResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( deletedInfoMap );
+ assertEquals( 1, deletedInfoMap.size() );
+ assertEquals( "d", Bytes.toString( deletedInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+ }
+ for ( int i = 0; i < 100; i++ )
+ {
+ // add + verify
+ Entry entry = buildCnJohnnyWalkerEntry();
+ cnIndexTable.add( entry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ HTable cnIndexHTable = new HTable( store.getConfiguration(), CN_INDEX_TABLE_NAME );
+
+ Get existsGet = new Get( Bytes.toBytes( "=johnny \u65E5\u672C walker" ) );
+ assertTrue( cnIndexHTable.exists( existsGet ) );
+ Result existsResult = cnIndexHTable.get( existsGet );
+ NavigableMap<byte[], byte[]> existsInfoMap = existsResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( existsInfoMap );
+ assertEquals( 1, existsInfoMap.size() );
+ assertEquals( "e", Bytes.toString( existsInfoMap.get( Utils.toBytes( CN_JOHNNY_WALKER_UUID ) ) ) );
+
+ // delete + verify
+ cnIndexTable.drop( entry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ Get deletedGet = new Get( Bytes.toBytes( "=johnny \u65E5\u672C walker" ) );
+ assertTrue( cnIndexHTable.exists( deletedGet ) );
+ Result deletedResult = cnIndexHTable.get( deletedGet );
+ NavigableMap<byte[], byte[]> deletedInfoMap = deletedResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( deletedInfoMap );
+ assertEquals( 1, deletedInfoMap.size() );
+ assertEquals( "d", Bytes.toString( deletedInfoMap.get( Utils.toBytes( CN_JOHNNY_WALKER_UUID ) ) ) );
+ }
+ }
+
+
+ @Test
+ public void testCounts() 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
+ Entry contextEntry = buildContextEntry();
+ objectClassIndexTable.add( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ assertEquals( 1, objectClassIndexTable.count( "organization" ) );
+
+ // 2nd entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ assertEquals( 1, objectClassIndexTable.count( "top" ) );
+ assertEquals( 1, objectClassIndexTable.count( "organizationalunit" ) );
+
+ // 3rd entry
+ Entry cnEntry = buildCnJohnnyWalkerEntry();
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.add( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ assertEquals( 2, objectClassIndexTable.count( "top" ) );
+ assertEquals( 1, objectClassIndexTable.count( "person" ) );
+ assertEquals( 1, cnIndexTable.count( "johnny \u65E5\u672C walker" ) );
+
+ // delete 3rd and 2nd
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.drop( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ 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.drop( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ 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", CONTEXT_ENTRY_ID ) );
+ assertFalse( objectClassIndexTable.exists( "organizationalunit", OU_SALES_ID ) );
+ assertFalse( objectClassIndexTable.exists( "top", OU_SALES_ID ) );
+ assertFalse( objectClassIndexTable.exists( "top", CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( objectClassIndexTable.exists( "person", CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( cnIndexTable.exists( "johnny \u65E5\u672C walker", CN_JOHNNY_WALKER_UUID ) );
+
+ // 1st entry
+ Entry contextEntry = buildContextEntry();
+ objectClassIndexTable.add( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ assertTrue( objectClassIndexTable.exists( "organization", CONTEXT_ENTRY_ID ) );
+
+ // 2nd entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.add( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ assertTrue( objectClassIndexTable.exists( "organizationalunit", OU_SALES_ID ) );
+ assertTrue( objectClassIndexTable.exists( "top", OU_SALES_ID ) );
+
+ // 3rd entry
+ Entry cnEntry = buildCnJohnnyWalkerEntry();
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.add( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.add( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ assertTrue( objectClassIndexTable.exists( "top", CN_JOHNNY_WALKER_UUID ) );
+ assertTrue( objectClassIndexTable.exists( "person", CN_JOHNNY_WALKER_UUID ) );
+ assertTrue( cnIndexTable.exists( "johnny \u65E5\u672C walker", CN_JOHNNY_WALKER_UUID ) );
+
+ // delete 3rd and 2nd
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 1 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( cnEntry.get( "objectClass" ).get( 2 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ cnIndexTable.drop( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 0 ).getBytes(), OU_SALES_ID );
+ objectClassIndexTable.drop( ouSalesEntry.get( "objectClass" ).get( 1 ).getBytes(), OU_SALES_ID );
+
+ assertTrue( objectClassIndexTable.exists( "organization", CONTEXT_ENTRY_ID ) );
+ assertFalse( objectClassIndexTable.exists( "organizationalunit", OU_SALES_ID ) );
+ assertFalse( objectClassIndexTable.exists( "top", OU_SALES_ID ) );
+ assertFalse( objectClassIndexTable.exists( "top", CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( objectClassIndexTable.exists( "person", CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( cnIndexTable.exists( "johnny \u65E5\u672C walker", CN_JOHNNY_WALKER_UUID ) );
+
+ // delete 1st
+ objectClassIndexTable.drop( contextEntry.get( "objectClass" ).get( 0 ).getBytes(), CONTEXT_ENTRY_ID );
+
+ assertFalse( objectClassIndexTable.exists( "organization", CONTEXT_ENTRY_ID ) );
+
+ // test non-existing values
+ assertFalse( objectClassIndexTable.exists( null, null ) );
+ assertFalse( cnIndexTable.exists( null, null ) );
+ assertFalse( objectClassIndexTable.exists( "", UUID.fromString( "ffffffff-ffff-ffff-ffff-ffffffffffff" ) ) );
+ assertFalse( cnIndexTable.exists( "", UUID.fromString( "ffffffff-ffff-ffff-ffff-ffffffffffff" ) ) );
+ assertFalse( objectClassIndexTable.exists( "abc", UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertFalse( cnIndexTable.exists( "abc", UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertFalse( objectClassIndexTable.exists( "\u65E5\u672C", null ) );
+ assertFalse( cnIndexTable.exists( "\u65E5\u672C", null ) );
+ assertFalse( objectClassIndexTable.exists( new byte[]
+ { 0x00, 0x01, 0x02 }, null ) );
+ assertFalse( cnIndexTable.exists( new byte[]
+ { 0x00, 0x01, 0x02 }, null ) );
+ }
+
+
+ @Test
+ public void testGetScanKey() throws Exception
+ {
+ byte[] scanKey = objectClassIndexTable.getScanKey( "bar", HBaseIndexTable.DELIMITER );
+ assertEquals( "=bar\u0000", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( "foo", HBaseIndexTable.DELIMITER );
+ assertEquals( "=foo\u0000", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( "foobar", null );
+ assertEquals( "=foobar", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( "", HBaseIndexTable.DELIMITER );
+ assertEquals( "=\u0000", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( "", null );
+ assertEquals( "=", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( null, null );
+ assertTrue( Bytes.equals( new byte[]
+ { '=' }, scanKey ) );
+
+ scanKey = objectClassIndexTable.getScanKey( null, null );
+ scanKey = Utils.incrementBytes( scanKey );
+ assertTrue( Bytes.equals( new byte[]
+ { '>', }, scanKey ) );
+
+ scanKey = cnIndexTable.getScanKey( "bar" );
+ assertEquals( "=bar", Bytes.toString( scanKey ) );
+
+ scanKey = cnIndexTable.getScanKey( "foo" );
+ assertEquals( "=foo", Bytes.toString( scanKey ) );
+
+ scanKey = cnIndexTable.getScanKey( "" );
+ assertEquals( "=", Bytes.toString( scanKey ) );
+
+ scanKey = cnIndexTable.getScanKey( null );
+ assertTrue( Bytes.equals( new byte[]
+ { '=' }, scanKey ) );
+
+ scanKey = cnIndexTable.getScanKey( null );
+ scanKey = Utils.incrementBytes( scanKey );
+ assertTrue( Bytes.equals( new byte[]
+ { '>' }, scanKey ) );
+ }
+
+
+ @Test
+ public void testGetValue() throws Exception
+ {
+ byte[] bytes = Bytes.toBytes( "=bar\u000012345678-1234-1234-1234-123456789abc" );
+ assertEquals( 41, bytes.length );
+ Object value = objectClassIndexTable.extractValueFromEqualsKey( bytes );
+ assertEquals( "bar", value );
+ UUID uuid = objectClassIndexTable.extractEntryIdFromEqualsKey( bytes );
+ assertEquals( "12345678-1234-1234-1234-123456789abc", uuid.toString() );
+
+ bytes = new byte[]
+ { '=', 0x00, 0x01, 0x00, '0', '0', '0', '0', '0', '0', '0', '0', '-', '0', '0', '0', '0', '-', '0', '0',
+ '0', '0', '-', '0', '0', '0', '0', '-', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
+ assertEquals( 40, bytes.length );
+ value = jpegPhotoIndexTable.extractValueFromEqualsKey( bytes );
+ assertTrue( Bytes.equals( new byte[]
+ { 0x00, 0x01 }, ( byte[] ) value ) );
+ uuid = objectClassIndexTable.extractEntryIdFromEqualsKey( bytes );
+ assertEquals( "00000000-0000-0000-0000-000000000000", uuid.toString() );
+
+ value = cnIndexTable.extractValueFromEqualsKey( Bytes.toBytes( "=foobar" ) );
+ assertEquals( "foobar", value );
+
+ value = userCertificateIndexTable.extractValueFromEqualsKey( new byte[]
+ { '=', 0x00, 0x01 } );
+ assertTrue( Bytes.equals( new byte[]
+ { 0x00, 0x01 }, ( byte[] ) value ) );
+ }
+
+
+ @Test
+ public void testGetColumnCandidates() throws Exception
+ {
+ Entry cnEntry = buildCnJohnnyWalkerEntry();
+ cnIndexTable.add( cnEntry.get( "cn" ).get( 0 ).getBytes(), CN_JOHNNY_WALKER_UUID );
+
+ List<UUID> candidates = cnIndexTable.getColumnCandidates( "johnny \u65E5\u672C walker" );
+ assertNotNull( candidates );
+ assertEquals( 1, candidates.size() );
+ assertTrue( candidates.contains( CN_JOHNNY_WALKER_UUID ) );
+ }
+
+}
Added: 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=1032121&view=auto
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java (added)
+++ directory/sandbox/seelmann/hbase-partition/src/test/java/org/apache/directory/server/core/partition/hbase/table/HBaseMasterTableTest.java Sat Nov 6 17:38:41 2010
@@ -0,0 +1,544 @@
+/*
+ * 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.NavigableMap;
+import java.util.UUID;
+
+import org.apache.directory.server.core.partition.hbase.HBaseStore;
+import org.apache.directory.server.core.partition.hbase.Utils;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
+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.Bytes;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests for {@link HBaseMasterTable}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HBaseMasterTableTest extends AbstractHBaseTableTest
+{
+
+ private static final String MASTER_TABLE_NAME = TABLE_PREFIX + "master";
+ private static final String TREE_TABLE_NAME = TABLE_PREFIX + "tree";
+ private HBaseStore store;
+ private HBaseMasterTable masterTable;
+
+
+ /**
+ * Cleanup HBase tables before each test.
+ *
+ */
+ @Before
+ public void setup() throws Exception
+ {
+ store = new HBaseStore();
+ store.setPartitionDir( new File( workingDirectory, "store" ) );
+ store.setSuffixDn( suffixDn );
+ store.setCacheSize( 100 );
+ store.setTablePrefix( TABLE_PREFIX );
+ store.init( schemaManager );
+ masterTable = store.getMasterTable();
+
+ HBaseAdmin admin = new HBaseAdmin( store.getConfiguration() );
+ if ( admin.tableExists( MASTER_TABLE_NAME ) )
+ {
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ ResultScanner masterScanner = masterHTable.getScanner( new Scan() );
+ Result masterResult;
+ while ( ( masterResult = masterScanner.next() ) != null )
+ {
+ masterHTable.delete( new Delete( masterResult.getRow() ) );
+ }
+ }
+ if ( admin.tableExists( TREE_TABLE_NAME ) )
+ {
+ HTable treeHTable = new HTable( store.getConfiguration(), TREE_TABLE_NAME );
+ ResultScanner treeScanner = treeHTable.getScanner( new Scan() );
+ Result treeResult;
+ while ( ( treeResult = treeScanner.next() ) != null )
+ {
+ treeHTable.delete( new Delete( treeResult.getRow() ) );
+ }
+ }
+ }
+
+
+ @Test
+ public void testEmpty() throws Exception
+ {
+ assertNull( masterTable.fetchId( new DN( "a=b" ) ) );
+ }
+
+
+ @Test
+ public void testAdd() throws Exception
+ {
+ // add context entry
+ Entry entry = buildContextEntry();
+ masterTable.add( entry );
+
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ HTable treeHTable = new HTable( store.getConfiguration(), TREE_TABLE_NAME );
+
+ // check state in HBase table 'master'
+ Get masterGet = new Get( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ Result masterResult = masterHTable.get( masterGet );
+
+ assertEquals( "00000000-0000-0000-0000-000000000001", Bytes.toString( masterResult.getRow() ) );
+
+ NavigableMap<byte[], byte[]> treeInfoMap = masterResult.getFamilyMap( Bytes.toBytes( "treeInfo" ) );
+ assertNotNull( treeInfoMap );
+ assertEquals( 4, treeInfoMap.size() );
+ assertEquals( "e", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+ assertEquals( "o=Good Times Co.", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "upRdn" ) ) ) );
+ assertEquals( "2.5.4.10=good times co.", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "normRdn" ) ) ) );
+ assertEquals( "00000000-0000-0000-0000-000000000000", Bytes.toString( treeInfoMap.get( Bytes
+ .toBytes( "parentId" ) ) ) );
+
+ NavigableMap<byte[], byte[]> upAttributesMap = masterResult.getFamilyMap( Bytes.toBytes( "upAttributes" ) );
+ assertNotNull( upAttributesMap );
+ assertEquals( 6, upAttributesMap.size() );
+ assertEquals( "Good Times Co.", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "o" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( "organization", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "objectClass" ),
+ Bytes.toBytes( 0 ) ) ) ) );
+ assertEquals( "1", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "postalCode" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( "1", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "postOfficeBox" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( entry.get( "entryUUID" ).get().getString(), Bytes.toString( upAttributesMap.get( Bytes.add( Bytes
+ .toBytes( "entryUUID" ), Bytes.toBytes( 0 ) ) ) ) );
+ assertEquals( entry.get( "entryCsn" ).get().getString(), Bytes.toString( upAttributesMap.get( Bytes.add( Bytes
+ .toBytes( "entryCsn" ), Bytes.toBytes( 0 ) ) ) ) );
+
+ // check state in HBase table 'tree'
+ Get treeGet = new Get( Bytes.add( Bytes.toBytes( "00000000-0000-0000-0000-000000000000" ),
+ Bytes.toBytes( "," ), Bytes.toBytes( "2.5.4.10=good times co." ) ) );
+ Result treeResult = treeHTable.get( treeGet );
+
+ //assertEquals( "", Bytes.toLong( treeResult.getRow() ));
+
+ NavigableMap<byte[], byte[]> infoMap = treeResult.getFamilyMap( Bytes.toBytes( "treeInfo" ) );
+ assertNotNull( infoMap );
+ assertEquals( 2, infoMap.size() );
+ assertEquals( "e", Bytes.toString( infoMap.get( Bytes.toBytes( "status" ) ) ) );
+ assertEquals( "00000000-0000-0000-0000-000000000001", Bytes.toString( infoMap.get( Bytes.toBytes( "id" ) ) ) );
+ // no oneLevelCount and subLevelCount column yet
+
+ NavigableMap<byte[], byte[]> normAttributesMap = treeResult.getFamilyMap( Bytes.toBytes( "normAttributes" ) );
+ assertNotNull( normAttributesMap );
+ assertEquals( 6, normAttributesMap.size() );
+
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.0=organization" ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.10=good times co." ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.17=1" ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.18=1" ) ) ) );
+ // ...
+
+ // add second entry
+ entry = buildOuSalesEntry();
+ masterTable.add( entry );
+
+ // check in HBase tables
+ masterGet = new Get( Bytes.toBytes( OU_SALES_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ treeGet = new Get( Bytes.add( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ), Bytes.toBytes( "," ), Bytes
+ .toBytes( "2.5.4.11=sales \u65E5\u672C" ) ) );
+ assertTrue( treeHTable.exists( treeGet ) );
+ }
+
+
+ @Test
+ public void testDelete() throws Exception
+ {
+ // add context entry
+ Entry entry = buildContextEntry();
+ masterTable.add( entry );
+
+ // add second entry
+ entry = buildOuSalesEntry();
+ masterTable.add( entry );
+
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ HTable treeHTable = new HTable( store.getConfiguration(), TREE_TABLE_NAME );
+
+ // delete second entry
+ masterTable.delete( OU_SALES_ID, entry );
+ Get masterGet = new Get( Bytes.toBytes( OU_SALES_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ Get treeGet = new Get( Bytes.add( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ), Bytes.toBytes( "," ), Bytes
+ .toBytes( "2.5.4.11=sales \u65E5\u672C" ) ) );
+ assertTrue( treeHTable.exists( treeGet ) );
+ assertTrue( masterHTable.exists( new Get( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ) ) ) );
+
+ // delete context entry
+ masterTable.delete( CONTEXT_ENTRY_ID, entry );
+ masterGet = new Get( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ treeGet = new Get( Bytes.add( Bytes.toBytes( "00000000-0000-0000-0000-000000000000" ), Bytes.toBytes( "," ),
+ Bytes
+ .toBytes( "2.5.4.10=good times co." ) ) );
+ assertTrue( treeHTable.exists( treeGet ) );
+ }
+
+
+ @Test
+ public void testModify() throws Exception
+ {
+ // add context entry
+ Entry entry = buildContextEntry();
+ masterTable.add( entry );
+
+ // modify some attributes
+ entry.get( "objectClass" ).add( "top" );
+ entry.removeAttributes( "postalCode" );
+ entry.get( "postOfficeBox" ).clear();
+ entry.get( "postOfficeBox" ).add( "2" );
+ masterTable.modify( CONTEXT_ENTRY_ID, entry );
+
+ // check state in HBase table 'master'
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ Get masterGet = new Get( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ Result masterResult = masterHTable.get( masterGet );
+
+ assertEquals( "00000000-0000-0000-0000-000000000001", Bytes.toString( masterResult.getRow() ) );
+
+ NavigableMap<byte[], byte[]> treeInfoMap = masterResult.getFamilyMap( Bytes.toBytes( "treeInfo" ) );
+ assertNotNull( treeInfoMap );
+ assertEquals( 4, treeInfoMap.size() );
+ assertEquals( "e", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+ assertEquals( "o=Good Times Co.", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "upRdn" ) ) ) );
+ assertEquals( "2.5.4.10=good times co.", Bytes.toString( treeInfoMap.get( Bytes.toBytes( "normRdn" ) ) ) );
+ assertEquals( "00000000-0000-0000-0000-000000000000", Bytes.toString( treeInfoMap.get( Bytes
+ .toBytes( "parentId" ) ) ) );
+
+ NavigableMap<byte[], byte[]> upAttributesMap = masterResult.getFamilyMap( Bytes.toBytes( "upAttributes" ) );
+ assertNotNull( upAttributesMap );
+ assertEquals( 7, upAttributesMap.size() );
+ assertEquals( "\u0000", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "postalCode" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( "Good Times Co.", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "o" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( "organization", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "objectClass" ),
+ Bytes.toBytes( 0 ) ) ) ) );
+ assertEquals( "top", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "objectClass" ), Bytes
+ .toBytes( 1 ) ) ) ) );
+ assertEquals( "2", Bytes.toString( upAttributesMap.get( Bytes.add( Bytes.toBytes( "postOfficeBox" ), Bytes
+ .toBytes( 0 ) ) ) ) );
+ assertEquals( entry.get( "entryUUID" ).get().getString(), Bytes.toString( upAttributesMap.get( Bytes.add( Bytes
+ .toBytes( "entryUUID" ), Bytes.toBytes( 0 ) ) ) ) );
+ assertEquals( entry.get( "entryCsn" ).get().getString(), Bytes.toString( upAttributesMap.get( Bytes.add( Bytes
+ .toBytes( "entryCsn" ), Bytes.toBytes( 0 ) ) ) ) );
+ }
+
+
+ @Test
+ public void testRename() throws Exception
+ {
+ // add context entry
+ Entry entry = buildContextEntry();
+ masterTable.add( entry );
+
+ // add second entry
+ entry = buildOuSalesEntry();
+ masterTable.add( entry );
+
+ // rename
+ RDN rdn = new RDN( "ou=SaLeS-US" );
+ rdn.normalize( schemaManager.getNormalizerMapping() );
+ masterTable.move( OU_SALES_ID, null, rdn );
+
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ HTable treeHTable = new HTable( store.getConfiguration(), TREE_TABLE_NAME );
+
+ // check in HBase tables
+ Get masterGet = new Get( Bytes.toBytes( OU_SALES_ID.toString() ) );
+ assertTrue( masterHTable.exists( masterGet ) );
+ Get treeGet = new Get( Bytes.add( Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ), Bytes.toBytes( "," ), Bytes
+ .toBytes( "2.5.4.11=sales-us" ) ) );
+ assertTrue( treeHTable.exists( treeGet ) );
+ }
+
+
+ private void dump() throws Exception
+ {
+ HTable masterHTable = new HTable( store.getConfiguration(), MASTER_TABLE_NAME );
+ ResultScanner masterScanner = masterHTable.getScanner( new Scan() );
+ Result masterResult;
+ while ( ( masterResult = masterScanner.next() ) != null )
+ {
+ System.out.println( "master: " + Utils.getPrintableString( masterResult.getRow() ) );
+ }
+
+ HTable treeHTable = new HTable( store.getConfiguration(), TREE_TABLE_NAME );
+ ResultScanner treeScanner = treeHTable.getScanner( new Scan() );
+ Result treeResult;
+ while ( ( treeResult = treeScanner.next() ) != null )
+ {
+ System.out.println( "tree: " + Utils.getPrintableString( treeResult.getRow() ) );
+ }
+ }
+
+
+ @Test
+ public void testFetch() throws Exception
+ {
+ // add first entry
+ Entry contextEntry = buildContextEntry();
+ masterTable.add( contextEntry );
+
+ // fetch norm attributes
+ long count1 = HBaseTableHelper.RPC_COUNT;
+ NavigableMap<byte[], byte[]> normAttributesMap = masterTable.fetchNormAttributes( CONTEXT_ENTRY_ID );
+ assertNotNull( normAttributesMap );
+ assertEquals( 6, normAttributesMap.size() );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.0=organization" ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.10=good times co." ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.17=1" ) ) ) );
+ assertEquals( 0, Bytes.toInt( normAttributesMap.get( Bytes.toBytes( "2.5.4.18=1" ) ) ) );
+ // ...
+ long count2 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 2, count2 - count1 ); // treeInfo from master table + normAttributes from tree table
+
+ // fetch again, this time we hit the cache
+ long count5 = HBaseTableHelper.RPC_COUNT;
+ normAttributesMap = masterTable.fetchNormAttributes( CONTEXT_ENTRY_ID );
+ long count6 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count6 - count5 ); // normAttributes from tree table
+ }
+
+
+ @Test
+ public void testFetchId() throws Exception
+ {
+ // add first entry
+ Entry contextEntry = buildContextEntry();
+ masterTable.add( contextEntry );
+
+ // fetch ID
+ long count1 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000001", masterTable.fetchId( contextEntry.getDn() ).toString() );
+ long count2 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count2 - count1 );
+
+ // add second entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ masterTable.add( ouSalesEntry );
+
+ // fetch entry ID
+ long count3 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000002", masterTable.fetchId( ouSalesEntry.getDn() ).toString() );
+ long count4 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count4 - count3 );
+
+ // fetch IDs again, this time we hit the cache
+ long count5 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000001", masterTable.fetchId( contextEntry.getDn() ).toString() );
+ assertEquals( "00000000-0000-0000-0000-000000000002", masterTable.fetchId( ouSalesEntry.getDn() ).toString() );
+ long count6 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 0, count6 - count5 );
+
+ // check result after deleting the entry
+ masterTable.delete( OU_SALES_ID, ouSalesEntry );
+ assertNull( masterTable.fetchId( ouSalesEntry.getDn() ) );
+
+ // fetch entry IDs of non-existing entries
+ assertNull( masterTable.fetchId( ( DN ) null ) );
+ assertNull( masterTable.fetchId( new DN( "a=b" ) ) );
+ }
+
+
+ @Test
+ public void testFetchParentId() throws Exception
+ {
+ // add first entry
+ Entry contextEntry = buildContextEntry();
+ masterTable.add( contextEntry );
+
+ // fetch parent ID
+ long count1 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000000", masterTable.fetchParentId( CONTEXT_ENTRY_ID ).toString() );
+ long count2 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count2 - count1 );
+
+ // add second entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ masterTable.add( ouSalesEntry );
+
+ // fetch parent ID
+ long count3 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000001", masterTable.fetchParentId( OU_SALES_ID ).toString() );
+ long count4 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count4 - count3 );
+
+ // fetch parents again, this time we hit the cache
+ long count5 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( "00000000-0000-0000-0000-000000000000", masterTable.fetchParentId( CONTEXT_ENTRY_ID ).toString() );
+ assertEquals( "00000000-0000-0000-0000-000000000001", masterTable.fetchParentId( OU_SALES_ID ).toString() );
+ long count6 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 0, count6 - count5 );
+
+ // check result after deleting the entry
+ masterTable.delete( OU_SALES_ID, ouSalesEntry );
+ assertNull( masterTable.fetchParentId( OU_SALES_ID ) );
+
+ // fetch parent IDs of non-existing entries
+ assertNull( masterTable.fetchParentId( null ) );
+ assertNull( masterTable.fetchParentId( UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertNull( masterTable.fetchParentId( UUID.randomUUID() ) );
+ }
+
+
+ @Test
+ public void testFetchEntry() throws Exception
+ {
+ // add first entry
+ Entry contextEntry = buildContextEntry();
+ masterTable.add( contextEntry );
+
+ // fetch first entry
+ long count1 = HBaseTableHelper.RPC_COUNT;
+ assertNotNull( masterTable.fetchEntry( CONTEXT_ENTRY_ID ) );
+ assertEquals( "o=Good Times Co.", masterTable.fetchEntry( CONTEXT_ENTRY_ID ).getDn().getName() );
+ assertEquals( contextEntry, masterTable.fetchEntry( CONTEXT_ENTRY_ID ) );
+ long count2 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count2 - count1 );
+
+ // add second entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ masterTable.add( ouSalesEntry );
+
+ // fetch second entry
+ long count3 = HBaseTableHelper.RPC_COUNT;
+ assertNotNull( masterTable.fetchEntry( OU_SALES_ID ) );
+ assertEquals( "ou=Sales \\E6\\97\\A5\\E6\\9C\\AC,o=Good Times Co.", masterTable.fetchEntry( OU_SALES_ID )
+ .getDn().getName() );
+ assertEquals( "2.5.4.11=sales \u65E5\u672C,2.5.4.10=good times co.", masterTable.fetchEntry( OU_SALES_ID )
+ .getDn().getNormName() );
+ assertEquals( ouSalesEntry, masterTable.fetchEntry( OU_SALES_ID ) );
+ long count4 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 1, count4 - count3 );
+
+ // fetch entries again, this time we hit the cache
+ long count5 = HBaseTableHelper.RPC_COUNT;
+ assertNotNull( masterTable.fetchEntry( CONTEXT_ENTRY_ID ) );
+ assertNotNull( masterTable.fetchEntry( OU_SALES_ID ) );
+ long count6 = HBaseTableHelper.RPC_COUNT;
+ assertEquals( 0, count6 - count5 );
+
+ // check result after deleting the entry
+ masterTable.delete( OU_SALES_ID, ouSalesEntry );
+ assertNull( masterTable.fetchEntry( OU_SALES_ID ) );
+
+ // fetch non-existing entries
+ assertNull( masterTable.fetchEntry( null ) );
+ assertNull( masterTable.fetchEntry( UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertNull( masterTable.fetchEntry( UUID.randomUUID() ) );
+ }
+
+
+ @Test
+ public void testOneAndSubLevelCount() throws Exception
+ {
+ // add context entry
+ Entry contextEntry = buildContextEntry();
+ masterTable.add( contextEntry );
+
+ // check counters
+ assertEquals( 0, masterTable.getOneLevelCount( CONTEXT_ENTRY_ID ) );
+ assertEquals( 0, masterTable.getSubLevelCount( CONTEXT_ENTRY_ID ) );
+
+ // add ou=Sales entry
+ Entry ouSalesEntry = buildOuSalesEntry();
+ masterTable.add( ouSalesEntry );
+
+ // check counters
+ assertEquals( 0, masterTable.getOneLevelCount( OU_SALES_ID ) );
+ assertEquals( 0, masterTable.getSubLevelCount( OU_SALES_ID ) );
+
+ // check updated counters of context entry
+ assertEquals( 1, masterTable.getOneLevelCount( CONTEXT_ENTRY_ID ) );
+ assertEquals( 1, masterTable.getSubLevelCount( CONTEXT_ENTRY_ID ) );
+
+ // add cn=Jonny Walker entry
+ Entry cnJohnnyWalkerEntry = buildCnJohnnyWalkerEntry();
+ masterTable.add( cnJohnnyWalkerEntry );
+
+ // check counters
+ assertEquals( 0, masterTable.getOneLevelCount( CN_JOHNNY_WALKER_UUID ) );
+ assertEquals( 0, masterTable.getSubLevelCount( CN_JOHNNY_WALKER_UUID ) );
+
+ // check updated counters of ou=Sales entry
+ assertEquals( 1, masterTable.getOneLevelCount( OU_SALES_ID ) );
+ assertEquals( 1, masterTable.getSubLevelCount( OU_SALES_ID ) );
+
+ // check updated counters of context entry
+ assertEquals( 1, masterTable.getOneLevelCount( CONTEXT_ENTRY_ID ) );
+ assertEquals( 2, masterTable.getSubLevelCount( CONTEXT_ENTRY_ID ) );
+
+ // delete cn=Jonny Walker entry
+ masterTable.delete( CN_JOHNNY_WALKER_UUID, cnJohnnyWalkerEntry );
+
+ // check updated counters of ou=Sales entry
+ assertEquals( 0, masterTable.getOneLevelCount( OU_SALES_ID ) );
+ assertEquals( 0, masterTable.getSubLevelCount( OU_SALES_ID ) );
+
+ // check updated counters of context entry
+ assertEquals( 1, masterTable.getOneLevelCount( CONTEXT_ENTRY_ID ) );
+ assertEquals( 1, masterTable.getSubLevelCount( CONTEXT_ENTRY_ID ) );
+
+ // delete ou=Sales entry
+ masterTable.delete( OU_SALES_ID, ouSalesEntry );
+
+ // check updated counters of context entry
+ assertEquals( 0, masterTable.getOneLevelCount( CONTEXT_ENTRY_ID ) );
+ assertEquals( 0, masterTable.getSubLevelCount( CONTEXT_ENTRY_ID ) );
+
+ // test counts for non-existing entries
+ assertEquals( 0, masterTable.getOneLevelCount( null ) );
+ assertEquals( 0, masterTable.getSubLevelCount( null ) );
+ assertEquals( 0, masterTable.getOneLevelCount( UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertEquals( 0, masterTable.getSubLevelCount( UUID.fromString( "00000000-0000-0000-0000-000000000000" ) ) );
+ assertEquals( 0, masterTable.getOneLevelCount( UUID.randomUUID() ) );
+ assertEquals( 0, masterTable.getSubLevelCount( UUID.randomUUID() ) );
+ }
+
+}
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=1032121&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 Sat Nov 6 17:38:41 2010
@@ -0,0 +1,289 @@
+/*
+ * 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.io.File;
+import java.util.NavigableMap;
+import java.util.UUID;
+
+import org.apache.directory.server.core.partition.hbase.HBaseStore;
+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.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;
+ private HBaseStore store;
+
+
+ /**
+ * Cleanup HBase tables before each test.
+ *
+ */
+ @Before
+ public void setup() throws Exception
+ {
+ store = new HBaseStore();
+ store.setPartitionDir( new File( workingDirectory, "store" ) );
+ store.setSuffixDn( suffixDn );
+ store.setCacheSize( 100 );
+ store.setTablePrefix( TABLE_PREFIX );
+ store.init( schemaManager );
+
+ HBaseAdmin admin = new HBaseAdmin( store.getConfiguration() );
+ if ( admin.tableExists( OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME ) )
+ {
+ HTable objectClassIndexHTable = new HTable( store.getConfiguration(), 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( store.getConfiguration(), 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", store, 100 );
+ jpegPhotoPresenceIndexTable = new HBasePresenceIndexTable( "0.9.2342.19200300.100.1.60", store, 100 );
+ }
+
+
+ @Test
+ public void testAdd() throws Exception
+ {
+ // 1st entry
+ objectClassPresenceIndexTable.add( CONTEXT_ENTRY_ID );
+
+ HTable objectClassPresenceIndexHTable = new HTable( store.getConfiguration(),
+ OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME );
+
+ Get presenceGet = new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes.toBytes( CONTEXT_ENTRY_ID.toString() ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( presenceGet ) );
+ Result presenceResult = objectClassPresenceIndexHTable.get( presenceGet );
+
+ NavigableMap<byte[], byte[]> presenceInfoMap = presenceResult.getFamilyMap( Bytes.toBytes( "info" ) );
+ assertNotNull( presenceInfoMap );
+ assertEquals( 1, presenceInfoMap.size() );
+ assertEquals( "e", Bytes.toString( presenceInfoMap.get( Bytes.toBytes( "status" ) ) ) );
+
+ // 2nd entry
+ objectClassPresenceIndexTable.add( OU_SALES_ID );
+
+ // 3rd entry
+ objectClassPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+
+ HTable jpegPhotoPresenceIndexHTable = new HTable( store.getConfiguration(), JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME );
+
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CONTEXT_ENTRY_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( OU_SALES_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+ assertTrue( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+ }
+
+
+ @Test
+ public void testDelete() throws Exception
+ {
+ // 1st entry
+ objectClassPresenceIndexTable.add( CONTEXT_ENTRY_ID );
+ // 2nd entry
+ objectClassPresenceIndexTable.add( OU_SALES_ID );
+ // 3rd entry
+ objectClassPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+
+ HTable objectClassPresenceIndexHTable = new HTable( store.getConfiguration(),
+ OBJECTCLASS_PRESENCE_INDEX_TABLE_NAME );
+ HTable jpegPhotoPresenceIndexHTable = new HTable( store.getConfiguration(), JPEGPHOTO_PRESENCE_INDEX_TABLE_NAME );
+
+ // detete 3rd entry
+ objectClassPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CONTEXT_ENTRY_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( OU_SALES_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+ assertTrue( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+
+ // detete 2nd and 1st entry
+ objectClassPresenceIndexTable.drop( OU_SALES_ID );
+ objectClassPresenceIndexTable.drop( CONTEXT_ENTRY_ID );
+
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CONTEXT_ENTRY_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( OU_SALES_ID.toString() ) ) ) ) );
+ assertTrue( objectClassPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+ assertTrue( jpegPhotoPresenceIndexHTable.exists( new Get( Bytes.add( Bytes.toBytes( "*" ), Bytes
+ .toBytes( CN_JOHNNY_WALKER_UUID.toString() ) ) ) ) );
+ }
+
+
+ @Test
+ public void testCounts() throws Exception
+ {
+ assertEquals( 0, objectClassPresenceIndexTable.count() );
+
+ // 1st entry
+ objectClassPresenceIndexTable.add( CONTEXT_ENTRY_ID );
+
+ assertEquals( 1, objectClassPresenceIndexTable.count() );
+
+ // 2nd entry
+ objectClassPresenceIndexTable.add( OU_SALES_ID );
+
+ assertEquals( 2, objectClassPresenceIndexTable.count() );
+
+ // 3rd entry
+ objectClassPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+
+ assertEquals( 3, objectClassPresenceIndexTable.count() );
+ assertEquals( 1, jpegPhotoPresenceIndexTable.count() );
+
+ // delete 3rd and 2nd
+ objectClassPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+ objectClassPresenceIndexTable.drop( OU_SALES_ID );
+
+ assertEquals( 1, objectClassPresenceIndexTable.count() );
+ assertEquals( 0, jpegPhotoPresenceIndexTable.count() );
+
+ // delete 1st
+ objectClassPresenceIndexTable.drop( CONTEXT_ENTRY_ID );
+
+ assertEquals( 0, objectClassPresenceIndexTable.count() );
+ }
+
+
+ @Test
+ public void testExists() throws Exception
+ {
+ assertFalse( objectClassPresenceIndexTable.exists( CONTEXT_ENTRY_ID ) );
+ assertFalse( objectClassPresenceIndexTable.exists( OU_SALES_ID ) );
+ assertFalse( objectClassPresenceIndexTable.exists( CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( jpegPhotoPresenceIndexTable.exists( CN_JOHNNY_WALKER_UUID ) );
+
+ // 1st entry
+ objectClassPresenceIndexTable.add( CONTEXT_ENTRY_ID );
+
+ assertTrue( objectClassPresenceIndexTable.exists( CONTEXT_ENTRY_ID ) );
+
+ // 2nd entry
+ objectClassPresenceIndexTable.add( OU_SALES_ID );
+
+ assertTrue( objectClassPresenceIndexTable.exists( OU_SALES_ID ) );
+
+ // 3rd entry
+ objectClassPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.add( CN_JOHNNY_WALKER_UUID );
+ assertTrue( objectClassPresenceIndexTable.exists( CN_JOHNNY_WALKER_UUID ) );
+ assertTrue( jpegPhotoPresenceIndexTable.exists( CN_JOHNNY_WALKER_UUID ) );
+
+ // delete 3rd and 2nd
+ objectClassPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+ jpegPhotoPresenceIndexTable.drop( CN_JOHNNY_WALKER_UUID );
+ objectClassPresenceIndexTable.drop( OU_SALES_ID );
+
+ assertTrue( objectClassPresenceIndexTable.exists( CONTEXT_ENTRY_ID ) );
+ assertFalse( objectClassPresenceIndexTable.exists( OU_SALES_ID ) );
+ assertFalse( objectClassPresenceIndexTable.exists( CN_JOHNNY_WALKER_UUID ) );
+ assertFalse( jpegPhotoPresenceIndexTable.exists( CONTEXT_ENTRY_ID ) );
+
+ // delete 1st
+ objectClassPresenceIndexTable.drop( CONTEXT_ENTRY_ID );
+
+ assertFalse( objectClassPresenceIndexTable.exists( CONTEXT_ENTRY_ID ) );
+ }
+
+
+ @Test
+ public void testGetPresenceKey() throws Exception
+ {
+ byte[] scanKey = objectClassPresenceIndexTable.getPresenceKey( UUID
+ .fromString( "00000000-0000-0000-0000-000000000000" ) );
+ assertEquals( "*00000000-0000-0000-0000-000000000000", Bytes.toString( scanKey ) );
+
+ UUID uuid = UUID.randomUUID();
+ scanKey = objectClassPresenceIndexTable.getPresenceKey( uuid );
+ assertEquals( "*" + uuid.toString(), Bytes.toString( scanKey ) );
+
+ scanKey = objectClassPresenceIndexTable.getPresenceKey( null );
+ assertEquals( "*", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassPresenceIndexTable.getPresenceKey( HBasePresenceIndexTable.VALUE_SCAN_FIRST_ENTRYID );
+ assertEquals( "*00000000-0000-0000-0000-000000000000", Bytes.toString( scanKey ) );
+
+ scanKey = objectClassPresenceIndexTable.getPresenceKey( HBasePresenceIndexTable.VALUE_SCAN_LAST_ENTRYID );
+ assertEquals( "*ffffffff-ffff-ffff-ffff-ffffffffffff", Bytes.toString( scanKey ) );
+ }
+
+
+ @Test
+ public void testExtractGetPresenceKey() throws Exception
+ {
+ UUID uuid = objectClassPresenceIndexTable.extractEntryIdFromPresenceKey( Bytes
+ .toBytes( "*00000000-0000-0000-0000-000000000000" ) );
+ assertEquals( "00000000-0000-0000-0000-000000000000", uuid.toString() );
+ }
+
+}
Modified: directory/sandbox/seelmann/hbase-partition/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/hbase-partition/src/test/resources/log4j.properties?rev=1032121&r1=1032120&r2=1032121&view=diff
==============================================================================
--- directory/sandbox/seelmann/hbase-partition/src/test/resources/log4j.properties (original)
+++ directory/sandbox/seelmann/hbase-partition/src/test/resources/log4j.properties Sat Nov 6 17:38:41 2010
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#############################################################################
-log4j.rootCategory=ERROR, stdout
+log4j.rootCategory=OFF, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout