]> source.dussan.org Git - archiva.git/commitdiff
avoid lucene lock issues with starting spring container with no repositories
authorOlivier Lamy <olamy@apache.org>
Fri, 4 Nov 2011 13:51:54 +0000 (13:51 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 4 Nov 2011 13:51:54 +0000 (13:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197569 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/pom.xml
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/util/MavenIndexerCleaner.java
archiva-modules/archiva-web/archiva-webdav/src/test/resources/repository-servlet-simple.xml
archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml
archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context.xml
archiva-modules/archiva-web/archiva-webdav/src/test/webapp/WEB-INF/web.xml

index 5c301b0231f93bbc2e899321d25fc875f785b017..693ec98d5f4cfe680c99bd666124ea40e70b0526 100644 (file)
             <appserver.base>${project.build.directory}/appserver-base</appserver.base>
             <plexus.home>${project.build.directory}/appserver-base</plexus.home>
             <derby.system.home>${project.build.directory}/appserver-base</derby.system.home>
+            <test.resources.path>${project.build.testOutputDirectory}</test.resources.path>
+            <redback.jdbc.url>jdbc:derby:memory:users-test;create=true</redback.jdbc.url>
+            <redback.jdbc.driver.name>org.apache.derby.jdbc.EmbeddedDriver</redback.jdbc.driver.name>
           </systemPropertyVariables>
           <forkMode>${webdav.forkMode}</forkMode>
         </configuration>
index 8ae24a9eea2115f1149ed39b0eda863796199cbc..653e5bb672b2fcece22c9c6f276946d45bbd9f72 100644 (file)
@@ -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();
index a2bf649caac4ccf50bd70ce11249d6d691d2845a..54db5c91586de895f116e0cf0d50dcdc2b0195c2 100644 (file)
@@ -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
+        }*/
+
     }
 
 
index 4f95eaecb36dd7eabae2ab5e5ce3b26bd0eb6937..f5e849df42749b26c1c32e5cdf3afbb3b2aaee35 100644 (file)
@@ -43,7 +43,7 @@
         <![CDATA[
         <configuration>
           <system/>
-          <xml fileName="${appserver.base}/conf/archiva.xml" config-forceCreate="true"
+          <xml fileName="${test.resources.path}/repository-archiva.xml" config-forceCreate="true"
                config-optional="true"
                config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
         </configuration>
index 62a91b38e806a41a2092a51f8952ec67b39afe65..2e69792f9943abe0cf922b57a91ebc043eba52f3 100644 (file)
@@ -59,7 +59,7 @@
         <![CDATA[
         <configuration>
           <system/>
-          <xml fileName="${appserver.base}/conf/archiva.xml" config-forceCreate="true"
+          <xml fileName="${test.resources.path}/repository-archiva.xml" config-forceCreate="true"
                config-optional="true"
                config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
         </configuration>
index caa12b018cd41af09e32d3e2298f1a7eb1753697..5f23fe716447ab2a7337f6d6a3423ba22dd027d9 100644 (file)
@@ -58,7 +58,7 @@
         <![CDATA[
         <configuration>
           <system/>
-          <xml fileName="${appserver.base}/conf/archiva.xml" config-forceCreate="true"
+          <xml fileName="${test.resources.path}/repository-archiva.xml" config-forceCreate="true"
                config-optional="true"
                config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
         </configuration>
index 0a0b0f9ac064489d0d975b673363e97e15064d0d..54dc1b70598bc8aed963bc5685a72b1452a61b44 100644 (file)
@@ -27,6 +27,9 @@
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
+  <listener>
+    <listener-class>org.apache.archiva.webdav.util.MavenIndexerCleaner</listener-class>
+  </listener>
 
   <context-param>
     <param-name>contextConfigLocation</param-name>