From: Olivier Lamy Date: Fri, 4 Nov 2011 13:51:54 +0000 (+0000) Subject: avoid lucene lock issues with starting spring container with no repositories X-Git-Tag: archiva-1.4-M2~158 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=840cabb0fb7b4a7e66eda3f8474a91c5158a8598;p=archiva.git avoid lucene lock issues with starting spring container with no repositories git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197569 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webdav/pom.xml b/archiva-modules/archiva-web/archiva-webdav/pom.xml index 5c301b023..693ec98d5 100644 --- a/archiva-modules/archiva-web/archiva-webdav/pom.xml +++ b/archiva-modules/archiva-web/archiva-webdav/pom.xml @@ -197,6 +197,9 @@ ${project.build.directory}/appserver-base ${project.build.directory}/appserver-base ${project.build.directory}/appserver-base + ${project.build.testOutputDirectory} + jdbc:derby:memory:users-test;create=true + org.apache.derby.jdbc.EmbeddedDriver ${webdav.forkMode} diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java index 8ae24a9ee..653e5bb67 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -27,16 +27,18 @@ import junit.framework.Assert; import junit.framework.TestCase; import net.sf.ehcache.CacheManager; import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.commons.io.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.maven.index.NexusIndexer; -import org.apache.maven.index.context.IndexingContext; +import org.apache.archiva.webdav.util.MavenIndexerCleaner; +import org.apache.commons.io.FileUtils; +import org.apache.lucene.store.Lock; +import org.apache.lucene.store.LockReleaseFailedException; +import org.apache.lucene.store.NativeFSLockFactory; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,6 +50,8 @@ import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * AbstractRepositoryServletTestCase @@ -85,11 +89,47 @@ public abstract class AbstractRepositoryServletTestCase saveConfiguration( archivaConfiguration ); } + @BeforeClass + public static void lockCleanup() + throws Exception + { + /* + + try + { + + /* + Field locks = NativeFSLockFactory.class.getDeclaredClasses()[0].getField( "LOCK_HELD" ); + locks.setAccessible( true ); + Method clear = locks.getClass().getMethod( "clear" ); + + clear.invoke( field, null ); + */ + + /* + NativeFSLockFactory nativeFSLockFactory = + new NativeFSLockFactory( new File( "target/appserver-base/data/repositories/internal/.indexer" ) ); + + Lock lock = nativeFSLockFactory.makeLock( "write.lock" ); + lock.release(); + LoggerFactory.getLogger( AbstractRepositoryServletTestCase.class ).info( "cleanup lock" ); + + + } + catch ( LockReleaseFailedException e ) + { + // ignore + } + */ + } + @Before public void setUp() throws Exception { + + lockCleanup(); super.setUp(); String appserverBase = new File( "target/appserver-base" ).getAbsolutePath(); @@ -105,7 +145,6 @@ public abstract class AbstractRepositoryServletTestCase archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class ); - //archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); repoRootInternal = new File( appserverBase, "data/repositories/internal" ); repoRootLegacy = new File( appserverBase, "data/repositories/legacy" ); Configuration config = archivaConfiguration.getConfiguration(); @@ -128,6 +167,8 @@ public abstract class AbstractRepositoryServletTestCase HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ); + applicationContext.getBean( MavenIndexerCleaner.class ).cleanupIndex(); + sr = new ServletRunner( new File( "src/test/resources/WEB-INF/web.xml" ) ); sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() ); @@ -140,7 +181,6 @@ public abstract class AbstractRepositoryServletTestCase throws Exception { - if ( sc != null ) { sc.clearContents(); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/util/MavenIndexerCleaner.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/util/MavenIndexerCleaner.java index a2bf649ca..54db5c915 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/util/MavenIndexerCleaner.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/util/MavenIndexerCleaner.java @@ -19,6 +19,9 @@ package org.apache.archiva.webdav.util; */ import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; +import org.apache.lucene.store.Lock; +import org.apache.lucene.store.LockReleaseFailedException; +import org.apache.lucene.store.NativeFSLockFactory; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; import org.slf4j.Logger; @@ -33,6 +36,7 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import java.io.File; /** * @author Olivier Lamy @@ -50,17 +54,18 @@ public class MavenIndexerCleaner private ApplicationContext applicationContext; @PostConstruct - public void startup() throws Exception + public void startup() + throws Exception { plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class ); - cleanupIndex( ); + cleanupIndex(); } @PreDestroy public void shutdown() throws Exception { - cleanupIndex( ); + cleanupIndex(); } @@ -71,7 +76,7 @@ public class MavenIndexerCleaner WebApplicationContext wacu = WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() ); plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class ); - cleanupIndex( ); + cleanupIndex(); } catch ( Exception e ) @@ -85,7 +90,7 @@ public class MavenIndexerCleaner { try { - cleanupIndex( ); + cleanupIndex(); } catch ( Exception e ) @@ -95,7 +100,7 @@ public class MavenIndexerCleaner } } - public void cleanupIndex( ) + public void cleanupIndex() throws Exception { log.info( "cleanup IndexingContext" ); @@ -104,6 +109,21 @@ public class MavenIndexerCleaner { nexusIndexer.removeIndexingContext( context, true ); } + + /* + try + { + NativeFSLockFactory nativeFSLockFactory = + new NativeFSLockFactory( new File( "target/appserver-base/data/repositories/internal/.indexer" ) ); + Lock lock = nativeFSLockFactory.makeLock( "write.lock" ); + lock.release(); + log.info( "cleanup lock" ); + } + catch ( LockReleaseFailedException e ) + { + // ignore + }*/ + } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/repository-servlet-simple.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/repository-servlet-simple.xml index 4f95eaecb..f5e849df4 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/repository-servlet-simple.xml +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/repository-servlet-simple.xml @@ -43,7 +43,7 @@ - diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml index 62a91b38e..2e69792f9 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml @@ -59,7 +59,7 @@ - diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context.xml index caa12b018..5f23fe716 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context.xml @@ -58,7 +58,7 @@ - diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/webapp/WEB-INF/web.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/webapp/WEB-INF/web.xml index 0a0b0f9ac..54dc1b705 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/webapp/WEB-INF/web.xml +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/webapp/WEB-INF/web.xml @@ -27,6 +27,9 @@ org.springframework.web.context.ContextLoaderListener + + org.apache.archiva.webdav.util.MavenIndexerCleaner + contextConfigLocation