From commits-return-31851-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon May 23 11:57:26 2011 Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2758345E2 for ; Mon, 23 May 2011 11:57:26 +0000 (UTC) Received: (qmail 3689 invoked by uid 500); 23 May 2011 11:57:26 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 3644 invoked by uid 500); 23 May 2011 11:57:25 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 3637 invoked by uid 99); 23 May 2011 11:57:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 11:57:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 11:57:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 91DD023888E4; Mon, 23 May 2011 11:57:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110523115701.91DD023888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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() ); } }