directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1039043 - in /directory/apacheds/trunk/kerberos-shared/src: main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java
Date Thu, 25 Nov 2010 13:53:01 GMT
Author: seelmann
Date: Thu Nov 25 13:53:00 2010
New Revision: 1039043

URL: http://svn.apache.org/viewvc?rev=1039043&view=rev
Log:
Fix sporadic failing test by calling cache.cleanCache() manually

Modified:
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java?rev=1039043&r1=1039042&r2=1039043&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCache.java
Thu Nov 25 13:53:00 2010
@@ -41,7 +41,9 @@ import org.apache.directory.server.kerbe
  * principal, and we will store a list of entries for each client principal.
  * 
  * A thread will run every N seconds to clean the cache from entries out of the 
- * clockSkew
+ * clockSkew.
+ * 
+ * TODO: check if we really want an active thread for each cache instance (DIRKRB-80).
  *    
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -52,13 +54,13 @@ public class InMemoryReplayCache extends
 
     /** default clock skew */
     private static final long DEFAULT_CLOCK_SKEW = 5 * KerberosTime.MINUTE;
-    
+
     /** The clock skew */
     private long clockSkew = DEFAULT_CLOCK_SKEW;
 
     /** The default delay between each run of the cleaning process : 5 s */
     private static long DEFAULT_DELAY = 5 * 1000;  
-    
+
     /** The delay to wait between each cache cleaning */
     private long delay;
 
@@ -257,7 +259,7 @@ public class InMemoryReplayCache extends
     /**
      * A method to remove all the expired entries from the cache.
      */
-    private synchronized void cleanCache()
+    synchronized void cleanCache()
     {
         Collection<List<ReplayCacheEntry>> entryList = cache.values();
         
@@ -307,6 +309,7 @@ public class InMemoryReplayCache extends
             }
             catch ( InterruptedException ie )
             {
+                cache.clear();
                 return;
             }
         }

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java?rev=1039043&r1=1039042&r2=1039043&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/replay/InMemoryReplayCacheTest.java
Thu Nov 25 13:53:00 2010
@@ -28,14 +28,17 @@ import javax.security.auth.kerberos.Kerb
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.server.kerberos.shared.messages.value.KerberosTime;
 import org.apache.directory.server.kerberos.shared.messages.value.types.PrincipalNameType;
 import org.apache.directory.server.kerberos.shared.replay.InMemoryReplayCache.ReplayCacheEntry;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Test the InMemory replay cache
@@ -46,6 +49,9 @@ import static org.junit.Assert.assertNot
 @Concurrent()
 public class InMemoryReplayCacheTest
 {
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.THREADSAFE
);
+
     /**
      * Test that the cache is working well. We will create a new entry
      * every 20 ms, with 10 different serverPrincipals.
@@ -107,9 +113,12 @@ public class InMemoryReplayCacheTest
 
         // We should have some
         assertNotNull( nbEntries );
+        assertTrue(nbEntries > 0);
         
         // Wait another delay, so that the cleaning thread will be kicked off
         Thread.sleep( delay + 50 );
+        // It's not guaranteed that the thread run, so invoke the method manually
+        cache.cleanCache();
         
         nbEntries = 0;
         
@@ -131,5 +140,8 @@ public class InMemoryReplayCacheTest
 
         // We should not have anymore entry in the cache
         assertEquals( 0, nbEntries );
+
+        // Stop background thread
+        cache.interrupt();
     }
 }



Mime
View raw message