[infinispan-commits] Infinispan SVN: r675 - in branches/ISPN-32/query/src: test/java/org/infinispan/query and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Aug 13 11:41:23 EDT 2009


Author: navssurtani
Date: 2009-08-13 11:41:23 -0400 (Thu, 13 Aug 2009)
New Revision: 675

Added:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/AbstractIterator.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/EagerIterator.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyIterator.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryIterator.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/EagerIteratorTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyIteratorTest.java
Removed:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyQueryResultIterator.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIterator.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIteratorImpl.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java
Modified:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQuery.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQueryImpl.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
Log:
[ISPN-32] Most work on iterators done]

Added: branches/ISPN-32/query/src/main/java/org/infinispan/query/AbstractIterator.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/AbstractIterator.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/AbstractIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,67 @@
+package org.infinispan.query;
+
+import org.infinispan.Cache;
+
+/**
+ * // TODO: Document this
+ * <p/>
+ * This is the abstract superclass of the 2 iterators. Since some of the methods have the same implementations they have
+ * been put onto a separate class.
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+
+public abstract class AbstractIterator implements QueryIterator {
+
+   protected Object[] buffer;
+   protected Cache cache;
+
+   protected int index = 0;
+   protected int bufferIndex = -1;
+   protected int max;
+   protected int first;
+   protected int fetchSize;
+
+   public void first() {
+      index = first;
+   }
+
+   public void last() {
+      index = max;
+   }
+
+   public void afterFirst() {
+      index = first + 1;
+   }
+
+   public void beforeLast() {
+      index = max - 1;
+   }
+
+   public boolean isFirst() {
+      return index == first;
+   }
+
+   public boolean isLast() {
+      return index == max;
+   }
+
+   public boolean isAfterFirst() {
+      return index == first + 1;
+   }
+
+   public boolean isBeforeLast() {
+      return index == max - 1;
+   }
+
+   public boolean hasPrevious() {
+      return index >= first;
+   }
+
+   public boolean hasNext() {
+      return index <= max;
+   }
+   
+}

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQuery.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQuery.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQuery.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -48,33 +48,33 @@
    List<Object> list();
 
    /**
-    * Returns the results of a search as a {@link org.infinispan.query.QueryResultIterator} with a given
+    * Returns the results of a search as a {@link QueryIterator} with a given
     * integer parameter - the fetchSize.
     *
     * @param fetchSize integer to be given to the implementation constructor.
     * @return a QueryResultIterator which can be used to iterate through the results that were found.
     */
 
-   QueryResultIterator iterator(int fetchSize);
+   QueryIterator iterator(int fetchSize);
 
    /**
-    * Returns the results of a search as a {@link QueryResultIterator}. This calls {@link CacheQuery#iterator(int fetchSize)}
+    * Returns the results of a search as a {@link QueryIterator}. This calls {@link CacheQuery#iterator(int fetchSize)}
     * but uses a default fetchSize of 1. 
     *
     * @return a QueryResultIterator which can be used to iterate through the results that were found.
     */
 
-   QueryResultIterator iterator();
+   QueryIterator iterator();
 
    /**
-    * Lazily loads the results from the Query as a {@link org.infinispan.query.QueryResultIterator} with a given
+    * Lazily loads the results from the Query as a {@link QueryIterator} with a given
     * integer parameter - the fetchSize.
     *
-    * @param fetchSize integer to be passed into the lazy implementation of {@link org.infinispan.query.QueryResultIterator}
+    * @param fetchSize integer to be passed into the lazy implementation of {@link QueryIterator}
     * @return a QueryResultIterator which can be used to <B>lazily</B> iterate through results.
     */
 
-   QueryResultIterator lazyIterator(int fetchSize);
+   QueryIterator lazyIterator(int fetchSize);
 
    /**
     * Calls the {@link CacheQuery#lazyIterator(int fetchSize)} method but passes in a default 1 as a parameter.
@@ -83,7 +83,7 @@
     */
 
 
