directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1126458 - /directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java
Date Mon, 23 May 2011 11:57:01 GMT
Author: elecharny
Date: Mon May 23 11:57:01 2011
New Revision: 1126458

URL: http://svn.apache.org/viewvc?rev=1126458&view=rev
Log:
Clear the cacheManager when the test is terminated

Modified:
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java?rev=1126458&r1=1126457&r2=1126458&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java
Mon May 23 11:57:01 2011
@@ -31,8 +31,6 @@ import javax.security.auth.kerberos.Kerb
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.shared.kerberos.KerberosTime;
 import org.apache.directory.shared.kerberos.codec.types.PrincipalNameType;
@@ -40,6 +38,9 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the InMemory replay cache
@@ -63,48 +64,60 @@ public class ReplayCacheImplTest
     @Test
     public void testCacheSetting() throws Exception
     {
-        long clockSkew = 1000; // 1 sec
-
-        CacheManager cacheManager = new CacheManager( ReplayCacheImplTest.class.getClassLoader().getResource(
-            "directory-cacheservice.xml" ) );
-
-        Cache ehCache = cacheManager.getCache( "kdcReplayCache" );
-        ehCache.getCacheConfiguration().setMaxElementsInMemory( 2 );
-        ehCache.getCacheConfiguration().setTimeToLiveSeconds( 1 );
-        ehCache.getCacheConfiguration().setTimeToIdleSeconds( 1 );
-        ehCache.getCacheConfiguration().setDiskExpiryThreadIntervalSeconds( 1 );
-
-        ReplayCacheImpl cache = new ReplayCacheImpl( ehCache, clockSkew );
-
-        int i = 0;
-
-        // Inject 4 entries
-        while ( i < 4 )
+        CacheManager cacheManager = null;
+        
+        try
         {
-            KerberosPrincipal serverPrincipal = new KerberosPrincipal( "server" + i + "@APACHE.ORG",
-                PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );
-            KerberosPrincipal clientPrincipal = new KerberosPrincipal( "client" + i + "@APACHE.ORG",
-                PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );
-
-            cache.save( serverPrincipal, clientPrincipal, new KerberosTime( System.currentTimeMillis()
), 0 );
-
-            i++;
+            long clockSkew = 1000; // 1 sec
+    
+            cacheManager = new CacheManager( ReplayCacheImplTest.class.getClassLoader().getResource(
+                "directory-cacheservice.xml" ) );
+    
+            Cache ehCache = cacheManager.getCache( "kdcReplayCache" );
+            ehCache.getCacheConfiguration().setMaxElementsInMemory( 2 );
+            ehCache.getCacheConfiguration().setTimeToLiveSeconds( 1 );
+            ehCache.getCacheConfiguration().setTimeToIdleSeconds( 1 );
+            ehCache.getCacheConfiguration().setDiskExpiryThreadIntervalSeconds( 1 );
+    
+            ReplayCacheImpl cache = new ReplayCacheImpl( ehCache, clockSkew );
+    
+            int i = 0;
+    
+            // Inject 4 entries
+            while ( i < 4 )
+            {
+                KerberosPrincipal serverPrincipal = new KerberosPrincipal( "server" + i +
"@APACHE.ORG",
+                    PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );
+                KerberosPrincipal clientPrincipal = new KerberosPrincipal( "client" + i +
"@APACHE.ORG",
+                    PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );
+    
+                cache.save( serverPrincipal, clientPrincipal, new KerberosTime( System.currentTimeMillis()
), 0 );
+    
+                i++;
+            }
+    
+            List<?> keys = ehCache.getKeys();
+    
+            // We should have 4 entries
+            assertTrue( keys.size() != 0 );
+    
+            // Wait till the timetolive time exceeds
+            Thread.sleep( 1200 );
+    
+            // then access the cache so that the objects present in the cache will be expired
+            for ( Object k : keys )
+            {
+                assertNull( ehCache.get( k ) );
+            }
+    
+            assertEquals( 0, ehCache.getKeys().size() );
         }
-
-        List<?> keys = ehCache.getKeys();
-
-        // We should have 4 entries
-        assertTrue( keys.size() != 0 );
-
-        // Wait till the timetolive time exceeds
-        Thread.sleep( 1200 );
-
-        // then access the cache so that the objects present in the cache will be expired
-        for ( Object k : keys )
+        finally
         {
-            assertNull( ehCache.get( k ) );
+            if ( cacheManager != null )
+            {
+                cacheManager.shutdown();
+            }
         }
-
-        assertEquals( 0, ehCache.getKeys().size() );
     }
 }



Mime
View raw message