Package org.hibernate.search.test.shards

Source Code of org.hibernate.search.test.shards.IdShardingStrategyTest

// $Id: IdShardingStrategyTest.java 20106 2010-08-04 06:31:38Z stliu $
package org.hibernate.search.test.shards;

import junit.framework.TestCase;

import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.IdHashShardingStrategy;
import org.hibernate.search.store.RAMDirectoryProvider;

/**
* @author Sanne Grinovero
*/
public class IdShardingStrategyTest extends TestCase {

  private IdHashShardingStrategy shardStrategy;

  protected void setUp() throws Exception {
    shardStrategy = new IdHashShardingStrategy();
    shardStrategy.initialize( null, new DirectoryProvider[] {
        new RAMDirectoryProvider(), new RAMDirectoryProvider() } );
  }

  public void testHashOverflow() {
    String key = String.valueOf( Integer.MAX_VALUE - 1 );
    // any key will do as long as it's hash is negative
    assertTrue( key.hashCode() < 0 );
    assertAcceptableId( key );
  }

  private void assertAcceptableId(String id) {
    try {
      shardStrategy.getDirectoryProviderForAddition( null, id, id, null );
      shardStrategy.getDirectoryProvidersForDeletion( null, id, id );
    }
    catch ( Exception e ) {
      fail( "Couldn't get directory for id " + id );
    }
  }

}
TOP

Related Classes of org.hibernate.search.test.shards.IdShardingStrategyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.