JBoss Cache SVN: r6791 - searchable/trunk/src/test/java/org/jboss/cache/search/blackbox.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-09-25 11:56:58 -0400 (Thu, 25 Sep 2008)
New Revision: 6791
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
Log:
Disabled POJO test
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-09-25 15:38:36 UTC (rev 6790)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-09-25 15:56:58 UTC (rev 6791)
@@ -31,7 +31,7 @@
* @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
*/
-@Test(groups = "functional", enabled = true)
+@Test(groups = "functional", enabled = false)
public class LocalPOJOCacheTest
{
SearchableCache searchableCache;
15 years, 7 months
JBoss Cache SVN: r6790 - in searchable/trunk/src: test/java/org/jboss/cache/search and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-09-25 11:38:36 -0400 (Thu, 25 Sep 2008)
New Revision: 6790
Modified:
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/LazyQueryResultIterator.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
searchable/trunk/src/test/java/org/jboss/cache/search/LazyQueryResultIteratorTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
Log:
Wrote up lazy iterator test ... Should release RC1
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -48,11 +48,22 @@
List<Object> list();
/**
- * Returns the results of a search as a {@link QueryResultIterator}.
+ * Returns the results of a search as a {@link QueryResultIterator} 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);
+
+ /**
+ * Returns the results of a search as a {@link QueryResultIterator}. 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();
/**
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -53,6 +53,7 @@
/**
* Implementation class of the CacheQuery interface.
* <p/>
+ *
* @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
*/
public class CacheQueryImpl implements CacheQuery
@@ -77,6 +78,7 @@
public CacheQueryImpl(Query luceneQuery, SearchFactoryImplementor searchFactory, Cache cache)
{
+
this.luceneQuery = luceneQuery;
// this.cache = cache;
entityLoader = new CacheEntityLoader(cache);
@@ -203,9 +205,13 @@
//TODO How do we deal with this if the parameter is too high.
}
-
public QueryResultIterator iterator() throws HibernateException
{
+ return iterator (1);
+ }
+
+ public QueryResultIterator iterator(int fetchSize) throws HibernateException
+ {
List<CacheEntityId> ids = null;
IndexSearcher searcher = buildSearcher(searchFactory);
if (searcher == null)
@@ -243,7 +249,7 @@
}
- return new QueryResultIteratorImpl(ids, entityLoader);
+ return new QueryResultIteratorImpl(ids, entityLoader, fetchSize);
}
public QueryResultIterator lazyIterator()
@@ -267,13 +273,15 @@
}
catch (IOException e)
{
- try {
- IndexSearcherCloser.closeSearcher( searcher, searchFactory.getReaderProvider() );
+ try
+ {
+ IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
}
- catch (SearchException ee) {
+ catch (SearchException ee)
+ {
//we have the initial issue already
}
- throw new HibernateException( "Unable to query Lucene index", e );
+ throw new HibernateException("Unable to query Lucene index", e);
}
@@ -356,7 +364,7 @@
}
this.maxResults = maxResults;
}
-
+
private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor)
{
Map<Class, DocumentBuilder<Object>> builders = searchFactoryImplementor.getDocumentBuilders();
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -50,7 +50,7 @@
private Hits hits;
private IndexSearcher searcher;
private SearchFactoryImplementor searchFactory;
- private Object[] buffer;
+ Object[] buffer;
public LazyQueryResultIterator(DocumentExtractor extractor, CacheEntityLoader entityLoader, Hits hits,
IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max, int fetchSize)
@@ -71,7 +71,7 @@
this.searchFactory = searchFactory;
//Create an buffer with size fetchSize (which is the size of the required buffer.
- buffer = new Object[fetchSize];
+ buffer = new Object[this.fetchSize];
}
public void jumpToResult(int index) throws IndexOutOfBoundsException
@@ -137,13 +137,15 @@
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
+ && index < (bufferIndex + bufferSize)) // upper boundary
{
// now we can get this from the buffer. Sweet!
int indexToReturn = index - bufferIndex;
@@ -167,7 +169,7 @@
// 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++)
+ for (int i = 1; i < bufferSize; i++)
{
String bufferDocumentId = (String) extractor.extract(hits, index + i).id;
CacheEntityId bufferId = new CacheEntityId(bufferDocumentId);
@@ -193,6 +195,8 @@
public Object previous()
{
+ if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
+
Object toReturn = null;
int bufferSize = buffer.length;
@@ -219,7 +223,7 @@
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++)
+ for (int i = 1; i < bufferSize; i++)
{
String bufferDocumentId = (String) extractor.extract(hits, index - i).id; //In this case it has to be index - i because previous() is called.
CacheEntityId bufferId = new CacheEntityId(bufferDocumentId);
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -18,19 +18,23 @@
* 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.jboss.cache.search;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Arrays;
/**
* This is the implementation class for the interface QueryResultIterator which extends ListIterator. It is what is
* returned when the iterator() method is run on a CacheQuery instance.
- *
* <p/>
+ * <p/>
*
* @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
*/
@@ -42,12 +46,25 @@
private CacheEntityLoader entityLoader;
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<CacheEntityId> idList, CacheEntityLoader entityLoader)
+
+ public QueryResultIteratorImpl(List<CacheEntityId> idList, CacheEntityLoader entityLoader, int fetchSize)
{
+ if (fetchSize < 1)
+ {
+ throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+ }
+
this.idList = idList;
this.entityLoader = entityLoader;
upperLimit = idList.size() - 1;
+ this.fetchSize = fetchSize;
+
+ buffer = new Object[this.fetchSize];
}
/**
@@ -163,8 +180,53 @@
*/
public Object next()
{
- if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
- Object toReturn = entityLoader.load(idList.get(index));
+ 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 = entityLoader.load(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 = entityLoader.load(idList.get(index + i));
+ buffer[i] = toBuffer;
+ }
+ bufferIndex = index;
+
+ }
+
index++;
return toReturn;
}
@@ -187,8 +249,51 @@
public Object previous()
{
- if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries");
- Object toReturn = entityLoader.load(idList.get(index));
+ 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 = entityLoader.load(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.
+ // 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++)
+ {
+ if (index - i < lowerLimit)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Your current index - bufferSize exceeds the size of your number of hits");
+ }
+ break;
+ }
+
+ Object toBuffer = entityLoader.load(idList.get(index - i));
+ buffer[i] = toBuffer;
+ }
+ bufferIndex = index;
+
+
+ }
index--;
return toReturn;
}
@@ -248,5 +353,5 @@
{
throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
}
-
+
}
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/LazyQueryResultIteratorTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/LazyQueryResultIteratorTest.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/LazyQueryResultIteratorTest.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -1,13 +1,285 @@
package org.jboss.cache.search;
-import org.testng.annotations.Test;
+import org.testng.annotations.*;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.search.test.Person;
+import org.jboss.cache.search.helper.IndexCleanUp;
+
/**
* @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
*/
-@Test(groups="functional")
+@Test(groups = "functional")
public class LazyQueryResultIteratorTest
{
- //Need to use mock-objects for this test.
-
+ SearchableCache searchableCache;
+ QueryParser parser = null;
+ Query luceneQuery = null;
+ CacheQuery cacheQuery = null;
+ LazyQueryResultIterator iterator = null;
+ int fetchSize = 1;
+ Person person1, person2, person3, person4, person5, person6, person7, person8, person9, person10;
+ StringBuilder builder;
+
+
+ @BeforeTest
+ public void setUpBeforeTest() throws ParseException
+ {
+ Cache coreCache = new DefaultCacheFactory().createCache();
+ searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
+
+ 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();
+
+ 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");
+
+ searchableCache.put(Fqn.fromString("/a"), "key1", person1);
+ searchableCache.put(Fqn.fromString("/a"), "key2", person2);
+ searchableCache.put(Fqn.fromString("/a"), "key3", person3);
+ searchableCache.put(Fqn.fromString("/a"), "key4", person4);
+ searchableCache.put(Fqn.fromString("/a"), "key5", person5);
+ searchableCache.put(Fqn.fromString("/a"), "key6", person6);
+ searchableCache.put(Fqn.fromString("/a"), "key7", person7);
+ searchableCache.put(Fqn.fromString("/a"), "key8", person8);
+ searchableCache.put(Fqn.fromString("/a"), "key9", person9);
+ searchableCache.put(Fqn.fromString("/a"), "key10", person10);
+
+
+ }
+
+ @AfterTest
+ public void tearDownAfterTest()
+ {
+ IndexCleanUp.cleanUpIndexes();
+ }
+
+ @BeforeMethod
+ public void setUp() throws ParseException
+ {
+ parser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = parser.parse("cat");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ iterator = (LazyQueryResultIterator) cacheQuery.lazyIterator();
+
+ }
+
+
+ @AfterMethod
+ public void tearDown()
+ {
+ iterator = null;
+ parser = null;
+ luceneQuery = null;
+ cacheQuery = 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();
+ 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 = searchableCache.get("/a", 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 = searchableCache.get("/a", 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.
+ }
+
}
+
+
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-09-25 14:38:10 UTC (rev 6789)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-09-25 15:38:36 UTC (rev 6790)
@@ -22,6 +22,7 @@
List<CacheEntityId> ids;
Map<CacheEntityId, Object> dummyResults;
QueryResultIterator iterator;
+ int fetchSize = 1;
@BeforeMethod
public void setUp()
@@ -52,7 +53,7 @@
// now create a dummy entity loader
CacheEntityLoader dummyLoader = new DummyEntityLoader(ids, dummyResults);
- iterator = new QueryResultIteratorImpl(ids, dummyLoader);
+ iterator = new QueryResultIteratorImpl(ids, dummyLoader, fetchSize);
}
@AfterMethod
@@ -149,7 +150,7 @@
assert next == dummyResults.get(ids.get(size - 2));
//Make sure that the iterator is not pointing at the penultimate element.
- assert !iterator.isAfterFirst();
+ assert !iterator.isBeforeLast();
}
public void testIsFirst()
@@ -190,6 +191,7 @@
iterator.first();
for (int i = 0; i < ids.size(); i++)
{
+ System.out.println("Loop number count: - " + (i+1));
Object expectedValue = dummyResults.get(ids.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()
@@ -229,16 +231,6 @@
assert iterator.previousIndex() == (ids.size() - 2);
}
-// public void testPreviousAndNext()
-// {
-// iterator.jumpToResult(5);
-// for (int i = 0; i < 10; i++) // repeat 10 times
-// {
-// assert iterator.next() == iterator.previous();
-// }
-//
-// }
-
public static class DummyEntityLoader extends CacheEntityLoader
{
private List<CacheEntityId> allKnownIds;
15 years, 7 months
JBoss Cache SVN: r6789 - core/trunk/src/test/java/org/jboss/cache/optimistic.
by jbosscache-commits@lists.jboss.org
Author: bela(a)jboss.com
Date: 2008-09-25 10:38:10 -0400 (Thu, 25 Sep 2008)
New Revision: 6789
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
Log:
fixed compile error
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-09-25 14:29:10 UTC (rev 6788)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-09-25 14:38:10 UTC (rev 6789)
@@ -309,6 +309,11 @@
return 0;
}
+ public int compareTo(Object o)
+ {
+ return 0;
+ }
+
public void readFrom(DataInputStream
arg0)
{
@@ -339,6 +344,7 @@
return false;
}
+
}
}
15 years, 7 months
Build failed in Hudson: jboss-cache-core-trunk-jdk1.6 » JBoss Cache - Core Edition #463
by jboss-qa-internal@redhat.com
See http://hudson.qa.jboss.com/hudson/job/jboss-cache-core-trunk-jdk1.6/org.j...
Changes:
[manik.surtani(a)jboss.com] JBCACHE-1410: JDBCCacheLoader may attempt to create a node entry in the DB twice
[bela(a)jboss.com] changed compareTo()
[manik.surtani(a)jboss.com] Do not create node if it already exists
[manik.surtani(a)jboss.com] Optimised memory footprint
------------------------------------------
started
Building remotely on dev41-rhel4
$ java -Xmx512m -cp /mnt/hudson_workspace/maven-agent.jar:/qa/tools/opt/maven-2.0.9/boot/classworlds-1.1.jar hudson.maven.agent.Main /qa/tools/opt/maven-2.0.9 /qa/services/hudson/hudson_release/WEB-INF/slave.jar /mnt/hudson_workspace/maven-interceptor.jar
channel started
[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building JBoss Cache - Core Edition
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [enforcer:enforce {execution: enforce-java}]
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 487 source files to /mnt/hudson_workspace/workspace/jboss-cache-core-trunk-jdk1.6/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 498 source files to /mnt/hudson_workspace/workspace/jboss-cache-core-trunk-jdk1.6/target/test-classes
[HUDSON] Archiving /mnt/hudson_workspace/workspace/jboss-cache-core-trunk-jdk1.6/./pom.xml
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/mnt/hudson_workspace/workspace/jboss-cache-core-trunk-jdk1.6/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java:[303,13] org.jboss.cache.optimistic.AbstractOptimisticTestCase.DummyAddress is not abstract and does not override abstract method compareTo(java.lang.Object) in java.lang.Comparable
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 2 seconds
[INFO] Finished at: Thu Sep 25 10:35:05 EDT 2008
[INFO] Final Memory: 13M/78M
[INFO] ------------------------------------------------------------------------
Waiting for Hudson to finish collecting data
15 years, 7 months
JBoss Cache SVN: r6788 - in core/trunk/src/main/java/org/jboss/cache: util/concurrent/locks and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-25 10:29:10 -0400 (Thu, 25 Sep 2008)
New Revision: 6788
Added:
core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java
Log:
JBCACHE-1410: JDBCCacheLoader may attempt to create a node entry in the DB twice
Modified: core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-25 14:27:07 UTC (rev 6787)
+++ core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-25 14:29:10 UTC (rev 6788)
@@ -22,12 +22,10 @@
package org.jboss.cache.lock;
import net.jcip.annotations.ThreadSafe;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.util.concurrent.locks.UpgradableLock;
import java.util.List;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* A simple implementation of lock striping, using Fqns as the keys to lock on, primarily used to help make
@@ -50,8 +48,7 @@
private final int lockSegmentMask;
private final int lockSegmentShift;
- final ReentrantReadWriteLock[] sharedLocks;
- private final Log log = LogFactory.getLog(StripedLock.class);
+ final UpgradableLock[] sharedLocks;
/**
* This constructor just calls {@link #StripedLock(int)} with a default concurrency value of 20.
@@ -78,9 +75,9 @@
lockSegmentShift = 32 - tempLockSegShift;
lockSegmentMask = numLocks - 1;
- sharedLocks = new ReentrantReadWriteLock[numLocks];
+ sharedLocks = new UpgradableLock[numLocks];
- for (int i = 0; i < numLocks; i++) sharedLocks[i] = new ReentrantReadWriteLock();
+ for (int i = 0; i < numLocks; i++) sharedLocks[i] = new UpgradableLock();
}
/**
@@ -91,15 +88,16 @@
*/
public void acquireLock(Fqn fqn, boolean exclusive)
{
- ReentrantReadWriteLock lock = getLock(fqn);
+ UpgradableLock lock = getLock(fqn);
if (exclusive)
{
- // allow for reentrancy
- lock.writeLock().lock();
+ lock.acquireWriteLockWithUpgrade();
}
else
+ {
lock.readLock().lock();
+ }
}
/**
@@ -109,28 +107,11 @@
*/
public void releaseLock(Fqn fqn)
{
- ReentrantReadWriteLock lock = getLock(fqn);
- if (lock.isWriteLockedByCurrentThread())
- {
- lock.writeLock().unlock();
- // check that we still don't have a stale WL
-// if (lock.isWriteLockedByCurrentThread() && log.isWarnEnabled())
-// log.warn("Write lock still exists on Fqn " + fqn + " for current thread. Perhaps this was write-locked more than once?");
- }
- else
- {
- try
- {
- lock.readLock().unlock();
- }
- catch (IllegalMonitorStateException imse)
- {
- // perhaps the RL was already released earlier?
- }
- }
+ UpgradableLock lock = getLock(fqn);
+ lock.unlock();
}
- final ReentrantReadWriteLock getLock(Object o)
+ final UpgradableLock getLock(Object o)
{
return sharedLocks[hashToIndex(o)];
}
Added: core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java 2008-09-25 14:29:10 UTC (rev 6788)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.jboss.cache.util.concurrent.locks;
+
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * A {@link java.util.concurrent.locks.ReentrantReadWriteLock} with support for acquiring write locks when the current
+ * thread already has a read lock. Also supports releasing such write locks and re-acquiring read locks in the process.
+ */
+public class UpgradableLock extends ReentrantReadWriteLock
+{
+ private final Set<Thread> upgraders = new ConcurrentHashSet<Thread>();
+
+ /**
+ * Attempts to upgrade a read lock to a write lock. If no read locks are held, a write lock is simply attempted.
+ */
+ public void acquireWriteLockWithUpgrade()
+ {
+ boolean upgradeNeeded = true;
+ try
+ {
+ readLock().unlock();
+ }
+ catch (IllegalMonitorStateException imse)
+ {
+ // read lock was never held; no upgrading needed.
+ upgradeNeeded = false;
+ }
+
+ if (upgradeNeeded) upgraders.add(Thread.currentThread());
+
+ writeLock().lock();
+ }
+
+ /**
+ * Unlocks any locks held by the current thread. If a write lock is held, it is released. If a read lock is held
+ * it is released. This method supports reentrant locks so unlocking repeatedly may release >1 write lock. It
+ * also supports upgraded locks, i.e., read locks that were upgraded to write locks.
+ */
+ public void unlock()
+ {
+ if (isWriteLockedByCurrentThread())
+ {
+ writeLock().unlock();
+ Thread current;
+ if (!isWriteLockedByCurrentThread() && upgraders.contains((current = Thread.currentThread())))
+ {
+ // re-acquire the RL.
+ readLock().lock();
+ upgraders.remove(current);
+ }
+ }
+ else
+ {
+ try
+ {
+ readLock().unlock();
+ }
+ catch (IllegalMonitorStateException imse)
+ {
+ // perhaps the RL was already released earlier?
+ }
+ }
+ }
+}
15 years, 7 months
JBoss Cache SVN: r6787 - in core/branches/2.2.X/src/main/java/org/jboss/cache: util/concurrent and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-25 10:27:07 -0400 (Thu, 25 Sep 2008)
New Revision: 6787
Added:
core/branches/2.2.X/src/main/java/org/jboss/cache/util/concurrent/locks/
core/branches/2.2.X/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java
Log:
JBCACHE-1410: JDBCCacheLoader may attempt to create a node entry in the DB twice
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-24 11:47:40 UTC (rev 6786)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-25 14:27:07 UTC (rev 6787)
@@ -1,13 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.cache.lock;
import net.jcip.annotations.ThreadSafe;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.util.concurrent.locks.UpgradableLock;
import java.util.List;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* A simple implementation of lock striping, using Fqns as the keys to lock on, primarily used to help make
@@ -30,8 +48,7 @@
private final int lockSegmentMask;
private final int lockSegmentShift;
- final ReentrantReadWriteLock[] sharedLocks;
- private final Log log = LogFactory.getLog(StripedLock.class);
+ final UpgradableLock[] sharedLocks;
/**
* This constructor just calls {@link #StripedLock(int)} with a default concurrency value of 20.
@@ -58,9 +75,9 @@
lockSegmentShift = 32 - tempLockSegShift;
lockSegmentMask = numLocks - 1;
- sharedLocks = new ReentrantReadWriteLock[numLocks];
+ sharedLocks = new UpgradableLock[numLocks];
- for (int i = 0; i < numLocks; i++) sharedLocks[i] = new ReentrantReadWriteLock();
+ for (int i = 0; i < numLocks; i++) sharedLocks[i] = new UpgradableLock();
}
/**
@@ -71,15 +88,16 @@
*/
public void acquireLock(Fqn fqn, boolean exclusive)
{
- ReentrantReadWriteLock lock = getLock(fqn);
+ UpgradableLock lock = getLock(fqn);
if (exclusive)
{
- // allow for reentrancy
- lock.writeLock().lock();
+ lock.acquireWriteLockWithUpgrade();
}
else
+ {
lock.readLock().lock();
+ }
}
/**
@@ -89,28 +107,11 @@
*/
public void releaseLock(Fqn fqn)
{
- ReentrantReadWriteLock lock = getLock(fqn);
- if (lock.isWriteLockedByCurrentThread())
- {
- lock.writeLock().unlock();
- // check that we still don't have a stale WL
-// if (lock.isWriteLockedByCurrentThread() && log.isWarnEnabled())
-// log.warn("Write lock still exists on Fqn " + fqn + " for current thread. Perhaps this was write-locked more than once?");
- }
- else
- {
- try
- {
- lock.readLock().unlock();
- }
- catch (IllegalMonitorStateException imse)
- {
- throw new CacheException("Lock is held by a different thread! Cannot be unlocked by current thread.", imse);
- }
- }
+ UpgradableLock lock = getLock(fqn);
+ lock.unlock();
}
- final ReentrantReadWriteLock getLock(Object o)
+ final UpgradableLock getLock(Object o)
{
return sharedLocks[hashToIndex(o)];
}
@@ -160,4 +161,4 @@
{
for (Fqn f : fqns) acquireLock(f, exclusive);
}
-}
+}
\ No newline at end of file
Added: core/branches/2.2.X/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java (rev 0)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/util/concurrent/locks/UpgradableLock.java 2008-09-25 14:27:07 UTC (rev 6787)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.jboss.cache.util.concurrent.locks;
+
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * A {@link java.util.concurrent.locks.ReentrantReadWriteLock} with support for acquiring write locks when the current
+ * thread already has a read lock. Also supports releasing such write locks and re-acquiring read locks in the process.
+ */
+public class UpgradableLock extends ReentrantReadWriteLock
+{
+ private final Set<Thread> upgraders = new ConcurrentHashSet<Thread>();
+
+ /**
+ * Attempts to upgrade a read lock to a write lock. If no read locks are held, a write lock is simply attempted.
+ */
+ public void acquireWriteLockWithUpgrade()
+ {
+ boolean upgradeNeeded = true;
+ try
+ {
+ readLock().unlock();
+ }
+ catch (IllegalMonitorStateException imse)
+ {
+ // read lock was never held; no upgrading needed.
+ upgradeNeeded = false;
+ }
+
+ if (upgradeNeeded) upgraders.add(Thread.currentThread());
+
+ writeLock().lock();
+ }
+
+ /**
+ * Unlocks any locks held by the current thread. If a write lock is held, it is released. If a read lock is held
+ * it is released. This method supports reentrant locks so unlocking repeatedly may release >1 write lock. It
+ * also supports upgraded locks, i.e., read locks that were upgraded to write locks.
+ */
+ public void unlock()
+ {
+ if (isWriteLockedByCurrentThread())
+ {
+ writeLock().unlock();
+ Thread current;
+ if (!isWriteLockedByCurrentThread() && upgraders.contains((current = Thread.currentThread())))
+ {
+ // re-acquire the RL.
+ readLock().lock();
+ upgraders.remove(current);
+ }
+ }
+ else
+ {
+ try
+ {
+ readLock().unlock();
+ }
+ catch (IllegalMonitorStateException imse)
+ {
+ // perhaps the RL was already released earlier?
+ }
+ }
+ }
+}
\ No newline at end of file
15 years, 7 months
JBoss Cache SVN: r6786 - core/trunk/src/test/java/org/jboss/cache/optimistic.
by jbosscache-commits@lists.jboss.org
Author: bela(a)jboss.com
Date: 2008-09-24 07:47:40 -0400 (Wed, 24 Sep 2008)
New Revision: 6786
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
Log:
changed compareTo()
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-09-23 22:52:13 UTC (rev 6785)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-09-24 11:47:40 UTC (rev 6786)
@@ -304,7 +304,7 @@
{
private static final long serialVersionUID = -2628268587640985944L;
- public int compareTo(Object arg0)
+ public int compareTo(Address arg0)
{
return 0;
}
15 years, 7 months
JBoss Cache SVN: r6785 - core/branches/2.2.X/src/main/java/org/jboss/cache/loader.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-23 18:52:13 -0400 (Tue, 23 Sep 2008)
New Revision: 6785
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
Log:
Don't write node to DB unnecessarily
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23 22:03:36 UTC (rev 6784)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23 22:52:13 UTC (rev 6785)
@@ -249,7 +249,7 @@
}
else
{
- insertNode(currentNode, null);
+ if (loadNode(currentNode) == null) insertNode(currentNode, null);
}
}
finally
15 years, 7 months
JBoss Cache SVN: r6784 - core/trunk/src/main/java/org/jboss/cache/loader.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-23 18:03:36 -0400 (Tue, 23 Sep 2008)
New Revision: 6784
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
Log:
Do not create node if it already exists
Modified: core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23 15:23:57 UTC (rev 6783)
+++ core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23 22:03:36 UTC (rev 6784)
@@ -335,7 +335,7 @@
}
else
{
- insertNode(currentNode, null);
+ if (loadNode(currentNode) == null) insertNode(currentNode, null);
}
}
finally
15 years, 7 months
JBoss Cache SVN: r6783 - core/trunk/src/main/java/org/jboss/cache/mvcc.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-23 11:23:57 -0400 (Tue, 23 Sep 2008)
New Revision: 6783
Modified:
core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
Log:
Optimised memory footprint
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-09-23 14:58:35 UTC (rev 6782)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-09-23 15:23:57 UTC (rev 6783)
@@ -45,10 +45,8 @@
protected volatile InternalNode backup;
protected byte flags = 0;
- protected Fqn fqn;
protected InternalNode parent;
- protected Fqn parentFqn;
protected static enum Flags
{
@@ -66,7 +64,6 @@
{
super(node);
this.parent = parent;
- if (parent != null) parentFqn = parent.getFqn();
}
public InternalNode getInternalParent()
@@ -111,13 +108,6 @@
return false;
}
- // convenience fqn retrieval method
- protected final Fqn fqn()
- {
- if (fqn == null) fqn = getFqn();
- return fqn;
- }
-
@Override
public void markForUpdate(DataContainer container, boolean writeSkewCheck)
{
@@ -140,7 +130,7 @@
// only do stuff if there are changes.
if (isFlagSet(CHANGED))
{
- Fqn fqn = fqn();
+ Fqn fqn = getFqn();
if (trace)
log.trace("Updating node [" + fqn + "]. deleted=" + isDeleted() + " valid=" + isValid() + " changed=" + isChanged() + " created=" + isFlagSet(CREATED));
@@ -152,7 +142,7 @@
InternalNode parent = lookupParent(fqn, ctx, container);
parent.removeChild(fqn.getLastElement());
setValid(false, false);
- updateNode(ctx, container);
+ updateNode(fqn, ctx, container);
}
else
{
@@ -169,7 +159,7 @@
else
{
// Only content has been updated, just update refs.
- updateNode(ctx, container);
+ updateNode(fqn, ctx, container);
}
// reset internal flags and refs to backups, etc.
@@ -198,7 +188,7 @@
if (parent != null) return parent;
InternalNode retval;
- Fqn parentFqn = this.parentFqn == null ? fqn.getParent() : this.parentFqn; // use the class-level parentFqn where possible since this will already have a hashcode computed.
+ Fqn parentFqn = fqn.getParent();
NodeSPI parent = ctx.lookUpNode(parentFqn);
// first check if the parent is cached in the context.
if (parent != null)
@@ -222,7 +212,7 @@
* @param dataContainer data container
*/
@SuppressWarnings("unchecked")
- protected void updateNode(InvocationContext ctx, DataContainer dataContainer)
+ protected void updateNode(Fqn fqn, InvocationContext ctx, DataContainer dataContainer)
{
// swap refs
if (!isFlagSet(CREATED)) ((NodeReference) backup).setDelegate(node);
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-09-23 14:58:35 UTC (rev 6782)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-09-23 15:23:57 UTC (rev 6783)
@@ -51,7 +51,7 @@
{
if (isFlagSet(CHANGED)) return; // already copied
- Fqn fqn = fqn();
+ Fqn fqn = getFqn();
// mark node as changed.
setFlag(CHANGED);
@@ -76,9 +76,8 @@
@Override
@SuppressWarnings("unchecked")
- protected void updateNode(InvocationContext ctx, DataContainer dataContainer)
+ protected void updateNode(Fqn fqn, InvocationContext ctx, DataContainer dataContainer)
{
- Fqn fqn = fqn();
if (fqn.isRoot())
{
dataContainer.setRoot(node);
15 years, 7 months