Author: navssurtani
Date: 2008-06-30 08:34:18 -0400 (Mon, 30 Jun 2008)
New Revision: 6121
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredPOJOCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
Removed:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java
searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
Modified:
searchable/trunk/pom.xml
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Javadocced stuff + black-box
Modified: searchable/trunk/pom.xml
===================================================================
--- searchable/trunk/pom.xml 2008-06-30 11:58:59 UTC (rev 6120)
+++ searchable/trunk/pom.xml 2008-06-30 12:34:18 UTC (rev 6121)
@@ -27,10 +27,16 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.2.0.CR4</version>
+ <version>2.2.0.CR5</version>
</dependency>
<dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-pojo</artifactId>
+ <version>2.2.0.CR5</version>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate.sandbox</groupId>
<artifactId>hibernate-search-gsoc</artifactId>
<version>3.1.0-SNAPSHOT</version>
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -3,6 +3,9 @@
import org.jboss.cache.Fqn;
/**
+ *
+ * This class is used to get fqns, keys and documentId's by calling methods on {@link
org.jboss.cache.search.Transformer}
+ *
@author Navin Surtani - navin(a)surtani.org
*/
public class CacheEntityId
@@ -22,6 +25,12 @@
this.key = key;
}
+ /**
+ * Gets the Fqn from the instance of CacheEntityId.
+ *
+ * @return Fqn from the instance of CacheEntityId.
+ */
+
public Fqn getFqn()
{
if (fqn != null) return fqn;
@@ -33,6 +42,12 @@
throw new IllegalArgumentException("At least fqn or documentId must be set to
call this method");
}
+ /**
+ * Gets the key from the instance of CacheEntityId.
+ *
+ * @return Key from the instance of CacheEntityId.
+ */
+
public String getKey()
{
if (key != null) return key;
@@ -45,6 +60,13 @@
throw new IllegalArgumentException("At least key or documentId must be set to
call this method");
}
+ /**
+ * Gets a documentId String from an Fqn and key combination.
+ *
+ * @return documentId String.
+ */
+
+
public String getDocumentId()
{
if (key != null || fqn != null)
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -6,6 +6,8 @@
import java.util.ArrayList;
/**
+ * Class that is used to load objects from a list of CacheEntityId ids.
+ *
* @author Navin Surtani - navin(a)surtani.org
*/
public class CacheEntityLoader
@@ -19,8 +21,9 @@
/**
* Takes a list of entity ids and gets them from the cache.
- * @param ids
- * @return
+ * @param ids list of cache entity IDs. Cannot be null.
+ * @return List of objects loaded from the cache. The list returned will be exactly
the same size as the ids list passed in.
+ * @throws NullPointerException if ids is null.
*/
public List<Object> load(List<CacheEntityId> ids)
{
@@ -35,8 +38,9 @@
/**
* Takes a list of entity ids and gets them from the cache.
- * @param id
- * @return
+ * @param id cache entity id to look up in the cache.
+ * @return the object from the cache, or null if one cannot be found.
+ * @throws NullPointerException if ids is null.
*/
public Object load(CacheEntityId id)
{
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -9,20 +9,64 @@
* as list, setFirstResult,setMaxResults, setFetchSize, getResultSize and setSort.
*
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @see
org.jboss.cache.search.SearchableCache#createQuery(org.apache.lucene.search.Query)
*/
public interface CacheQuery
{
+ /**
+ * Returns the results of a search as a list.
+ *
+ * @return list of objects that were found from the search.
+ */
+
List<Object> list();
+ /**
+ * Returns the results of a search as a {@link QueryResultIterator}.
+ *
+ * @return a QueryResultIterator which can be used to iterate through the results that
were found.
+ */
+
QueryResultIterator iterator();
+ /**
+ * Sets a result with a given index to the first result.
+ *
+ * @param index of result to be set to the first.
+ * @throws IllegalArgumentException if the index given is less than zero.
+ */
+
void setFirstResult(int index);
+ /**
+ * Sets the maximum number of results to the number passed in as a parameter.
+ *
+ * @param numResults that are to be set to the maxResults.
+ */
+
void setMaxResults(int numResults);
+ /**
+ * Defines scrollable result fetch size
+ *
+ * @param size to be set
+ */
+
void setFetchSize(int size);
+ /**
+ * Gets the integer number of results.
+ *
+ * @return integer number of results.
+ */
+
int getResultSize();
+ /**
+ * Allows lucene to sort the results.
+ *
+ * @param s - lucene sort object
+ */
+
void setSort(Sort s);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -34,9 +34,9 @@
import java.util.Set;
/**
+ * Implementation class of the CacheQuery interface.
+ * <p />
* @author Navin Surtani - navin(a)surtani.org
- * <p/>
- * Implementation class of the FullTextQuery interface in Hibernate Search.
*/
public class CacheQueryImpl implements CacheQuery
{
@@ -138,8 +138,8 @@
/**
* Enable a given filter by its name.
*
- * @param name
- * @return
+ * @param name of filter.
+ * @return a FullTextFilter object.
*/
public FullTextFilter enableFullTextFilter(String name)
{
@@ -164,7 +164,7 @@
/**
* Disable a given filter by its name.
*
- * @param name
+ * @param name of filter.
*/
public void disableFullTextFilter(String name)
{
@@ -174,8 +174,8 @@
/**
* Sets the the result of the given integer value to the first result.
*
- * @param firstResult
- * @return
+ * @param firstResult index to be set.
+ * @throws IllegalArgumentException if the index given is less than zero.
*/
public void setFirstResult(int firstResult)
{
@@ -184,8 +184,11 @@
throw new IllegalArgumentException("'first' pagination parameter
less than 0");
}
this.firstResult = firstResult;
+
+ //TODO How do we deal with this if the parameter is too high.
}
+
public QueryResultIterator iterator() throws HibernateException
{
List<CacheEntityId> ids = null;
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -3,8 +3,7 @@
import org.jboss.cache.CacheException;
/**
- *
- * Thrown when an invalid Fqn is passed into the generateId method in Transformer
+ * Thrown when an invalid Fqn is passed into {@link
org.jboss.cache.search.Transformer#generateId(org.jboss.cache.Fqn, String)}
* <p />
*
* @author Navin Surtani - navin(a)surtani.org
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -7,20 +7,28 @@
import javax.transaction.Transaction;
/**
- * This class implements the TransactionContext interface in the
org.hibernate.search.transaction package. It
- * retrieves transaction context information from the NodeModifiedEvent that gets passed
in.
+ * This class implements the {@link org.hibernate.search.transaction.TransactionContext}
interface. It
+ * retrieves transaction context information from the {@link
org.jboss.cache.notifications.event.NodeModifiedEvent} that gets passed in.
* <p />
- * It is used by the SearchableListener to pass in transaction information to a Hibernate
Search Work object.
+ * It is used by the {@link org.jboss.cache.search.SearchableListener} to pass
transaction information to a Hibernate Search {@link org.hibernate.search.backend.Work}
object.
* <p />
* @author Navin Surtani - navin(a)surtani.org
+ * @see org.jboss.cache.search.SearchableListener
*/
public class NodeModifiedTransactionContext implements TransactionContext
{
NodeModifiedEvent event;
+ /**
+ * Creates a new instance of NodeModifiedTransactionContext.
+ * <p />
+ * @param event a NodeModifiedEvent to wrap. Should not be null.
+ * @throws NullPointerException if event is null.
+ */
public NodeModifiedTransactionContext(NodeModifiedEvent event)
{
+ if (event == null) throw new NullPointerException("event cannot be
null");
this.event = event;
}
@@ -46,20 +54,27 @@
}
/**
- * Registers a synchronization from one passed as a parameter.
- *
- * @param synchronization
+ * Registers the synchronization passed in as a parameter with the ongoing
transaction.
+ * <p />
+ * If there is no ongoing transaction, then this method will do nothing and simply
return.
+ * <p />
+ * @param synchronization synchronization to register. Must not be null.
+ * @throws NullPointerException if the synchronization is null.
*/
public void registerSynchronization(Synchronization synchronization)
{
Transaction transaction = event.getTransaction();
- try
+ if (transaction != null)
{
- transaction.registerSynchronization(synchronization);
+ if (synchronization == null) throw new
NullPointerException("Synchronization passed in is null!");
+ try
+ {
+ transaction.registerSynchronization(synchronization);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
}
}
Deleted: searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -1,61 +0,0 @@
-package org.jboss.cache.search;
-
-import org.hibernate.search.engine.EntityInfo;
-import org.hibernate.search.engine.Loader;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * @author Navin Surtani - navin(a)surtani.org
- */
-public class SearchResultIterator implements Iterator
-{
- protected final List<CacheEntityId> entityIds;
- protected int index = 0;
- protected final int size;
- protected Object next;
- protected int nextObjectIndex = -1;
- protected final CacheEntityLoader loader;
-
- public SearchResultIterator(List<CacheEntityId> entityIds, CacheEntityLoader
loader) {
- this.entityIds = entityIds;
- this.size = entityIds.size();
- this.loader = loader;
- }
-
- //side effect is to set up next
- public boolean hasNext() {
- if ( nextObjectIndex == index ) return next != null;
- next = null;
- nextObjectIndex = -1;
- do {
- if ( index >= size ) {
- nextObjectIndex = index;
- next = null;
- return false;
- }
- next = loader.load( entityIds.get( index ) );
- if ( next == null ) {
- index++;
- }
- else {
- nextObjectIndex = index;
- }
- }
- while ( next == null );
- return true;
- }
-
- public Object next() {
- //hasNext() has side effect
- if ( !hasNext() ) throw new NoSuchElementException( "Out of boundaries" );
- index++;
- return next;
- }
-
- public void remove() {
- throw new UnsupportedOperationException( "Cannot remove from a lucene query
iterator" );
- }
-}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -17,17 +17,17 @@
/**
* Creates a CacheQuery object from a luceneQuery.
*
- * @param luceneQuery
- * @return
+ * @param luceneQuery - from {@link org.apache.lucene.search.Query}
+ * @return a CacheQuery instance from which the user can get a list/iterator object.
*/
public CacheQuery createQuery(Query luceneQuery);
/**
* Creates a CacheQuery from a lucene query and a class array.
*
- * @param luceneQuery
- * @param classes
- * @return
+ * @param classes - array of classes to be searched from.
+ * @param luceneQuery - from {@link org.apache.lucene.search.Query}
+ * @return a CacheQuery instance from which the user can get a list/iterator object.
*/
public CacheQuery createQuery(Query luceneQuery, Class... classes);
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -34,6 +34,8 @@
//TODO: javadoc!!
public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImpl searchFactory)
{
+ if (cache == null) throw new NullPointerException("Blah");
+ if (searchFactory == null) throw new NullPointerException("Blah");
this.cache = cache;
this.searchFactory = searchFactory;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-30
11:58:59 UTC (rev 6120)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -25,7 +25,7 @@
* Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the
NodeModifiedEvent class.
*
*
- * @param event
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
*/
@@ -51,7 +51,7 @@
* If the modification type is PUT_MAP or PUT_DATA then this method will be called.
* Takes in the event as a parameter
*
- * @param event
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
*/
void handlePutData(NodeModifiedEvent event)
{
@@ -73,7 +73,7 @@
* If the modification type is DELETE_DATA then this method will be called.
* Takes in the event as a parameter
*
- * @param event
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
*/
void handleDeleteData(NodeModifiedEvent event)
{
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -18,8 +18,8 @@
* Takes in the documentId string from the user and will return the key from the Fqn,
key combination.
*
*
- * @param docId
- * @return
+ * @param docId - for the keystring to be obtained
+ * @return keystring.
*/
public static String getKey(String docId)
@@ -45,8 +45,8 @@
/**
* Takes in the documentId string from the user and will return the Fqn from the Fqn,
key combination.
*
- * @param docId
- * @return
+ * @param docId - for the Fqn to be obtained
+ * @return Fqn from the documentId.
*/
@@ -74,7 +74,7 @@
*
* @param fqn
* @param key
- * @return
+ * @return documentId String to be given to Lucene.
* @throws InvalidFqnException
*/
Deleted: searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-30
11:58:59 UTC (rev 6120)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -1,129 +0,0 @@
-package org.jboss.cache.search;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.search.test.Person;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-/**
- * @author Navin Surtani - navin(a)surtani.org
- */
-@Test
-public class BlackBoxTest
-{
- public void doTest() throws ParseException
- {
- Cache cache = new DefaultCacheFactory().createCache();
- SearchableCache sc = new SearchableCacheFactory().createSearchableCache(cache,
Person.class);
-
- Person p1 = new Person();
- p1.setName("Navin Surtani");
- p1.setBlurb("Likes playing WoW");
-
- Person p2 = new Person();
- p2.setName("BigGoat");
- p2.setName("Eats grass");
-
- Person p3 = new Person();
- p3.setName("MiniGoat");
- p3.setBlurb("Makes cheese");
-
- //Put the 3 created objects in the cache.
-
- sc.put(Fqn.fromString("/a/b/c"), "Navin", p1);
- sc.put(Fqn.fromString("/a/b/d"), "BigGoat", p2);
- sc.put(Fqn.fromString("/a/b/c"), "MiniGoat", p3);
-
-
- QueryParser qp = new QueryParser("field", new StandardAnalyzer());
- Query luceneQuery = qp.parse("playing");
- CacheQuery query = sc.createQuery(luceneQuery);
-
- List found = query.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(p1);
-
- sc.remove("/a/b/c", "Navin");
-
- query = sc.createQuery(luceneQuery);
-
- found = query.list();
-
- assert found.size() == 0;
-
- sc.put(Fqn.fromString("/a/b/c"), "Navin", p1);
-
- luceneQuery = qp.parse("Goat");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert found.size() == 2;
- assert !found.get(1).equals(p2);
- assert !found.get(0).equals(p3);
-
- luceneQuery = qp.parse("/a/b/c");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert found.size() == 2;
-
- for (int i = 0; i < found.size(); i++)
- {
- assert !found.get(i).equals(p2);
- }
-
- p1.setBlurb("Likes pizza");
-
- luceneQuery = qp.parse("pizza");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(p1);
-
- Cache cache2 = new DefaultCacheFactory().createCache();
- SearchableCache sc2 = new SearchableCacheFactory().createSearchableCache(cache2,
Person.class);
-
- Person p4 = new Person();
-
- p4.setName("Ralph Nader");
- p4.setBlurb("Runs for president");
-
- sc2.put(Fqn.fromString("/u/s/a"), "Ralph", p4);
-
- luceneQuery = qp.parse("president");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert found.size() == 1;
-
- p4.setBlurb("Makes cheese");
-
- sc2.put(Fqn.fromString("/u/s/a"), "Ralph", p4);
-
- luceneQuery = qp.parse("Makes cheese");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert found.size() == 2;
-
- sc2.remove("/u/s/a", "Ralph");
-
- luceneQuery = qp.parse("Makes cheese");
- query = sc.createQuery(luceneQuery);
- found = query.list();
-
- assert !found.contains(p4);
-
- // TODO: Test stuff with PojoCache. Put stuff in PojoCache (using cache.attach())
and see if you can find stuff.
-
- }
-}
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
(rev 0)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -0,0 +1,167 @@
+package org.jboss.cache.search.blackbox;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+@Test
+public class ClusteredCacheTest
+{
+ Cache cache1, cache2;
+ SearchableCache searchableCache1, searchableCache2;
+ Person person1;
+ Person person2;
+ Person person3;
+ Person person4;
+ QueryParser queryParser;
+ Query luceneQuery;
+ CacheQuery cacheQuery;
+ List found;
+
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache1 = new DefaultCacheFactory().createCache();
+ searchableCache1 = new SearchableCacheFactory().createSearchableCache(cache1,
Person.class);
+
+ cache2 = new DefaultCacheFactory().createCache();
+ searchableCache2 = new SearchableCacheFactory().createSearchableCache(cache2,
Person.class);
+
+ person1 = new Person();
+ person1.setName("Navin Surtani");
+ person1.setBlurb("Likes playing WoW");
+
+ person2 = new Person();
+ person2.setName("BigGoat");
+ person2.setName("Eats grass");
+
+ person3 = new Person();
+ person3.setName("MiniGoat");
+ person3.setBlurb("Makes cheese");
+
+ //Put the 3 created objects in the searchableCache1.
+
+ searchableCache1.put(Fqn.fromString("/a/b/c"), "Navin",
person1);
+ searchableCache1.put(Fqn.fromString("/a/b/d"), "BigGoat",
person2);
+ searchableCache1.put(Fqn.fromString("/a/b/c"), "MiniGoat",
person3);
+
+
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (searchableCache1 != null) searchableCache1.stop();
+ if (searchableCache2 != null) searchableCache2.stop();
+
+ }
+
+ public void testSimple() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+
+ }
+
+ public void testModified() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+
+ person1.setBlurb("Likes pizza");
+ searchableCache1.put(Fqn.fromString("/a/b/c/"), "Navin",
person1);
+
+
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+ }
+
+ public void testAdded() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2 : "Size of list should be 2";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert !found.contains(person4) : "This should not contain object
person4";
+
+ person4.setName("MightyGoat");
+ person4.setBlurb("Also eats grass");
+
+ searchableCache1.put(Fqn.fromString("/r/a/m/"), "Ram",
person4);
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 3 : "Size of list should be 3";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert found.contains(person4) : "This should now contain object
person4";
+ }
+
+ public void testRemoved() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert found.contains(person2);
+ assert found.contains(person3) : "This should still contain object
person3";
+
+ searchableCache1.remove(Fqn.fromString("/a/b/c/"), person3);
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache2.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.contains(person2);
+ assert !found.contains(person3) : "The search should not return
person3";
+
+
+ }
+
+
+}
+
+
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredPOJOCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredPOJOCacheTest.java
(rev 0)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredPOJOCacheTest.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -0,0 +1,8 @@
+package org.jboss.cache.search.blackbox;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class ClusteredPOJOCacheTest
+{
+}
Added: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
(rev 0)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -0,0 +1,166 @@
+package org.jboss.cache.search.blackbox;
+
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.test.Person;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.search.Query;
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+
+@Test
+public class LocalCacheTest
+{
+ SearchableCache searchableCache;
+ Person person1;
+ Person person2;
+ Person person3;
+ Person person4;
+ QueryParser queryParser;
+ Query luceneQuery;
+ CacheQuery cacheQuery;
+ List found;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ Cache coreCache = new DefaultCacheFactory().createCache();
+ searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache,
Person.class);
+
+ person1 = new Person();
+ person1.setName("Navin Surtani");
+ person1.setBlurb("Likes playing WoW");
+
+ person2 = new Person();
+ person2.setName("BigGoat");
+ person2.setName("Eats grass");
+
+ person3 = new Person();
+ person3.setName("MiniGoat");
+ person3.setBlurb("Makes cheese");
+
+ //Put the 3 created objects in the searchableCache.
+
+ searchableCache.put(Fqn.fromString("/a/b/c"), "Navin",
person1);
+ searchableCache.put(Fqn.fromString("/a/b/d"), "BigGoat",
person2);
+ searchableCache.put(Fqn.fromString("/a/b/c"), "MiniGoat",
person3);
+
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (searchableCache != null) searchableCache.stop();
+ }
+
+ public void testSimple() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+ }
+
+ public void testMultipleResults() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert !found.get(1).equals(person2);
+ assert !found.get(0).equals(person3);
+
+ }
+
+ public void testModified() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+
+ person1.setBlurb("Likes pizza");
+ searchableCache.put(Fqn.fromString("/a/b/c/"), "Navin",
person1);
+
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("pizza");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+ }
+
+ public void testAdded() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2: "Size of list should be 2";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert !found.contains(person4) : "This should not contain object
person4";
+
+ person4.setName("MightyGoat");
+ person4.setBlurb("Also eats grass");
+
+ searchableCache.put(Fqn.fromString("/r/a/m/"), "Ram",
person4);
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 3: "Size of list should be 3";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert found.contains(person4) : "This should now contain object
person4";
+ }
+
+ public void testRemoved() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert found.contains(person2);
+ assert found.contains(person3): "This should still contain object
person3";
+
+ searchableCache.remove(Fqn.fromString("/a/b/c/"), person3);
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.contains(person2);
+ assert !found.contains(person3): "The search should not return person3";
+
+
+ }
+
+}
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
(rev 0)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-06-30
12:34:18 UTC (rev 6121)
@@ -0,0 +1,181 @@
+package org.jboss.cache.search.blackbox;
+
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.test.Person;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+
+import java.util.List;
+
+/**
+ * Same as LocalCacheTest except that you will use a POJO Cache instead and use
pojoCache.attach() ad pojoCache.detach()
+ * instead of cache.put() and cache.remove().
+ * <p />
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+
+@Test
+public class LocalPOJOCacheTest
+{
+ SearchableCache searchableCache;
+ PojoCache pojo;
+ Person person1;
+ Person person2;
+ Person person3;
+ Person person4;
+ QueryParser queryParser;
+ Query luceneQuery;
+ CacheQuery cacheQuery;
+ List found;
+
+
+ @BeforeMethod
+ public void setUp()
+ {
+ Configuration config = new Configuration();
+ PojoCache pojo = PojoCacheFactory.createCache(config, true);
+ Cache coreCache = new DefaultCacheFactory().createCache();
+ searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache,
Person.class);
+
+ person1 = new Person();
+ person1.setName("Navin Surtani");
+ person1.setBlurb("Likes playing WoW");
+
+ person2 = new Person();
+ person2.setName("BigGoat");
+ person2.setName("Eats grass");
+
+ person3 = new Person();
+ person3.setName("MiniGoat");
+ person3.setBlurb("Makes cheese");
+
+ pojo.attach(Fqn.fromString("/a/b/c"), person1);
+ pojo.attach(Fqn.fromString("/a/b/d"), person2);
+ pojo.attach(Fqn.fromString("/a/b/c"), person3);
+
+
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+
+ if(pojo != null) pojo.stop();
+ if(searchableCache != null) searchableCache.stop();
+ }
+
+ public void testSimple() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+ }
+
+ public void testMultipleResults() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert !found.get(1).equals(person2);
+ assert !found.get(0).equals(person3);
+
+ }
+
+ public void testModified() throws ParseException
+ {
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("playing");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+
+ person1.setBlurb("Likes pizza");
+
+ pojo.attach(Fqn.fromString("/a/b/c/"), person1);
+
+ queryParser = new QueryParser("field", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("pizza");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(person1);
+ }
+
+ public void testAdded() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2: "Size of list should be 2";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert !found.contains(person4) : "This should not contain object
person4";
+
+ person4.setName("MightyGoat");
+ person4.setBlurb("Also eats grass");
+
+ pojo.attach(Fqn.fromString("/r/a/m/"), person4);
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 3: "Size of list should be 3";
+ assert found.contains(person2);
+ assert found.contains(person3);
+ assert found.contains(person4) : "This should now contain object
person4";
+ }
+
+ public void testRemoved() throws ParseException
+ {
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert found.contains(person2);
+ assert found.contains(person3): "This should still contain object
person3";
+
+ pojo.detach(Fqn.fromString("/a/b/c/"));
+
+ luceneQuery = queryParser.parse("Goat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.contains(person2);
+ assert !found.contains(person3): "The search should not return person3";
+
+
+ }
+
+}
+
+
+}