-   QueryResultIterator lazyIterator();
+   QueryIterator lazyIterator();
 
    /**
     * Sets a result with a given index to the first result.

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQueryImpl.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQueryImpl.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheQueryImpl.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -222,12 +222,12 @@
 
    }
 
-   public QueryResultIterator iterator() throws HibernateException
+   public QueryIterator iterator() throws HibernateException
    {
       return iterator(1);
    }
 
-   public QueryResultIterator iterator(int fetchSize) throws HibernateException
+   public QueryIterator iterator(int fetchSize) throws HibernateException
    {
       List<Object> keyList = null;
       IndexSearcher searcher = buildSearcher(searchFactory);
@@ -271,15 +271,15 @@
 
       }
 
-      return new QueryResultIteratorImpl(keyList, cache, fetchSize);
+      return new EagerIterator(keyList, cache, fetchSize);
    }
 
-   public QueryResultIterator lazyIterator()
+   public QueryIterator lazyIterator()
    {
       return lazyIterator(1);
    }
 
-   public QueryResultIterator lazyIterator(int fetchSize)
+   public QueryIterator lazyIterator(int fetchSize)
    {
       IndexSearcher searcher = buildSearcher(searchFactory);
 
@@ -291,7 +291,7 @@
 
          DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory, indexProjection, idFieldNames, allowFieldSelectionInProjection);
 
-         return new LazyQueryResultIterator(extractor, cache, searcher, searchFactory, first, max, fetchSize);
+         return new LazyIterator(extractor, cache, searcher, searchFactory, first, max, fetchSize);
       }
       catch (IOException e)
       {

Copied: branches/ISPN-32/query/src/main/java/org/infinispan/query/EagerIterator.java (from rev 632, branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIteratorImpl.java)
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/EagerIterator.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/EagerIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,274 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query;
+
+
+import net.jcip.annotations.NotThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.infinispan.Cache;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * This is the implementation class for the interface QueryResultIterator which extends ListIterator. It is what is
+ * returned when the {@link org.infinispan.query.CacheQuery#iterator()}.
+ * <p/>
+ * <p/>
+ *
+ * //TODO: navssurtani --> Document this.
+ *
+ * @author Navin Surtani
+ */
+
+ at NotThreadSafe
+public class EagerIterator extends AbstractIterator {
+   //private final int size;
+   private List<Object> idList;
+
+   private int lowerLimit = 0;
+   private int upperLimit = 0;
+   private static final Log log = LogFactory.getLog(EagerIterator.class);
+
+
+   public EagerIterator(List<Object> idList, Cache cache, int fetchSize)
+   {
+      if (fetchSize < 1)
+      {
+         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+      }
+
+      this.idList = idList;
+      this.cache = cache;
+      this.fetchSize = fetchSize;
+
+      // Set the values of first and max so that they can be used by the methods on the superclass.
+      // Since this is the eager version, we know that we can set the 'first' field to 0.
+
+      first = 0;
+
+      // Similarly max can be set to the size of the list that gets passed in - 1. Using -1 because max is on base 0 while
+      // the size of the list is base 1.
+
+      max = idList.size() - 1;
+
+      buffer = new Object[this.fetchSize];
+   }
+
+   /**
+    * Jumps to a given index in the list of results.
+    *
+    * @param index to jump to
+    * @throws IndexOutOfBoundsException
+    */
+
+   public void jumpToResult(int index) throws IndexOutOfBoundsException
+   {
+      if (index > idList.size() || index < 0)
+      {
+         throw new IndexOutOfBoundsException("The index you entered is either greater than the size of the list or negative");
+      }
+      this.index = index;
+   }
+
+   public void close()
+   {
+      // This method does not need to do anything for this type of iterator as when an instace of it is
+      // created, the iterator() method in CacheQueryImpl closes everything that needs to be closed.
+
+      // TODO: Should I be throwing an exception here?
+   }
+
+   /**
+    * Returns the next element in the list
+    *
+    * @return The next element in the list.
+    */
+   public Object next()
+   {
+      if (!hasNext()) throw new IndexOutOfBoundsException("Out of boundaries. There is no next");
+
+      Object toReturn;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+      if (bufferIndex >= 0                                       // buffer init check
+              && index >= bufferIndex                           // lower boundary
+              && index < (bufferIndex + bufferSize))          // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = index - bufferIndex;
+         toReturn = buffer[indexToReturn];
+      }
+
+      else
+      {
+         // We need to populate the buffer.
+
+         toReturn = cache.get(idList.get(index));
+
+         //Wiping bufferObjects and the bufferIndex so that there is no stale data.
+
+         Arrays.fill(buffer, null);
+         buffer[0] = toReturn;
+
+         // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
+         //now loop through bufferSize times to add the rest of the objects into the list.
+
+         for (int i = 1; i < bufferSize; i++)
+         {
+            if (index + i > max)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("Your current index + bufferSize exceeds the size of your number of hits");
+               }
+               break;
+            }
+
+            Object toBuffer = cache.get(idList.get(index + i));
+            buffer[i] = toBuffer;
+         }
+         bufferIndex = index;
+
+      }
+
+      index++;
+      return toReturn;
+   }
+
+
+   /**
+    * Returns the previous element in the list.
+    *
+    * @return The previous element in the list.
+    */
+
+   public Object previous()
+   {
+      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
+
+      Object toReturn;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+
+      if (bufferIndex >= 0 // buffer init check
+              && index <= bufferIndex // lower boundary
+              && index >= (bufferIndex + bufferSize)) // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
+         toReturn = buffer[indexToReturn];
+      }
+      else
+      {
+         toReturn = cache.get(idList.get(index));
+         // Wiping bufferObjects and the bufferIndex so that there is no stale data.
+
+         Arrays.fill(buffer, null);
+         buffer[0] = toReturn;
+
+         // we now need to buffer objects at index "index", as well as the next "fetchsize - 1" elements.
+         // I.e., a total of fetchsize elements will be buffered.
+         // now loop through bufferSize times to add the rest of the objects into the list.
+
+         for (int i = 1; i < bufferSize; i++)
+         {
+            if (index - i < first)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("Your current index - bufferSize exceeds the size of your number of hits");
+               }
+               break;
+            }
+            Object toBuffer = cache.get(idList.get(index - i));
+            buffer[i] = toBuffer;
+         }
+         bufferIndex = index;
+      }
+      index--;
+      return toReturn;
+   }
+
+   /**
+    * Returns the index of the element that would be returned by a subsequent call to next.
+    *
+    * @return Index of next element.
+    */
+
+   public int nextIndex()
+   {
+      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
+      return index + 1;
+
+   }
+
+   /**
+    * Returns the index of the element that would be returned by a subsequent call to previous.
+    *
+    * @return Index of previous element.
+    */
+
+   public int previousIndex()
+   {
+      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries");
+      return index - 1;
+   }
+
+   /**
+    * This method is not supported and should not be used. Use cache.remove() instead.
+    */
+   public void remove()
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+   public void set(Object o) throws UnsupportedOperationException
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+
+   public void add(Object o)
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache. Please use searchableCache.put()");
+   }
+
+
+}

