[hibernate-issues] [Hibernate-JIRA] Resolved: (HSEARCH-237) IdHashShardingStrategy fails on IDs having negative hashcode

Sanne Grinovero (JIRA) noreply at atlassian.com
Sun Sep 14 05:02:04 EDT 2008


     [ http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-237?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sanne Grinovero resolved HSEARCH-237.
-------------------------------------

    Resolution: Fixed

> IdHashShardingStrategy fails on IDs having negative hashcode
> ------------------------------------------------------------
>
>                 Key: HSEARCH-237
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-237
>             Project: Hibernate Search
>          Issue Type: Bug
>    Affects Versions: 3.0.0.GA
>            Reporter: Rafal Glowacz
>            Assignee: Sanne Grinovero
>             Fix For: 3.1.0.Beta2
>
>   Original Estimate: 30 minutes
>  Remaining Estimate: 30 minutes
>
> public class IdShardingStrategyTest extends TestCase
> {
>     private IdHashShardingStrategy _defaultIdStrategy;
>     private IdShardingStrategy _idStrategy;
>     protected void setUp() throws Exception {
>         _idStrategy = new IdShardingStrategy();
>         _idStrategy.initialize(null, createDirectoryProviders());
>         _defaultIdStrategy = new IdHashShardingStrategy();
>         _defaultIdStrategy.initialize(null, createDirectoryProviders());
>     }
>     private DirectoryProvider[] createDirectoryProviders() {
>         return new DirectoryProvider[]{new MockDirectoryProvider(),
>                                        new MockDirectoryProvider(),
>                                        new MockDirectoryProvider()};
>     }
>     public void testIdSharding() {
>         long id = 1;
>         long limit = 1000 * 1000000 * 1000000L;
>         try {
>             while (id < limit) {
>                 generateForAddition(_idStrategy, id);
>                 generateForDeletion(_idStrategy, id);
>                 id += 129653153;
>             }
>         } catch (Exception e) {
>             fail("Couldn't get directory for id " + id);
>         }
>     }
>     public void testIdHashSharding() {
>         long id = 1;
>         long limit = 1000 * 1000000 * 1000000L;
>         try {
>             while (id < limit) {
>                 generateForAddition(_defaultIdStrategy, id);
>                 generateForDeletion(_defaultIdStrategy, id);
>                 id += 129653153;
>             }
>             fail("Should fail with ArrayIndexOutOfBoundsException for long id");
>         } catch (Exception e) {
>         }
>     }
>     private MockDirectoryProvider generateForAddition(IndexShardingStrategy strategy, long id) {
>         return (MockDirectoryProvider) strategy.getDirectoryProviderForAddition(null, id, id + "", null);
>     }
>     private DirectoryProvider[] generateForDeletion(IndexShardingStrategy strategy, long id) {
>         return strategy.getDirectoryProvidersForDeletion(null, id, id + "");
>     }
> }
> Workaround:
> Returned value is minus for id's bigger then 1.7M so for time being I added check like: return value < 0 ? -1 * value : value; Works fine for me.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list