[infinispan-issues] [JBoss JIRA] (ISPN-2821) CacheQuery sort() sorts entries in reverse order when cache values are updated

Anna Manukyan (JIRA) jira-events at lists.jboss.org
Wed Feb 13 04:36:56 EST 2013


     [ https://issues.jboss.org/browse/ISPN-2821?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Anna Manukyan updated ISPN-2821:
--------------------------------

    Description: 
While test development for the Query module, I've noticed some strange behaviour, which I couldn't explain anyhow. 

The case is the following:

3 new objects type of Person are created and put to the cache. The age parameter is set for all these objects. 

Then the age is changed for them (set to other values), and query is run using sort by age. 
The thing is that even though the sort is descending by default for integers, but the returned result list is sorted in ascending order. 

The code is:

{code}
      Person person2 = new Person();
      person2.setAge(30);
      //some other setters

      Person person3 = new Person();
      person3.setAge(25);
      // some other setters

      cache.put("key1", person2);
      cache.put("key2", person3);

      person2.setAge(35);
      person3.setAge(12);

      Sort sort = new Sort( new SortField("age", SortField.STRING)); //<--- The same happens for SortField.INT

      queryParser = createQueryParser("name");

      Query luceneQuery = queryParser.parse("Goat");
      CacheQuery cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery);
      cacheQuery.sort(sort);
      List<Object> found = cacheQuery.list();
      assert found.size() == 2;

      assert found.get(0).equals(person2);   //<------ The first element should be the one with higher age, but in reality in the first place it is person3
      assert found.get(1).equals(person3);
{code}

By the way, if initially you'll set the values in other order, then the test passes - the sorting works fine. 

{code}
      Person person2 = new Person();
      person2.setAge(25);
      //some other setters

      Person person3 = new Person();
      person3.setAge(30);
      // some other setters
     //............ the rest of the code
{code}

You can find attached the test file itself.

  was:
While test development for the Query module, I've noticed some strange behaviour, which I couldn't explain anyhow. 

The case is the following:

3 new objects type of Person are created and put to the cache. The age parameter is set for all these objects. 

Then the age is changed for them (set to other values), and query is run using sort by age. 
The thing is that even though the sort is descending by default for integers, but the returned result list is sorted in ascending order. 

The code is:

{code}
      Person person2 = new Person();
      person2.setAge(30);
      //some other setters

      Person person3 = new Person();
      person3.setAge(25);
      // some other setters

      cache.put("key1", person2);
      cache.put("key2", person3);

      person2.setAge(35);
      person3.setAge(12);

      Sort sort = new Sort( new SortField("age", SortField.STRING)); //<--- The same happens for SortField.INT

      queryParser = createQueryParser("name");

      Query luceneQuery = queryParser.parse("Goat");
      CacheQuery cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery);
      cacheQuery.sort(sort);
      List<Object> found = cacheQuery.list();
      assert found.size() == 2;

      assert found.get(0).equals(person2);   //<------ The first element should be the one with higher age, but in reality in the first place it is person3
      assert found.get(1).equals(person3);
{code}

You can find attached the test file itself.


    
> CacheQuery sort() sorts entries in reverse order when cache values are updated 
> -------------------------------------------------------------------------------
>
>                 Key: ISPN-2821
>                 URL: https://issues.jboss.org/browse/ISPN-2821
>             Project: Infinispan
>          Issue Type: Bug
>          Components: Querying
>    Affects Versions: 5.2.0.Final, 5.2.1
>            Reporter: Anna Manukyan
>            Assignee: Sanne Grinovero
>
> While test development for the Query module, I've noticed some strange behaviour, which I couldn't explain anyhow. 
> The case is the following:
> 3 new objects type of Person are created and put to the cache. The age parameter is set for all these objects. 
> Then the age is changed for them (set to other values), and query is run using sort by age. 
> The thing is that even though the sort is descending by default for integers, but the returned result list is sorted in ascending order. 
> The code is:
> {code}
>       Person person2 = new Person();
>       person2.setAge(30);
>       //some other setters
>       Person person3 = new Person();
>       person3.setAge(25);
>       // some other setters
>       cache.put("key1", person2);
>       cache.put("key2", person3);
>       person2.setAge(35);
>       person3.setAge(12);
>       Sort sort = new Sort( new SortField("age", SortField.STRING)); //<--- The same happens for SortField.INT
>       queryParser = createQueryParser("name");
>       Query luceneQuery = queryParser.parse("Goat");
>       CacheQuery cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery);
>       cacheQuery.sort(sort);
>       List<Object> found = cacheQuery.list();
>       assert found.size() == 2;
>       assert found.get(0).equals(person2);   //<------ The first element should be the one with higher age, but in reality in the first place it is person3
>       assert found.get(1).equals(person3);
> {code}
> By the way, if initially you'll set the values in other order, then the test passes - the sorting works fine. 
> {code}
>       Person person2 = new Person();
>       person2.setAge(25);
>       //some other setters
>       Person person3 = new Person();
>       person3.setAge(30);
>       // some other setters
>      //............ the rest of the code
> {code}
> You can find attached the test file itself.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the infinispan-issues mailing list