Copied: branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyIterator.java (from rev 642, branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyQueryResultIterator.java)
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyIterator.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.apache.lucene.search.IndexSearcher;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+/**
+ * Implementation for {@link QueryIterator}. This is what is returned when the {@link CacheQuery#lazyIterator()} method
+ * is called. This loads the results only when required and hence differs from {@link EagerIterator} which is the
+ * other implementation of QueryResultIterator.
+ *
+ * @author Navin Surtani
+ */
+
+ at NotThreadSafe
+public class LazyIterator extends AbstractIterator {
+
+   private DocumentExtractor extractor;
+   private IndexSearcher searcher;
+   private SearchFactoryImplementor searchFactory;
+
+
+
+   public LazyIterator(DocumentExtractor extractor, Cache cache,
+                            IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max, int fetchSize) {
+      if (fetchSize < 1) {
+         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+      }
+
+      this.extractor = extractor;
+      this.cache = cache;
+      index = first;
+      this.first = first;
+      this.max = max;
+      this.fetchSize = fetchSize;
+      this.searcher = searcher;
+      this.searchFactory = searchFactory;
+
+      //Create an buffer with size fetchSize (which is the size of the required buffer).
+      buffer = new Object[this.fetchSize];
+   }
+
+   public void jumpToResult(int index) throws IndexOutOfBoundsException {
+      if (index < first || index > max) {
+         throw new IndexOutOfBoundsException("The given index is incorrect. Please check and try again.");
+      }
+
+      this.index = first + index;
+   }
+
+   public void close() {
+      IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+   }
+
+   public Object next() {
+      if (!hasNext()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no next");
+
+      Object toReturn = null;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+      if (bufferIndex >= 0                                       // buffer init check
+            && index >= bufferIndex                           // lower boundary
+            && index < (bufferIndex + bufferSize))          // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = index - bufferIndex;
+         toReturn = buffer[indexToReturn];
+      } else {
+         // else we need to populate the buffer and get what we need.
+
+         try {
+            String documentId = (String) extractor.extract(index).id;
+            toReturn = cache.get(documentId);
+
+            //Wiping bufferObjects and the bufferIndex so that there is no stale data.
+            Arrays.fill(buffer, null);
+            buffer[0] = toReturn;
+
+            // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
+            // ignore loop below, in needs fixing
+            //now loop through bufferSize times to add the rest of the objects into the list.
+
+            for (int i = 1; i < bufferSize; i++) {
+               String bufferDocumentId = (String) extractor.extract(index + i).id;
+               Object toBuffer = cache.get(bufferDocumentId);
+               buffer[i] = toBuffer;
+            }
+            bufferIndex = index;
+         }
+         catch (IOException e) {
+            throw new CacheException();
+         }
+      }
+
+      index++;
+      return toReturn;
+   }
+
+   public Object previous() {
+      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
+
+      Object toReturn = null;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+
+      if (bufferIndex >= 0 // buffer init check
+            && index <= bufferIndex // lower boundary
+            && index >= (bufferIndex + bufferSize)) // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
+         toReturn = buffer[indexToReturn];
+      }
+
+      try {
+         //Wiping the buffer
+         Arrays.fill(buffer, null);
+
+         String documentId = (String) extractor.extract(index).id;
+         toReturn = cache.get(documentId);
+
+         buffer[0] = toReturn;
+
+         //now loop through bufferSize times to add the rest of the objects into the list.
+         for (int i = 1; i < bufferSize; i++) {
+            String bufferDocumentId = (String) extractor.extract(index - i).id;    //In this case it has to be index - i because previous() is called.
+            Object toBuffer = cache.get(bufferDocumentId);
+            buffer[i] = toBuffer;
+         }
+
+         bufferIndex = index;
+      }
+      catch (IOException e) {
+         e.printStackTrace();
+      }
+      index--;
+      return toReturn;
+   }
+
+   public int nextIndex() {
+      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
+      return index + 1;
+   }
+
+   public int previousIndex() {
+      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries.");
+      return index - 1;
+   }
+
+   /**
+    * This method is not supported and should not be used. Use cache.remove() instead.
+    */
+   public void remove() {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+   public void set(Object o) throws UnsupportedOperationException {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+
+   public void add(Object o) {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyQueryResultIterator.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyQueryResultIterator.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/LazyQueryResultIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -1,250 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.infinispan.query;
-
-import org.apache.lucene.search.IndexSearcher;
-import org.hibernate.search.engine.DocumentExtractor;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.infinispan.Cache;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.NoSuchElementException;
-
-/**
- * Implementation for {@link org.infinispan.query.QueryResultIterator}. This is what is returned when the {@link
- * CacheQuery#lazyIterator()} method is called. This loads the results only when required and hence differs from {@link
- * org.infinispan.query.QueryResultIteratorImpl} which is the other implementation of QueryResultIterator.
- *
- * @author Navin Surtani
- */
-public class LazyQueryResultIterator implements QueryResultIterator {
-   private int index = 0;
-   private int bufferIndex = -1; // this is the index at which the buffer was populated.  Hence, the first element of the buffer is at this index in the overall result set.
-   private int max = 0;
-   private int first = 0;
-   private int fetchSize = 0;     // difference between fetchsize and index must always be the value for first. fetchSize has to be at least 1.
-   private DocumentExtractor extractor;
-   private Cache cache;
-   private IndexSearcher searcher;
-   private SearchFactoryImplementor searchFactory;
-   Object[] buffer;
-
-   public LazyQueryResultIterator(DocumentExtractor extractor, Cache cache,
-                                  IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max, int fetchSize) {
-      if (fetchSize < 1) {
-         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
-      }
-
-      this.extractor = extractor;
-      this.cache = cache;
-      index = first;
-      this.first = first;
-      this.max = max;
-      this.fetchSize = fetchSize;
-      this.searcher = searcher;
-      this.searchFactory = searchFactory;
-
-      //Create an buffer with size fetchSize (which is the size of the required buffer).
-      buffer = new Object[this.fetchSize];
-   }
-
-   public void jumpToResult(int index) throws IndexOutOfBoundsException {
-      if (index < first || index > max) {
-         throw new IndexOutOfBoundsException("The given index is incorrect. Please check and try again.");
-      }
-
-      this.index = first + index;
-
-   }
-
-   public void first() {
-      index = first;
-   }
-
-   public void last() {
-      index = max;
-   }
-
-   public void afterFirst() {
-      index = first + 1;
-   }
-
-   public void beforeLast() {
-      index = max - 1;
-   }
-
-   public boolean isFirst() {
-      return index == first;
-   }
-
-   public boolean isLast() {
-      return index == max;
-   }
-
-   public boolean isAfterFirst() {
-      return index == first + 1;
-   }
-
-   public boolean isBeforeLast() {
-      return index == max - 1;
-   }
-
-   public void close() {
-      IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
-   }
-
-   public boolean hasNext() {
-      return index <= max;
-   }
-
-   public Object next() {
-      if (!hasNext()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no next");
-
-      Object toReturn = null;
-      int bufferSize = buffer.length;
-
-      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
-      if (bufferIndex >= 0                                       // buffer init check
-            && index >= bufferIndex                           // lower boundary
-            && index < (bufferIndex + bufferSize))          // upper boundary
-      {
-         // now we can get this from the buffer.  Sweet!
-         int indexToReturn = index - bufferIndex;
-         toReturn = buffer[indexToReturn];
-      } else {
-         // else we need to populate the buffer and get what we need.
-
-         try {
-            String documentId = (String) extractor.extract(index).id;
-            toReturn = cache.get(documentId);
-
-            //Wiping bufferObjects and the bufferIndex so that there is no stale data.
-            Arrays.fill(buffer, null);
-            buffer[0] = toReturn;
-
-            // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
-            // ignore loop below, in needs fixing
-            //now loop through bufferSize times to add the rest of the objects into the list.
-
-            for (int i = 1; i < bufferSize; i++) {
-               String bufferDocumentId = (String) extractor.extract(index + i).id;
-               Object toBuffer = cache.get(bufferDocumentId);
-               buffer[i] = toBuffer;
-            }
-            bufferIndex = index;
-         }
-         catch (IOException e) {
-            e.printStackTrace();
-         }
-      }
-
-      index++;
-      return toReturn;
-   }
-
-   public boolean hasPrevious() {
-      return index >= first;
-   }
-
-   public Object previous() {
-      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
-
-      Object toReturn = null;
-      int bufferSize = buffer.length;
-
-      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
-
-      if (bufferIndex >= 0 // buffer init check
-            && index <= bufferIndex // lower boundary
-            && index >= (bufferIndex + bufferSize)) // upper boundary
-      {
-         // now we can get this from the buffer.  Sweet!
-         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
-         toReturn = buffer[indexToReturn];
-      }
-
-      try {
-         //Wiping the buffer
-         Arrays.fill(buffer, null);
-
-         String documentId = (String) extractor.extract(index).id;
-         toReturn = cache.get(documentId);
-
-         buffer[0] = toReturn;
-
-         //now loop through bufferSize times to add the rest of the objects into the list.
-         for (int i = 1; i < bufferSize; i++) {
-            String bufferDocumentId = (String) extractor.extract(index - i).id;    //In this case it has to be index - i because previous() is called.
-            Object toBuffer = cache.get(bufferDocumentId);
-            buffer[i] = toBuffer;
-         }
-
-         bufferIndex = index;
-      }
-      catch (IOException e) {
-         e.printStackTrace();
-      }
-      index--;
-      return toReturn;
-   }
-
-   public int nextIndex() {
-      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
-      return index + 1;
-   }
-
-   public int previousIndex() {
-      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries.");
-      return index - 1;
-   }
-
-   /**
-    * This method is not supported and should not be used. Use cache.remove() instead.
-    */
-   public void remove() {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
-   }
-
-   /**
-    * This method is not supported in and should not be called. Use cache.put() instead.
-    *
-    * @param o
-    * @throws UnsupportedOperationException
-    */
-   public void set(Object o) throws UnsupportedOperationException {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
-   }
-
-   /**
-    * This method is not supported in and should not be called. Use cache.put() instead.
-    *
-    * @param o
-    * @throws UnsupportedOperationException
-    */
-
-   public void add(Object o) {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
-   }
-
-}

Copied: branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryIterator.java (from rev 632, branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIterator.java)
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryIterator.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+
+package org.infinispan.query;
+
+import java.util.ListIterator;
+
+/**
+ * Iterates over query results
+ * <p/>
+ * @author Manik Surtani
+ * @author Navin Surtani 
+ */
+public interface QueryIterator extends ListIterator
+{
+   /**
+    * Jumps to a specific index in the iterator.
+    *
+    * @param index index to jump to.
+    * @throws IndexOutOfBoundsException if the index is out of bounds
+    */
+   void jumpToResult(int index) throws IndexOutOfBoundsException;
+
+   /**
+    * Jumps to the first result
+    */
+   void first();
+
+   /**
+    * Jumps to the last result
+    */
+   void last();
+
+   /**
+    * Jumps to the one-after-the-first result
+    */
+   void afterFirst();
+
+   /**
+    * Jumps to the one-before-the-last result
+    */
+   void beforeLast();
+
+   /**
+    * @return true if the current result is the first
+    */
+   boolean isFirst();
+
+   /**
+    * @return true if the current result is the last
+    */
+   boolean isLast();
+
+   /**
+    * @return true if the current result is one after the first
+    */
+   boolean isAfterFirst();
+
+   /**
+    * @return true if the current result is one before the last
+    */
+   boolean isBeforeLast();
+
+   /**
+    * This method must be called on your iterator once you have finished so that Lucene resources can be freed up. 
+    */
+
+   void close();
+}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIterator.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIterator.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIterator.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -1,88 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
-
-package org.infinispan.query;
-
-import java.util.ListIterator;
-
-/**
- * Iterates over query results
- * <p/>
- * @author Manik Surtani
- * @author Navin Surtani 
- */
-public interface QueryResultIterator extends ListIterator
-{
-   /**
-    * Jumps to a specific index in the iterator.
-    *
-    * @param index index to jump to.
-    * @throws IndexOutOfBoundsException if the index is out of bounds
-    */
-   void jumpToResult(int index) throws IndexOutOfBoundsException;
-
-   /**
-    * Jumps to the first result
-    */
-   void first();
-
-   /**
-    * Jumps to the last result
-    */
-   void last();
-
-   /**
-    * Jumps to the one-after-the-first result
-    */
-   void afterFirst();
-
-   /**
-    * Jumps to the one-before-the-last result
-    */
-   void beforeLast();
-
-   /**
-    * @return true if the current result is the first
-    */
-   boolean isFirst();
-
-   /**
-    * @return true if the current result is the last
-    */
-   boolean isLast();
-
-   /**
-    * @return true if the current result is one after the first
-    */
-   boolean isAfterFirst();
-
-   /**
-    * @return true if the current result is one before the last
-    */
-   boolean isBeforeLast();
-
-   /**
-    * This method must be called on your iterator once you have finished so that Lucene resources can be freed up. 
-    */
-
-   void close();
-}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIteratorImpl.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIteratorImpl.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryResultIteratorImpl.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -1,363 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.infinispan.query;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.infinispan.Cache;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * This is the implementation class for the interface QueryResultIterator which extends ListIterator. It is what is
- * returned when the {@link org.infinispan.query.CacheQuery#iterator()}.
- * <p/>
- * <p/>
- *
- * //TODO: navssurtani --> Document this.
- *
- * @author Navin Surtani
- */
-public class QueryResultIteratorImpl implements QueryResultIterator
-{
-   private int index = 0;
-   //private final int size;
-   private List<Object> idList;
-   private Cache cache;
-   private int lowerLimit = 0;
-   private int upperLimit = 0;
-   private int fetchSize = 0;
-   private int bufferIndex = -1; // this is the index at which the buffer was populated.  Hence, the first element of the buffer is at this index in the overall result set.
-   private Object[] buffer;
-   private static final Log log = LogFactory.getLog(QueryResultIteratorImpl.class);
-
-
-   public QueryResultIteratorImpl(List<Object> idList, Cache cache, int fetchSize)
-   {
-      if (fetchSize < 1)
-      {
-         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
-      }
-
-      this.idList = idList;
-      this.cache = cache;
-      upperLimit = idList.size() - 1;
-      this.fetchSize = fetchSize;
-
-      buffer = new Object[this.fetchSize];
-   }
-
-   /**
-    * Jumps to a given index in the list of results.
-    *
-    * @param index to jump to
-    * @throws IndexOutOfBoundsException
-    */
-
-   public void jumpToResult(int index) throws IndexOutOfBoundsException
-   {
-      if (index > idList.size() || index < 0)
-      {
-         throw new IndexOutOfBoundsException("The index you entered is either greater than the size of the list or negative");
-      }
-      this.index = index;
-   }
-
-   /**
-    * Jumps to first element in the list.
-    */
-
-   public void first()
-   {
-      index = 0;
-   }
-
-   /**
-    * Jumps to last element in the list.
-    */
-
-   public void last()
-   {
-      index = idList.size() - 1;
-   }
-
-   /**
-    * Jumps to second element in the list.
-    */
-
-   public void afterFirst()
-   {
-      index = 1;
-   }
-
-   /**
-    * Jumps to penultimate element in the list.
-    */
-
-   public void beforeLast()
-   {
-      index = idList.size() - 2;
-   }
-
-   /**
-    * @return true if the current element is the first in the list.
-    */
-
-   public boolean isFirst()
-   {
-      return index == 0;
-   }
-
-   /**
-    * @return true if the current result is the last one.
-    */
-
-   public boolean isLast()
-   {
-      return index == idList.size() - 1;
-
-   }
-
-   /**
-    * @return true if the current result is one after the first.
-    */
-
-   public boolean isAfterFirst()
-   {
-      return index == 1;
-//      return idList.get(index).equals(idList.get(1));
-   }
-
-   /**
-    * @return true if the current result is one before the last
-    */
-
-   public boolean isBeforeLast()
-   {
-      return index == idList.size() - 2;
-//      return idList.get(index) == idList.get(idList.size() - 2);
-   }
-
-   public void close()
-   {
-      // This method does not need to do anything for this type of iterator as when an instace of it is
-      // created, the iterator() method in CacheQueryImpl closes everything that needs to be closed.
-   }
-
-   /**
-    * Returns true if the list has more elements when traversing the list in the forward direction.
-    *
-    * @return true if the list has more elements when traversing the list in the forward direction.
-    */
-
-   public boolean hasNext()
-   {
-      return index <= upperLimit;
-   }
-
-   /**
-    * Returns the next element in the list
-    *
-    * @return The next element in the list.
-    */
-   public Object next()
-   {
-      if (!hasNext()) throw new IndexOutOfBoundsException("Out of boundaries. There is no next");
-
-      Object toReturn;
-      int bufferSize = buffer.length;
-
-      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
-      if (bufferIndex >= 0                                       // buffer init check
-              && index >= bufferIndex                           // lower boundary
-              && index < (bufferIndex + bufferSize))          // upper boundary        //TODO: - Why does this logic work but <= not. >= works with previous() however.
-      {
-         // now we can get this from the buffer.  Sweet!
-         int indexToReturn = index - bufferIndex;
-         toReturn = buffer[indexToReturn];
-      }
-
-      else
-      {
-         // We need to populate the buffer.
-
-         toReturn = cache.get(idList.get(index));
-
-         //Wiping bufferObjects and the bufferIndex so that there is no stale data.
-
-         Arrays.fill(buffer, null);
-         buffer[0] = toReturn;
-
-         // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
-         //now loop through bufferSize times to add the rest of the objects into the list.
-
-         for (int i = 1; i < bufferSize; i++)
-         {
-            if (index + i > upperLimit)
-            {
-               if (log.isDebugEnabled())
-               {
-                  log.debug("Your current index + bufferSize exceeds the size of your number of hits");
-               }
-               break;
-            }
-
-            Object toBuffer = cache.get(idList.get(index + i));
-            buffer[i] = toBuffer;
-         }
-         bufferIndex = index;
-
-      }
-
-      index++;
-      return toReturn;
-   }
-
-   /**
-    * Returns true if the list has more elements when traversing the list in the reverse direction.
-    *
-    * @return true if the list iterator has more elements when traversing the list in the reverse direction
-    */
-   public boolean hasPrevious()
-   {
-      return index >= lowerLimit;
-   }
-
-   /**
-    * Returns the previous element in the list.
-    *
-    * @return The previous element in the list.
-    */
-
-   public Object previous()
-   {
-      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
-
-      Object toReturn;
-      int bufferSize = buffer.length;
-
-      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
-
-      if (bufferIndex >= 0 // buffer init check
-              && index <= bufferIndex // lower boundary
-              && index >= (bufferIndex + bufferSize)) // upper boundary
-      {
-         // now we can get this from the buffer.  Sweet!
-         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
-         toReturn = buffer[indexToReturn];
-      }
-      else
-      {
-         toReturn = cache.get(idList.get(index));
-         // Wiping bufferObjects and the bufferIndex so that there is no stale data.
-
-         Arrays.fill(buffer, null);
-         buffer[0] = toReturn;
-
-         // we now need to buffer objects at index "index", as well as the next "fetchsize - 1" elements.
-         // I.e., a total of fetchsize elements will be buffered.
-         // now loop through bufferSize times to add the rest of the objects into the list.
-
-         for (int i = 1; i < bufferSize; i++)
-         {
-            if (index - i < lowerLimit)
-            {
-               if (log.isDebugEnabled())
-               {
-                  log.debug("Your current index - bufferSize exceeds the size of your number of hits");
-               }
-               break;
-            }
-            Object toBuffer = cache.get(idList.get(index - i));
-            buffer[i] = toBuffer;
-         }
-         bufferIndex = index;
-      }
-      index--;
-      return toReturn;
-   }
-
-   /**
-    * Returns the index of the element that would be returned by a subsequent call to next.
-    *
-    * @return Index of next element.
-    */
-
-   public int nextIndex()
-   {
-      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
-      return index + 1;
-
-   }
-
-   /**
-    * Returns the index of the element that would be returned by a subsequent call to previous.
-    *
-    * @return Index of previous element.
-    */
-
-   public int previousIndex()
-   {
-      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries");
-      return index - 1;
-   }
-
-   /**
-    * This method is not supported and should not be used. Use cache.remove() instead.
-    */
-   public void remove()
-   {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
-   }
-
-   /**
-    * This method is not supported in and should not be called. Use cache.put() instead.
-    *
-    * @param o
-    * @throws UnsupportedOperationException
-    */
-   public void set(Object o) throws UnsupportedOperationException
-   {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
-   }
-
-   /**
-    * This method is not supported in and should not be called. Use cache.put() instead.
-    *
-    * @param o
-    * @throws UnsupportedOperationException
-    */
-
-   public void add(Object o)
-   {
-      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache. Please use searchableCache.put()");
-   }
-
-   public void setFetchSize(int newFetchSize){
-      fetchSize = newFetchSize;
-   }
-
-}

Copied: branches/ISPN-32/query/src/test/java/org/infinispan/query/EagerIteratorTest.java (from rev 642, branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java)
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/EagerIteratorTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/EagerIteratorTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,220 @@
+package org.infinispan.query;
+
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
+import org.easymock.IAnswer;
+import org.infinispan.Cache;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Navin Surtani
+ *         <p/>
+ *         Test class for the QueryResultIteratorImpl
+ */
+
+ at Test(groups = "functional")
+public class EagerIteratorTest {
+   List<Object> keys;
+   Map<String, String> dummyResults;
+   QueryIterator iterator;
+   int fetchSize = 1;
+   Cache<String, String> cache;
+
+   @BeforeMethod
+   public void setUp() throws Exception {
+
+      // create a set of dummy keys
+      keys = new ArrayList<Object>();
+      // create some dummy data
+      dummyResults = new HashMap<String, String>();
+
+      for (int i=1; i<=10; i++) {
+         String key = "key" + i;
+         keys.add(key);
+         dummyResults.put(key, "Result number " + i);
+      }
+
+      // create the instance of the iterator.
+      cache = createMock(Cache.class);
+
+      expect(cache.get(anyObject())).andAnswer(new IAnswer<String>(){
+         public String answer() throws Throwable {
+            String k = getCurrentArguments()[0].toString();
+            return dummyResults.get(k);
+         }
+      }).anyTimes();
+
+      iterator = new EagerIterator(keys, cache, fetchSize);
+      EasyMock.replay(cache);
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      keys = null;
+      dummyResults = null;
+      iterator = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult((keys.size() - 1));
+      assert iterator.isLast();
+
+      iterator.jumpToResult(keys.size() - 2);
+      assert iterator.isBeforeLast();
+   }
+
+   public void testFirst() {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+      System.out.println(next);
+
+      assert next == dummyResults.get(keys.get(0));
+
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == dummyResults.get(keys.get(0));
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast() {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      Object next = iterator.next();
+
+      //Returns the size of the list of keys.
+      int size = keys.size();
+
+      //Makes sure that previous is the last element.
+      assert next == dummyResults.get(keys.get(size - 1));
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst() {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == dummyResults.get(keys.get(1));
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast() {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      int size = keys.size();
+      assert next == dummyResults.get(keys.get(size - 2));
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst() {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast() {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst() {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast() {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext() {
+      iterator.first();
+      for (int i = 0; i < keys.size(); i++) {
+         System.out.println("Loop number count: - " + (i + 1));
+         Object expectedValue = dummyResults.get(keys.get(i));
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+         assert expectedValue == iterator.next(); // tests next()
+      }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious() {
+      iterator.last();
+      for (int i = keys.size() - 1; i >= 0; i--) {
+         Object expectedValue = dummyResults.get(keys.get(i));
+         assert iterator.hasPrevious(); // should have previous as long as we are more than the number of elements.
+         assert expectedValue == iterator.previous(); // tests previous()
+      }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex() {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == keys.size();
+
+   }
+
+   public void testPreviousIndex() {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == (keys.size() - 2);
+   }
+
+}

Copied: branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyIteratorTest.java (from rev 642, branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java)
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyIteratorTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyIteratorTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -0,0 +1,344 @@
+package org.infinispan.query;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.IndexSearcher;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
+import org.easymock.IAnswer;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.EntityInfo;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.Cache;
+import org.infinispan.query.helper.IndexCleanUp;
+import org.infinispan.query.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.testng.annotations.ExpectedExceptions;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * @author Navin Surtani
+ */
+ at Test(groups = "functional")
+public class LazyIteratorTest {
+   Cache<String, Person> cache;
+   LazyIterator iterator = null;
+   int fetchSize = 1;
+   Person person1, person2, person3, person4, person5, person6, person7, person8, person9, person10;
+   StringBuilder builder;
+   Map<String, Person> dummyDataMap;
+   List<String> keyList;
+
+   @BeforeTest
+   public void setUpBeforeTest() throws Exception {
+      dummyDataMap = new HashMap<String, Person>();
+
+      // Create a bunch of Person instances.
+      person1 = new Person();
+      person2 = new Person();
+      person3 = new Person();
+      person4 = new Person();
+      person5 = new Person();
+      person6 = new Person();
+      person7 = new Person();
+      person8 = new Person();
+      person9 = new Person();
+      person10 = new Person();
+
+
+      // Set the fields to something so that everything will be found.
+      person1.setBlurb("cat");
+      person2.setBlurb("cat");
+      person3.setBlurb("cat");
+      person4.setBlurb("cat");
+      person5.setBlurb("cat");
+      person6.setBlurb("cat");
+      person7.setBlurb("cat");
+      person8.setBlurb("cat");
+      person9.setBlurb("cat");
+      person10.setBlurb("cat");
+
+      // Stick them all into a dummy map.
+      dummyDataMap.put("key1", person1);
+      dummyDataMap.put("key2", person2);
+      dummyDataMap.put("key3", person3);
+      dummyDataMap.put("key4", person4);
+      dummyDataMap.put("key5", person5);
+      dummyDataMap.put("key6", person6);
+      dummyDataMap.put("key7", person7);
+      dummyDataMap.put("key8", person8);
+      dummyDataMap.put("key9", person9);
+      dummyDataMap.put("key10", person10);
+
+      keyList = new ArrayList<String>();
+
+      keyList.add("key1");
+      keyList.add("key2");
+      keyList.add("key3");
+      keyList.add("key4");
+      keyList.add("key5");
+      keyList.add("key6");
+      keyList.add("key7");
+      keyList.add("key8");
+      keyList.add("key9");
+      keyList.add("key10");
+
+
+   }
+
+   @AfterTest
+   public void tearDownAfterTest() {
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   @BeforeMethod
+   public void setUp() throws ParseException {
+
+      // Setting up the cache mock instance
+      cache = createMock(Cache.class);
+
+      expect(cache.get(anyObject())).andAnswer(new IAnswer<Person>() {
+
+         public Person answer() throws Throwable {
+            String key = getCurrentArguments()[0].toString();
+            return dummyDataMap.get(key);
+         }
+      }).anyTimes();
+
+
+      // Create mock instances of other things required to create a lazy iterator.
+
+      SearchFactoryImplementor searchFactory = createMock(SearchFactoryImplementor.class);
+
+      DocumentExtractor extractor = org.easymock.classextension.EasyMock.createMock(DocumentExtractor.class);
+
+
+      try {
+         org.easymock.classextension.EasyMock.expect(extractor.extract(anyInt())).andAnswer(new IAnswer<EntityInfo>() {
+
+            public EntityInfo answer() throws Throwable {
+               int index = (Integer) getCurrentArguments()[0];
+               String keyString = keyList.get(index);
+
+               System.out.println("The key for index parameter " + index + " is " + keyString);
+
+               return new EntityInfo(Person.class, keyString, null);
+            }
+         }).anyTimes();
+
+
+      } catch (IOException e) {
+         e.printStackTrace();
+      }
+      IndexSearcher searcher = org.easymock.classextension.EasyMock.createMock(IndexSearcher.class);
+
+      EasyMock.replay(cache, searchFactory);
+      org.easymock.classextension.EasyMock.replay(searcher, extractor);
+
+      iterator = new LazyIterator(extractor, cache, searcher, searchFactory, 0, 9, fetchSize);
+
+   }
+
+
+   @AfterMethod
+   public void tearDown() {
+      iterator = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult(9);
+      assert iterator.isLast();
+
+      iterator.jumpToResult(8);
+      assert iterator.isBeforeLast();
+   }
+
+
+   //TODO: This is deprecated. What should I be using instead?
+   @ExpectedExceptions(IndexOutOfBoundsException.class)
+   public void testOutOfBoundsBelow(){     
+      iterator.jumpToResult(-1);
+   }
+
+   @ExpectedExceptions(IndexOutOfBoundsException.class)
+   public void testOutOfBoundsAbove(){
+      iterator.jumpToResult(keyList.size() + 1);
+   }
+
+
+
+   public void testFirst() {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+
+      System.out.println(next);
+      assert next == person1;
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == person1;
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast() {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      iterator.first();
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst() {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == person2;
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast() {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      assert next == person9;
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst() {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast() {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst() {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast() {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext() {
+      iterator.first();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();
+
+      for (int i = 1; i <= 10; i++) {
+         builder.delete(0, 4);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+         Object expectedValue = cache.get(keyString);
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+
+         Object next = iterator.next();
+
+         assert expectedValue == next; // tests next()
+      }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious() {
+      iterator.last();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();
+
+      for (int i = 10; i >= 1; i--) {
+         builder.delete(0, 5);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+
+
+         Object expectedValue = cache.get(keyString);
+
+         assert iterator.hasPrevious(); // should have previous as long as we are less than the number of elements.
+
+         Object previous = iterator.previous();
+
+         assert expectedValue == previous; // tests previous()
+      }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex() {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == 10; //Index will be the index of the last element + 1.
+
+   }
+
+   public void testPreviousIndex() {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == 8; //Index will be that of the last element - 1.
+   }
+
+}
+
+

Deleted: branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -1,349 +0,0 @@
-package org.infinispan.query;
-
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.search.IndexSearcher;
-import org.easymock.EasyMock;
-import static org.easymock.EasyMock.*;
-import org.easymock.IAnswer;
-import org.hibernate.search.engine.DocumentExtractor;
-import org.hibernate.search.engine.EntityInfo;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.infinispan.Cache;
-import org.infinispan.query.helper.IndexCleanUp;
-import org.infinispan.query.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * @author Navin Surtani
- */
- at Test(groups = "functional")
-public class LazyQueryResultIteratorTest 
-{
-   Cache <String, Person> cache;
-   LazyQueryResultIterator iterator = null;
-   int fetchSize = 1;
-   Person person1, person2, person3, person4, person5, person6, person7, person8, person9, person10;
-   StringBuilder builder;
-   Map<String, Person> dummyDataMap;
-   List<String> keyList;
-
-   @BeforeTest
-   public void setUpBeforeTest() throws Exception
-   {
-      dummyDataMap = new HashMap<String, Person>();
-
-      // Create a bunch of Person instances.
-      person1 = new Person();
-      person2 = new Person();
-      person3 = new Person();
-      person4 = new Person();
-      person5 = new Person();
-      person6 = new Person();
-      person7 = new Person();
-      person8 = new Person();
-      person9 = new Person();
-      person10 = new Person();
-
-
-      // Set the fields to something so that everything will be found.
-      person1.setBlurb("cat");
-      person2.setBlurb("cat");
-      person3.setBlurb("cat");
-      person4.setBlurb("cat");
-      person5.setBlurb("cat");
-      person6.setBlurb("cat");
-      person7.setBlurb("cat");
-      person8.setBlurb("cat");
-      person9.setBlurb("cat");
-      person10.setBlurb("cat");
-
-      // Stick them all into a dummy map.
-      dummyDataMap.put("key1", person1);
-      dummyDataMap.put("key2", person2);
-      dummyDataMap.put("key3", person3);
-      dummyDataMap.put("key4", person4);
-      dummyDataMap.put("key5", person5);
-      dummyDataMap.put("key6", person6);
-      dummyDataMap.put("key7", person7);
-      dummyDataMap.put("key8", person8);
-      dummyDataMap.put("key9", person9);
-      dummyDataMap.put("key10", person10);
-
-      keyList = new ArrayList<String>();
-
-      keyList.add("key1");
-      keyList.add("key2");
-      keyList.add("key3");
-      keyList.add("key4");
-      keyList.add("key5");
-      keyList.add("key6");
-      keyList.add("key7");
-      keyList.add("key8");
-      keyList.add("key9");
-      keyList.add("key10");
-
-
-   }
-
-   @AfterTest
-   public void tearDownAfterTest()
-   {
-      IndexCleanUp.cleanUpIndexes();
-   }
-
-   @BeforeMethod
-   public void setUp() throws ParseException
-   {
-
-      // Setting up the cache mock instance
-      cache = createMock(Cache.class);
-
-      expect(cache.get(anyObject())).andAnswer(new IAnswer<Person>(){
-
-         public Person answer() throws Throwable {
-            String key = getCurrentArguments()[0].toString();
-            return dummyDataMap.get(key);
-         }
-      }).anyTimes();
-
-
-      // Create mock instances of other things required to create a lazy iterator.
-
-      SearchFactoryImplementor searchFactory = createMock(SearchFactoryImplementor.class);
-
-      DocumentExtractor extractor = org.easymock.classextension.EasyMock.createMock(DocumentExtractor.class);
-
-
-      try {
-         org.easymock.classextension.EasyMock.expect(extractor.extract(anyInt())).andAnswer(new IAnswer<EntityInfo>(){
-
-            public EntityInfo answer() throws Throwable {
-               int index = (Integer) getCurrentArguments()[0];
-               String keyString = keyList.get(index);
-
-               System.out.println("The key for index parameter " + index + " is " + keyString);
-
-               return new EntityInfo(Person.class, keyString, null);
-            }
-         }).anyTimes();
-
-
-      } catch (IOException e) {
-         e.printStackTrace();
-      }
-      IndexSearcher searcher = org.easymock.classextension.EasyMock.createMock(IndexSearcher.class);
-
-      EasyMock.replay(cache, searchFactory);
-      org.easymock.classextension.EasyMock.replay(searcher, extractor);
-
-      iterator = new LazyQueryResultIterator(extractor, cache, searcher, searchFactory, 0, 9, fetchSize);
-
-   }
-
-
-   @AfterMethod
-   public void tearDown()
-   {
-      iterator = null;
-   }
-
-   public void testJumpToResult() throws IndexOutOfBoundsException
-   {
-      iterator.jumpToResult(0);
-      assert iterator.isFirst();
-
-      iterator.jumpToResult(1);
-      assert iterator.isAfterFirst();
-
-      iterator.jumpToResult(9);
-      assert iterator.isLast();
-
-      iterator.jumpToResult(8);
-      assert iterator.isBeforeLast();
-   }
-
-   public void testFirst()
-   {
-      assert iterator.isFirst() : "We should be pointing at the first element";
-      Object next = iterator.next();
-
-      System.out.println(next);
-      assert next == person1;
-      assert !iterator.isFirst();
-
-      iterator.first();
-
-      assert iterator.isFirst() : "We should be pointing at the first element";
-      next = iterator.next();
-      assert next == person1;
-      assert !iterator.isFirst();
-
-   }
-
-   public void testLast()
-   {
-      //Jumps to the last element
-      iterator.last();
-
-      //Makes sure that the iterator is pointing at the last element.
-      assert iterator.isLast();
-
-      iterator.first();
-
-      //Check that the iterator is NOT pointing at the last element.
-      assert !iterator.isLast();
-   }
-
-   public void testAfterFirst()
-   {
-      //Jump to the second element.
-      iterator.afterFirst();
-
-      //Check this
-      assert iterator.isAfterFirst();
-
-      //Previous element in the list
-      Object previous = iterator.previous();
-
-      //Check that previous is the first element.
-      assert previous == person2;
-
-      //Make sure that the iterator isn't pointing at the second element.
-      assert !iterator.isAfterFirst();
-
-   }
-
-   public void testBeforeLast()
-   {
-      //Jump to the penultimate element.
-      iterator.beforeLast();
-
-      //Check this
-      assert iterator.isBeforeLast();
-
-      //Next element - which should be the last.
-      Object next = iterator.next();
-
-      //Check that next is the penultimate element.
-      assert next == person9;
-
-      //Make sure that the iterator is not pointing at the penultimate element.
-      assert !iterator.isBeforeLast();
-   }
-
-   public void testIsFirst()
-   {
-      iterator.first();
-      assert iterator.isFirst();
-
-      iterator.next();
-      assert !iterator.isFirst();
-   }
-
-   public void testIsLast()
-   {
-      iterator.last();
-      assert iterator.isLast();
-
-      iterator.previous();
-      assert !iterator.isLast();
-   }
-
-   public void testIsAfterFirst()
-   {
-      iterator.afterFirst();
-      assert iterator.isAfterFirst();
-
-      iterator.previous();
-      assert !iterator.isAfterFirst();
-   }
-
-   public void testIsBeforeLast()
-   {
-      iterator.beforeLast();
-      assert iterator.isBeforeLast();
-   }
-
-   public void testNextAndHasNext()
-   {
-      iterator.first();
-
-      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
-      builder = new StringBuilder();
-
-      for (int i = 1; i <= 10; i++)
-      {
-         builder.delete(0, 4);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
-         builder.append("key");
-         builder.append(i);
-         String keyString = builder.toString();
-         Object expectedValue = cache.get(keyString);
-         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
-
-         Object next = iterator.next();
-
-         assert expectedValue == next; // tests next()
-     }
-      assert !iterator.hasNext(); // this should now NOT be true.
-   }
-
-   public void testPreviousAndHasPrevious()
-   {
-      iterator.last();
-
-      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
-      builder = new StringBuilder();      
-
-      for (int i = 10; i >= 1; i--)
-      {
-         builder.delete(0, 5);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
-         builder.append("key");
-         builder.append(i);
-         String keyString = builder.toString();
-
-
-         Object expectedValue = cache.get(keyString);
-
-         assert iterator.hasPrevious(); // should have previous as long as we are less than the number of elements.
-
-         Object previous = iterator.previous();
-
-         assert expectedValue == previous; // tests previous()
-     }
-      assert !iterator.hasPrevious(); // this should now NOT be true.
-
-   }
-
-   public void testNextIndex()
-   {
-      iterator.first();
-      assert iterator.nextIndex() == 1;
-
-      iterator.last();
-      assert iterator.nextIndex() == 10; //Index will be the index of the last element + 1.
-
-   }
-
-   public void testPreviousIndex()
-   {
-      iterator.first();
-      assert iterator.previousIndex() == -1;
-
-      iterator.last();
-      assert iterator.previousIndex() == 8; //Index will be that of the last element - 1.
-   }
-
-}
-
-

Deleted: branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -1,220 +0,0 @@
-package org.infinispan.query;
-
-import org.easymock.EasyMock;
-import static org.easymock.EasyMock.*;
-import org.easymock.IAnswer;
-import org.infinispan.Cache;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Navin Surtani
- *         <p/>
- *         Test class for the QueryResultIteratorImpl
- */
-
- at Test(groups = "functional")
-public class QueryResultIteratorImplTest {
-   List<Object> keys;
-   Map<String, String> dummyResults;
-   QueryResultIterator iterator;
-   int fetchSize = 1;
-   Cache<String, String> cache;
-
-   @BeforeMethod
-   public void setUp() throws Exception {
-
-      // create a set of dummy keys
-      keys = new ArrayList<Object>();
-      // create some dummy data
-      dummyResults = new HashMap<String, String>();
-
-      for (int i=1; i<=10; i++) {
-         String key = "key" + i;
-         keys.add(key);
-         dummyResults.put(key, "Result number " + i);
-      }
-
-      // create the instance of the iterator.
-      cache = createMock(Cache.class);
-
-      expect(cache.get(anyObject())).andAnswer(new IAnswer<String>(){
-         public String answer() throws Throwable {
-            String k = getCurrentArguments()[0].toString();
-            return dummyResults.get(k);
-         }
-      }).anyTimes();
-
-      iterator = new QueryResultIteratorImpl(keys, cache, fetchSize);
-      EasyMock.replay(cache);
-   }
-
-   @AfterMethod
-   public void tearDown() {
-      keys = null;
-      dummyResults = null;
-      iterator = null;
-   }
-
-   public void testJumpToResult() throws IndexOutOfBoundsException {
-      iterator.jumpToResult(0);
-      assert iterator.isFirst();
-
-      iterator.jumpToResult(1);
-      assert iterator.isAfterFirst();
-
-      iterator.jumpToResult((keys.size() - 1));
-      assert iterator.isLast();
-
-      iterator.jumpToResult(keys.size() - 2);
-      assert iterator.isBeforeLast();
-   }
-
-   public void testFirst() {
-      assert iterator.isFirst() : "We should be pointing at the first element";
-      Object next = iterator.next();
-      System.out.println(next);
-
-      assert next == dummyResults.get(keys.get(0));
-
-      assert !iterator.isFirst();
-
-      iterator.first();
-
-      assert iterator.isFirst() : "We should be pointing at the first element";
-      next = iterator.next();
-      assert next == dummyResults.get(keys.get(0));
-      assert !iterator.isFirst();
-
-   }
-
-   public void testLast() {
-      //Jumps to the last element
-      iterator.last();
-
-      //Makes sure that the iterator is pointing at the last element.
-      assert iterator.isLast();
-
-      Object next = iterator.next();
-
-      //Returns the size of the list of keys.
-      int size = keys.size();
-
-      //Makes sure that previous is the last element.
-      assert next == dummyResults.get(keys.get(size - 1));
-
-      //Check that the iterator is NOT pointing at the last element.
-      assert !iterator.isLast();
-   }
-
-   public void testAfterFirst() {
-      //Jump to the second element.
-      iterator.afterFirst();
-
-      //Check this
-      assert iterator.isAfterFirst();
-
-      //Previous element in the list
-      Object previous = iterator.previous();
-
-      //Check that previous is the first element.
-      assert previous == dummyResults.get(keys.get(1));
-
-      //Make sure that the iterator isn't pointing at the second element.
-      assert !iterator.isAfterFirst();
-
-   }
-
-   public void testBeforeLast() {
-      //Jump to the penultimate element.
-      iterator.beforeLast();
-
-      //Check this
-      assert iterator.isBeforeLast();
-
-      //Next element - which should be the last.
-      Object next = iterator.next();
-
-      //Check that next is the penultimate element.
-      int size = keys.size();
-      assert next == dummyResults.get(keys.get(size - 2));
-
-      //Make sure that the iterator is not pointing at the penultimate element.
-      assert !iterator.isBeforeLast();
-   }
-
-   public void testIsFirst() {
-      iterator.first();
-      assert iterator.isFirst();
-
-      iterator.next();
-      assert !iterator.isFirst();
-   }
-
-   public void testIsLast() {
-      iterator.last();
-      assert iterator.isLast();
-
-      iterator.previous();
-      assert !iterator.isLast();
-   }
-
-   public void testIsAfterFirst() {
-      iterator.afterFirst();
-      assert iterator.isAfterFirst();
-
-      iterator.previous();
-      assert !iterator.isAfterFirst();
-   }
-
-   public void testIsBeforeLast() {
-      iterator.beforeLast();
-      assert iterator.isBeforeLast();
-   }
-
-   public void testNextAndHasNext() {
-      iterator.first();
-      for (int i = 0; i < keys.size(); i++) {
-         System.out.println("Loop number count: - " + (i + 1));
-         Object expectedValue = dummyResults.get(keys.get(i));
-         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
-         assert expectedValue == iterator.next(); // tests next()
-      }
-      assert !iterator.hasNext(); // this should now NOT be true.
-   }
-
-   public void testPreviousAndHasPrevious() {
-      iterator.last();
-      for (int i = keys.size() - 1; i >= 0; i--) {
-         Object expectedValue = dummyResults.get(keys.get(i));
-         assert iterator.hasPrevious(); // should have previous as long as we are more than the number of elements.
-         assert expectedValue == iterator.previous(); // tests previous()
-      }
-      assert !iterator.hasPrevious(); // this should now NOT be true.
-
-   }
-
-   public void testNextIndex() {
-      iterator.first();
-      assert iterator.nextIndex() == 1;
-
-      iterator.last();
-      assert iterator.nextIndex() == keys.size();
-
-   }
-
-   public void testPreviousIndex() {
-      iterator.first();
-      assert iterator.previousIndex() == -1;
-
-      iterator.last();
-      assert iterator.previousIndex() == (keys.size() - 2);
-   }
-
-}

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -12,7 +12,7 @@
 import org.infinispan.manager.CacheManager;
 import org.infinispan.manager.DefaultCacheManager;
 import org.infinispan.query.CacheQuery;
-import org.infinispan.query.QueryResultIterator;
+import org.infinispan.query.QueryIterator;
 import org.infinispan.query.SearchableCache;
 import org.infinispan.query.SearchableCacheFactory;
 import org.infinispan.query.helper.IndexCleanUp;
@@ -102,7 +102,7 @@
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
 
-      QueryResultIterator found = cacheQuery.iterator();
+      QueryIterator found = cacheQuery.iterator();
 
       assert found.isFirst();
       assert found.isLast();

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-08-13 15:33:47 UTC (rev 674)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-08-13 15:41:23 UTC (rev 675)
@@ -13,7 +13,7 @@
 import org.infinispan.config.Configuration;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.query.CacheQuery;
-import org.infinispan.query.QueryResultIterator;
+import org.infinispan.query.QueryIterator;
 import org.infinispan.query.SearchableCache;
 import org.infinispan.query.SearchableCacheFactory;
 import org.infinispan.query.helper.IndexCleanUp;
@@ -112,7 +112,7 @@
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
 
-      QueryResultIterator found = cacheQuery.iterator();
+      QueryIterator found = cacheQuery.iterator();
 
       assert found.isFirst();
       assert found.isLast();
@@ -261,7 +261,7 @@
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
 
-      QueryResultIterator found = cacheQuery.lazyIterator();
+      QueryIterator found = cacheQuery.lazyIterator();
 
       assert found.isFirst();
       assert found.isLast();



More information about the infinispan-commits mailing list