mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r887522 - /lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
Date Sat, 05 Dec 2009 09:29:24 GMT
Author: srowen
Date: Sat Dec  5 09:29:24 2009
New Revision: 887522

URL: http://svn.apache.org/viewvc?rev=887522&view=rev
Log:
Added more cache tests in pursuit of possible infinite loop issue

Added:
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
      - copied, changed from r887324, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/EmptyIteratorTest.java

Copied: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
(from r887324, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/EmptyIteratorTest.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java?p2=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java&p1=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/EmptyIteratorTest.java&r1=887324&r2=887522&rev=887522&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/EmptyIteratorTest.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
Sat Dec  5 09:29:24 2009
@@ -17,33 +17,42 @@
 
 package org.apache.mahout.cf.taste.impl.common;
 
+import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.common.RandomUtils;
 
-import java.util.Iterator;
-import java.util.NoSuchElementException;
+import java.util.Random;
 
-public final class EmptyIteratorTest extends TasteTestCase {
+public final class CacheTest extends TasteTestCase {
 
-  public void testIterator() {
-    Iterator<Object> mock = new EmptyIterator<Object>();
-    assertFalse(mock.hasNext());
-    try {
-      mock.next();
-      fail("Should have thrown NoSuchElementException");
-    } catch (NoSuchElementException nsee) {
-      // good
-    }
-    try {
-      mock.remove();
-      fail("Should have thrown UnsupportedOperationException");
-    } catch (UnsupportedOperationException uoe) {
-      // good
+  public void testLotsOfGets() throws TasteException {
+    Retriever<Object,Object> retriever = new IdentityRetriever();
+    Cache<Object,Object> cache = new Cache<Object,Object>(retriever, 1000);
+    for (int i = 0; i < 1000000; i++) {
+      assertEquals(i, cache.get(i));
     }
   }
 
-  public void testIterable() {
-    Iterable<Object> mock = new EmptyIterable<Object>();
-    assertNotNull(mock.iterator());
+  public void testMixedUsage() throws TasteException {
+    Random random = RandomUtils.getRandom();
+    Retriever<Object,Object> retriever = new IdentityRetriever();
+    Cache<Object,Object> cache = new Cache<Object,Object>(retriever, 1000);
+    for (int i = 0; i < 1000000; i++) {
+      double r = random.nextDouble();
+      if (r < 0.01) {
+        cache.clear();
+      } else if (r < 0.1) {
+        cache.remove(r-100);
+      } else {
+        assertEquals(i, cache.get(i));
+      }
+    }
   }
 
-}
+  private static class IdentityRetriever implements Retriever<Object,Object> {
+    @Override
+    public Object get(Object key) {
+      return key;
+    }
+  }
+}
\ No newline at end of file



Mime
View raw message