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>
|
||||
<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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,7 +54,8 @@ public class MavenIndexerCleaner
|
|||
private ApplicationContext applicationContext;
|
||||
|
||||
@PostConstruct
|
||||
public void startup() throws Exception
|
||||
public void startup()
|
||||
throws Exception
|
||||
{
|
||||
plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
|
||||
cleanupIndex();
|
||||
|
@ -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
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue