Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-2821

Correct Query Sort tests

    XMLWordPrintable

Details

    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:

            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);
      

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

            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
      

      You can find attached the test file itself.

      Attachments

        Activity

          People

            sgrinove Sanne Grinovero
            amanukya@redhat.com Anna Manukyan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: