mirror of https://github.com/apache/archiva.git
[MRM-1750] Add remote repository health check
add unit test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1552982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
84bcc48e6b
commit
0c9fab3b3b
|
@ -402,18 +402,26 @@
|
|||
<version>${tomcat7Version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
<version>${tomcat7Version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-metadata-consumer</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.apache.maven.wagon.authorization.AuthorizationException;
|
|||
import org.apache.maven.wagon.providers.http.AbstractHttpClientWagon;
|
||||
import org.apache.maven.wagon.providers.http.HttpConfiguration;
|
||||
import org.apache.maven.wagon.providers.http.HttpMethodConfiguration;
|
||||
import org.apache.maven.wagon.providers.http.HttpWagon;
|
||||
import org.apache.maven.wagon.repository.Repository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -170,7 +172,7 @@ public class DefaultRemoteRepositoriesService
|
|||
|
||||
wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
|
||||
wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
|
||||
|
||||
HttpWagon foo;
|
||||
if ( wagon instanceof AbstractHttpClientWagon )
|
||||
{
|
||||
HttpConfiguration httpConfiguration = new HttpConfiguration();
|
||||
|
@ -181,37 +183,14 @@ public class DefaultRemoteRepositoriesService
|
|||
AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
|
||||
}
|
||||
|
||||
wagon.connect( new Repository( remoteRepository.getId(), remoteRepository.getUrl() ) );
|
||||
|
||||
// we only check connectivity as remote repo can be empty
|
||||
wagon.getFileList( "/" );
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
catch ( MalformedURLException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
catch ( WagonFactoryException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
catch ( AuthorizationException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
|
|
|
@ -167,4 +167,6 @@ public class ManagedRepositoriesServiceTest
|
|||
|
||||
deleteTestRepo( testRepoId );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -152,5 +152,4 @@ public class RemoteRepositoriesServiceTest
|
|||
"cool repo" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -124,8 +124,6 @@ public class DownloadArtifactsTest
|
|||
this.redirectPort = redirectServer.getConnectors()[0].getLocalPort();
|
||||
log.info( "redirect server port {}", redirectPort );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.archiva;
|
||||
package org.apache.archiva.remotedownload;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -21,7 +21,6 @@ package org.apache.archiva;
|
|||
|
||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
||||
import org.apache.archiva.redback.rest.api.services.RoleManagementService;
|
||||
import org.apache.archiva.remotedownload.AbstractDownloadTest;
|
||||
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
||||
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
|
|
@ -0,0 +1,142 @@
|
|||
package org.apache.archiva;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import org.apache.archiva.admin.model.beans.RemoteRepository;
|
||||
import org.apache.archiva.remotedownload.AbstractDownloadTest;
|
||||
import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.cxf.jaxrs.client.WebClient;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
public class RemoteRepositoryConnectivityCheckTest
|
||||
extends AbstractDownloadTest
|
||||
{
|
||||
|
||||
@BeforeClass
|
||||
public static void setAppServerBase()
|
||||
{
|
||||
previousAppServerBase = System.getProperty( "appserver.base" );
|
||||
System.setProperty( "appserver.base", "target/" + RemoteRepositoryConnectivityCheckTest.class.getName() );
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void resetAppServerBase()
|
||||
{
|
||||
System.setProperty( "appserver.base", previousAppServerBase );
|
||||
}
|
||||
|
||||
protected String getSpringConfigLocation()
|
||||
{
|
||||
return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRemoteConnectivity()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
Server repoServer =
|
||||
buildStaticServer( new File( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ) );
|
||||
repoServer.start();
|
||||
|
||||
RemoteRepositoriesService service = getRemoteRepositoriesService();
|
||||
|
||||
WebClient.client( service ).header( "Authorization", authorizationHeader );
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
|
||||
|
||||
RemoteRepository repo = getRemoteRepository();
|
||||
|
||||
repo.setUrl( "http://localhost:" + repoServerPort );
|
||||
|
||||
service.addRemoteRepository( repo );
|
||||
|
||||
service.checkRemoteConnectivity( repo.getId() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
service.deleteRemoteRepository( "id-new" );
|
||||
repoServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRemoteConnectivityEmptyRemote()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
File tmpDir = Files.createTempDir();
|
||||
Server repoServer = buildStaticServer( tmpDir );
|
||||
repoServer.start();
|
||||
|
||||
RemoteRepositoriesService service = getRemoteRepositoriesService();
|
||||
|
||||
WebClient.client( service ).header( "Authorization", authorizationHeader );
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
|
||||
|
||||
RemoteRepository repo = getRemoteRepository();
|
||||
|
||||
repo.setUrl( "http://localhost:" + repoServerPort );
|
||||
|
||||
service.addRemoteRepository( repo );
|
||||
|
||||
service.checkRemoteConnectivity( repo.getId() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
service.deleteRemoteRepository( "id-new" );
|
||||
FileUtils.deleteQuietly( tmpDir );
|
||||
repoServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
protected Server buildStaticServer( File path )
|
||||
{
|
||||
Server repoServer = new Server( 0 );
|
||||
|
||||
ResourceHandler resourceHandler = new ResourceHandler();
|
||||
resourceHandler.setDirectoriesListed( true );
|
||||
resourceHandler.setWelcomeFiles( new String[]{ "index.html" } );
|
||||
resourceHandler.setResourceBase( path.getAbsolutePath() );
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
|
||||
repoServer.setHandler( handlers );
|
||||
|
||||
return repoServer;
|
||||
}
|
||||
|
||||
|
||||
RemoteRepository getRemoteRepository()
|
||||
{
|
||||
return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,
|
||||
"cool repo" );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue