mirror of https://github.com/apache/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
This commit is contained in:
parent
1f57d52fa4
commit
840cabb0fb
|
@ -197,6 +197,9 @@
|
||||||
<appserver.base>${project.build.directory}/appserver-base</appserver.base>
|
<appserver.base>${project.build.directory}/appserver-base</appserver.base>
|
||||||
<plexus.home>${project.build.directory}/appserver-base</plexus.home>
|
<plexus.home>${project.build.directory}/appserver-base</plexus.home>
|
||||||
<derby.system.home>${project.build.directory}/appserver-base</derby.system.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>
|
</systemPropertyVariables>
|
||||||
<forkMode>${webdav.forkMode}</forkMode>
|
<forkMode>${webdav.forkMode}</forkMode>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -27,16 +27,18 @@ import junit.framework.Assert;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
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.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
|
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.archiva.webdav.util.MavenIndexerCleaner;
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
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.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -48,6 +50,8 @@ import javax.inject.Inject;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractRepositoryServletTestCase
|
* AbstractRepositoryServletTestCase
|
||||||
|
@ -85,11 +89,47 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
saveConfiguration( archivaConfiguration );
|
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
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
lockCleanup();
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
String appserverBase = new File( "target/appserver-base" ).getAbsolutePath();
|
String appserverBase = new File( "target/appserver-base" ).getAbsolutePath();
|
||||||
|
@ -105,7 +145,6 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
|
|
||||||
archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
|
archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
|
||||||
|
|
||||||
//archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
|
||||||
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
|
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
|
||||||
repoRootLegacy = new File( appserverBase, "data/repositories/legacy" );
|
repoRootLegacy = new File( appserverBase, "data/repositories/legacy" );
|
||||||
Configuration config = archivaConfiguration.getConfiguration();
|
Configuration config = archivaConfiguration.getConfiguration();
|
||||||
|
@ -128,6 +167,8 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
|
|
||||||
HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
|
HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
|
||||||
|
|
||||||
|
applicationContext.getBean( MavenIndexerCleaner.class ).cleanupIndex();
|
||||||
|
|
||||||
sr = new ServletRunner( new File( "src/test/resources/WEB-INF/web.xml" ) );
|
sr = new ServletRunner( new File( "src/test/resources/WEB-INF/web.xml" ) );
|
||||||
|
|
||||||
sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
|
sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
|
||||||
|
@ -140,7 +181,6 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if ( sc != null )
|
if ( sc != null )
|
||||||
{
|
{
|
||||||
sc.clearContents();
|
sc.clearContents();
|
||||||
|
|
|
@ -19,6 +19,9 @@ package org.apache.archiva.webdav.util;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
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.NexusIndexer;
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -33,6 +36,7 @@ import javax.annotation.PreDestroy;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -50,17 +54,18 @@ public class MavenIndexerCleaner
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void startup() throws Exception
|
public void startup()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
|
plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
|
||||||
cleanupIndex( );
|
cleanupIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
cleanupIndex( );
|
cleanupIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +76,7 @@ public class MavenIndexerCleaner
|
||||||
WebApplicationContext wacu =
|
WebApplicationContext wacu =
|
||||||
WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() );
|
WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() );
|
||||||
plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class );
|
plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class );
|
||||||
cleanupIndex( );
|
cleanupIndex();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
|
@ -85,7 +90,7 @@ public class MavenIndexerCleaner
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cleanupIndex( );
|
cleanupIndex();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
|
@ -95,7 +100,7 @@ public class MavenIndexerCleaner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanupIndex( )
|
public void cleanupIndex()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
log.info( "cleanup IndexingContext" );
|
log.info( "cleanup IndexingContext" );
|
||||||
|
@ -104,6 +109,21 @@ public class MavenIndexerCleaner
|
||||||
{
|
{
|
||||||
nexusIndexer.removeIndexingContext( context, true );
|
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
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<configuration>
|
<configuration>
|
||||||
<system/>
|
<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-optional="true"
|
||||||
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<configuration>
|
<configuration>
|
||||||
<system/>
|
<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-optional="true"
|
||||||
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<configuration>
|
<configuration>
|
||||||
<system/>
|
<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-optional="true"
|
||||||
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
<listener>
|
||||||
|
<listener-class>org.apache.archiva.webdav.util.MavenIndexerCleaner</listener-class>
|
||||||
|
</listener>
|
||||||
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextConfigLocation</param-name>
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
|
Loading…
Reference in New Issue