* use testcontainers for cassandra test Signed-off-by: Olivier Lamy <olamy@apache.org>pull/81/head
@@ -91,6 +91,7 @@ | |||
<goal>shade</goal> | |||
</goals> | |||
<configuration> | |||
<createDependencyReducedPom>false</createDependencyReducedPom> | |||
<finalName>apache-archiva-cli-${project.version}</finalName> | |||
<transformers> | |||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> |
@@ -24,7 +24,7 @@ under the License. | |||
xmlns="http://maven.apache.org/SETTINGS/1.0.0"> | |||
<mirrors> | |||
<mirror> | |||
<mirrorOf>external:*</mirrorOf> | |||
<mirrorOf>external:*,!central</mirrorOf> | |||
<id>local-mirror</id> | |||
<name>local-mirror</name> | |||
<url>@localRepositoryUrl@</url> | |||
@@ -60,6 +60,16 @@ under the License. | |||
<enabled>true</enabled> | |||
</snapshots> | |||
</repository> | |||
<repository> | |||
<id>central</id> | |||
<url>https://repo.maven.apache.org/maven2</url> | |||
<releases> | |||
<enabled>true</enabled> | |||
</releases> | |||
<snapshots> | |||
<enabled>false</enabled> | |||
</snapshots> | |||
</repository> | |||
</repositories> | |||
<pluginRepositories> | |||
<pluginRepository> | |||
@@ -72,6 +82,16 @@ under the License. | |||
<enabled>true</enabled> | |||
</snapshots> | |||
</pluginRepository> | |||
<pluginRepository> | |||
<id>central</id> | |||
<url>https://repo.maven.apache.org/maven2</url> | |||
<releases> | |||
<enabled>true</enabled> | |||
</releases> | |||
<snapshots> | |||
<enabled>false</enabled> | |||
</snapshots> | |||
</pluginRepository> | |||
</pluginRepositories> | |||
</profile> | |||
</profiles> |
@@ -234,20 +234,14 @@ public abstract class AbstractMetadataRepositoryTest | |||
{ | |||
try ( RepositorySession session = getSessionFactory( ).createSession( ) ) | |||
{ | |||
tryAssert( ( ) -> { | |||
assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( ); | |||
} ); | |||
tryAssert( ( ) -> assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( )); | |||
getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE ); | |||
tryAssert( ( ) -> { | |||
assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains( | |||
TEST_NAMESPACE ).hasSize( 1 ); | |||
} ); | |||
tryAssert( ( ) -> assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ) | |||
.contains( TEST_NAMESPACE ).hasSize( 1 )); | |||
getRepository( ).removeNamespace( session, TEST_REPO_ID, TEST_NAMESPACE ); | |||
tryAssert( ( ) -> { | |||
assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( ); | |||
} ); | |||
tryAssert( ( ) -> assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( )); | |||
} | |||
} | |||
@@ -44,12 +44,6 @@ | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-repository-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-repository-api</artifactId> | |||
<classifier>tests</classifier> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-common</artifactId> | |||
@@ -79,7 +73,6 @@ | |||
<artifactId>metadata-model</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>jakarta.annotation</groupId> | |||
<artifactId>jakarta.annotation-api</artifactId> | |||
@@ -119,11 +112,11 @@ | |||
<version>${datastax.driver.version}</version> | |||
</dependency> | |||
<!-- TEST Scope --> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-api</artifactId> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-repository-api</artifactId> | |||
<classifier>tests</classifier> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
@@ -165,158 +158,32 @@ | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.logging.log4j</groupId> | |||
<artifactId>log4j-1.2-api</artifactId> | |||
<artifactId>log4j-core</artifactId> | |||
<version>${log4j.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-engine</artifactId> | |||
<groupId>org.testcontainers</groupId> | |||
<artifactId>cassandra</artifactId> | |||
<version>1.17.1</version> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<testResources> | |||
<testResource> | |||
<directory>src/test/filtered-resources</directory> | |||
<filtering>true</filtering> | |||
</testResource> | |||
</testResources> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.codehaus.mojo</groupId> | |||
<artifactId>build-helper-maven-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>reserve-ports</id> | |||
<phase>process-test-resources</phase> | |||
<goals> | |||
<goal>reserve-network-port</goal> | |||
</goals> | |||
<configuration> | |||
<portNames> | |||
<portName>cassandra.rpcPort</portName> | |||
<portName>cassandra.storagePort</portName> | |||
<portName>cassandra.stopPort</portName> | |||
<portName>cassandra.jmxPort</portName> | |||
<portName>cassandra.nativeTransportPort</portName> | |||
</portNames> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.codehaus.mojo</groupId> | |||
<artifactId>cassandra-maven-plugin</artifactId> | |||
<version>3.7-SNAPSHOT</version> | |||
<executions> | |||
<execution> | |||
<id>start-cassandra</id> | |||
<phase>pre-integration-test</phase> | |||
<goals> | |||
<goal>start</goal> | |||
</goals> | |||
<configuration> | |||
<nativeTransportPort>${cassandra.nativeTransportPort}</nativeTransportPort> | |||
<rpcPort>${cassandra.rpcPort}</rpcPort> | |||
<storagePort>${cassandra.storagePort}</storagePort> | |||
<stopPort>${cassandra.stopPort}</stopPort> | |||
<jmxPort>${cassandra.jmxPort}</jmxPort> | |||
<addMainClasspath>false</addMainClasspath> | |||
<addTestClasspath>false</addTestClasspath> | |||
<startWaitSeconds>500</startWaitSeconds> | |||
<startNativeTransport>true</startNativeTransport> | |||
<logLevel>INFO</logLevel> | |||
<loadAfterFirstStart>false</loadAfterFirstStart> | |||
<systemPropertyVariables> | |||
<cassandra.jmx.local.port>${cassandra.jmxPort}</cassandra.jmx.local.port> | |||
</systemPropertyVariables> | |||
<yaml><![CDATA[rpc_address: 127.0.0.1 | |||
broadcast_rpc_address: 127.0.0.1 | |||
listen_address: 127.0.0.1 | |||
auto_snapshot: false | |||
snapshot_before_compaction: false | |||
num_tokens: 1 | |||
]]></yaml> | |||
</configuration> | |||
</execution> | |||
<execution> | |||
<id>stop-cassandra</id> | |||
<phase>post-integration-test</phase> | |||
<goals> | |||
<goal>stop</goal> | |||
</goals> | |||
</execution> | |||
</executions> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.slf4j</groupId> | |||
<artifactId>slf4j-simple</artifactId> | |||
<version>${slf4j.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>net.java.dev.jna</groupId> | |||
<artifactId>jna</artifactId> | |||
<version>4.2.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.cassandra</groupId> | |||
<artifactId>cassandra-all</artifactId> | |||
<version>${cassandraVersion}</version> | |||
</dependency> | |||
</dependencies> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-failsafe-plugin</artifactId> | |||
<version>3.0.0-M5</version> | |||
<executions> | |||
<execution> | |||
<goals> | |||
<goal>integration-test</goal> | |||
<goal>verify</goal> | |||
</goals> | |||
</execution> | |||
</executions> | |||
<configuration> | |||
<includes> | |||
<include>**/*Test.java</include> | |||
</includes> | |||
<systemPropertyVariables> | |||
<cassandra.port>${cassandra.nativeTransportPort}</cassandra.port> | |||
<cassandra.host>127.0.0.1</cassandra.host> | |||
<archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id> | |||
<appserver.base>${project.build.directory}/appserver-base</appserver.base> | |||
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack> | |||
</systemPropertyVariables> | |||
<trimStackTrace>false</trimStackTrace> | |||
<skip>false</skip> | |||
<classesDirectory>${project.build.outputDirectory}</classesDirectory> | |||
</configuration> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-engine</artifactId> | |||
<version>${junit.jupiter.version}</version> | |||
</dependency> | |||
</dependencies> | |||
</plugin> | |||
</plugins> | |||
<pluginManagement> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-surefire-plugin</artifactId> | |||
<executions> | |||
</executions> | |||
<configuration> | |||
<skip>true</skip> | |||
<systemPropertyVariables> | |||
<archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id> | |||
<appserver.base>${project.build.directory}/appserver-base</appserver.base> | |||
<cassandraVersion>${cassandraVersion}</cassandraVersion> | |||
</systemPropertyVariables> | |||
</configuration> | |||
</plugin> | |||
@@ -326,7 +193,6 @@ num_tokens: 1 | |||
<configuration> | |||
<excludes> | |||
<exclude>src/cassandra/**</exclude> | |||
<exclude>src/test/resources/cassandra-test.yaml</exclude> | |||
</excludes> | |||
</configuration> | |||
</plugin> | |||
@@ -334,15 +200,4 @@ num_tokens: 1 | |||
</pluginManagement> | |||
</build> | |||
<profiles> | |||
<profile> | |||
<id>jdk9+</id> | |||
<activation> | |||
<jdk>[1.9,)</jdk> | |||
</activation> | |||
<properties > | |||
<cassandra.addJdk11Options>true</cassandra.addJdk11Options> | |||
</properties> | |||
</profile> | |||
</profiles> | |||
</project> |
@@ -182,7 +182,6 @@ public class DefaultCassandraArchivaManager | |||
hostNames.add( cassandraHost + ":" + cassandraPort ); | |||
configLoader = | |||
DriverConfigLoader.programmaticBuilder( ) | |||
.withStringList( DefaultDriverOption.CONTACT_POINTS, hostNames ) | |||
.withInt( DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, maxActive ) | |||
.withInt( DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE, maxActive ) |
@@ -27,13 +27,19 @@ import org.apache.archiva.metadata.repository.MetadataService; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel; | |||
import org.junit.jupiter.api.AfterAll; | |||
import org.junit.jupiter.api.AfterEach; | |||
import org.junit.jupiter.api.BeforeEach; | |||
import org.junit.jupiter.api.Test; | |||
import org.junit.jupiter.api.TestInfo; | |||
import org.junit.jupiter.api.TestInstance; | |||
import org.junit.jupiter.api.extension.ExtendWith; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.test.context.ContextConfiguration; | |||
import org.springframework.test.context.junit.jupiter.SpringExtension; | |||
import org.testcontainers.containers.CassandraContainer; | |||
import org.testcontainers.containers.output.Slf4jLogConsumer; | |||
import org.testcontainers.utility.DockerImageName; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
@@ -57,9 +63,13 @@ import static org.mockito.Mockito.when; | |||
*/ | |||
@ExtendWith( SpringExtension.class ) | |||
@TestInstance( TestInstance.Lifecycle.PER_CLASS ) | |||
@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml"} ) | |||
public class CassandraMetadataRepositoryTest | |||
extends AbstractMetadataRepositoryTest | |||
{ | |||
private static final Logger LOGGER = LoggerFactory.getLogger( CassandraMetadataRepositoryTest.class ); | |||
@Inject | |||
@Named(value = "archivaEntityManagerFactory#cassandra") | |||
CassandraArchivaManager cassandraArchivaManager; | |||
@@ -70,6 +80,19 @@ public class CassandraMetadataRepositoryTest | |||
RepositorySession session; | |||
private static final CassandraContainer CASSANDRA = | |||
new CassandraContainer(DockerImageName.parse("cassandra") | |||
.withTag(System.getProperty("cassandraVersion","3.11.2"))); | |||
// because of @ExtendWith( SpringExtension.class ) @BeforeAll will not be executed before spring resolution so need to use this... | |||
static { | |||
LOGGER.info("initCassandra"); | |||
CASSANDRA.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("org.apache.archiva.metadata.repository.cassandra.logs"))); | |||
CASSANDRA.start(); | |||
System.setProperty("cassandra.host", CASSANDRA.getHost()); | |||
System.setProperty("cassandra.port", CASSANDRA.getMappedPort(9042).toString()); | |||
} | |||
long cTime; | |||
int testNum = 0; | |||
final AtomicBoolean clearedTables = new AtomicBoolean( false ); | |||
@@ -87,8 +110,15 @@ public class CassandraMetadataRepositoryTest | |||
return cmr; | |||
} | |||
@AfterAll | |||
public static void stopCassandra() | |||
throws Exception { | |||
CASSANDRA.close(); | |||
} | |||
@BeforeEach | |||
public void setUp( TestInfo testInfo ) | |||
@Override | |||
public void setUp() | |||
throws Exception | |||
{ | |||
cTime = System.currentTimeMillis( ); | |||
@@ -152,7 +182,7 @@ public class CassandraMetadataRepositoryTest | |||
@AfterEach | |||
public void shutdown(TestInfo testInfo) | |||
public void shutdown() | |||
throws Exception | |||
{ | |||
clearReposAndNamespace( cassandraArchivaManager, clearedTables ); | |||
@@ -177,7 +207,8 @@ public class CassandraMetadataRepositoryTest | |||
cassandraArchivaManager.getLicenseFamilyName( ), | |||
cassandraArchivaManager.getDependencyFamilyName( ) | |||
); | |||
CompletableFuture.allOf( tables.stream( ).map( table -> session.executeAsync( truncate( table ).build( ) ) ) | |||
CompletableFuture.allOf(tables.stream() | |||
.map(table -> session.executeAsync(truncate(table).build())) | |||
.map( CompletionStage::toCompletableFuture ).collect( Collectors.toList( ) ).toArray( new CompletableFuture[0] ) ) | |||
.whenComplete( ( c, e ) -> { | |||
if ( clearedFlag != null ) clearedFlag.set( true ); |
@@ -22,7 +22,9 @@ package org.apache.archiva.metadata.repository.cassandra; | |||
import org.apache.archiva.metadata.model.ProjectMetadata; | |||
import org.apache.archiva.metadata.repository.cassandra.model.Namespace; | |||
import org.apache.archiva.metadata.repository.cassandra.model.Repository; | |||
import org.junit.jupiter.api.AfterAll; | |||
import org.junit.jupiter.api.AfterEach; | |||
import org.junit.jupiter.api.BeforeAll; | |||
import org.junit.jupiter.api.BeforeEach; | |||
import org.junit.jupiter.api.Test; | |||
import org.junit.jupiter.api.extension.ExtendWith; | |||
@@ -30,6 +32,9 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.test.context.ContextConfiguration; | |||
import org.springframework.test.context.junit.jupiter.SpringExtension; | |||
import org.testcontainers.containers.CassandraContainer; | |||
import org.testcontainers.containers.output.Slf4jLogConsumer; | |||
import org.testcontainers.utility.DockerImageName; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
@@ -40,19 +45,37 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
* @author Olivier Lamy | |||
*/ | |||
@ExtendWith( SpringExtension.class ) | |||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) | |||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml" } ) | |||
public class RepositoriesNamespaceTest | |||
{ | |||
private Logger logger = LoggerFactory.getLogger( getClass() ); | |||
private static final Logger LOGGER = LoggerFactory.getLogger( RepositoriesNamespaceTest.class ); | |||
private static final CassandraContainer CASSANDRA = | |||
new CassandraContainer(DockerImageName.parse("cassandra") | |||
.withTag(System.getProperty("cassandraVersion","3.11.2"))); | |||
@Inject | |||
@Named( value = "archivaEntityManagerFactory#cassandra" ) | |||
CassandraArchivaManager cassandraArchivaManager; | |||
CassandraMetadataRepository cmr; | |||
@BeforeAll | |||
public static void initCassandra() | |||
throws Exception { | |||
CASSANDRA.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("org.apache.archiva.metadata.repository.cassandra.logs"))); | |||
CASSANDRA.start(); | |||
System.setProperty("cassandra.host", CASSANDRA.getHost()); | |||
System.setProperty("cassandra.port", CASSANDRA.getMappedPort(9042).toString()); | |||
} | |||
@AfterAll | |||
public static void stopCassandra() | |||
throws Exception { | |||
CASSANDRA.close(); | |||
} | |||
@BeforeEach | |||
public void setup() | |||
throws Exception | |||
@@ -131,7 +154,7 @@ public class RepositoriesNamespaceTest | |||
} | |||
catch ( Exception e ) | |||
{ | |||
logger.error( e.getMessage(), e ); | |||
LOGGER.error( e.getMessage(), e ); | |||
throw e; | |||
} | |||
finally |
@@ -19,23 +19,16 @@ | |||
--> | |||
<configuration status="debug"> | |||
<configuration> | |||
<appenders> | |||
<Console name="console" target="SYSTEM_OUT"> | |||
<!--PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/--> | |||
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" /> | |||
</Console> | |||
</appenders> | |||
<loggers> | |||
<logger name="org.apache.archiva.metadata.repository.cassandra" level="debug"/> | |||
<root level="debug" includeLocation="true"> | |||
<logger name="org.apache.archiva.metadata.repository.cassandra" level="info"/> | |||
<logger name="org.apache.archiva.metadata.repository.cassandra.logs" level="error"/> | |||
<root level="info" includeLocation="true"> | |||
<appender-ref ref="console"/> | |||
</root> | |||
</loggers> |
@@ -19,7 +19,7 @@ | |||
--> | |||
<configuration status="debug"> | |||
<configuration> | |||
<appenders> | |||
<Console name="console" target="SYSTEM_OUT"> |
@@ -182,7 +182,6 @@ | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-shade-plugin</artifactId> | |||
<version>3.2.4</version> | |||
<executions> | |||
<!-- Run shade goal on package phase --> | |||
<execution> | |||
@@ -191,6 +190,7 @@ | |||
<goal>shade</goal> | |||
</goals> | |||
<configuration> | |||
<createDependencyReducedPom>false</createDependencyReducedPom> | |||
<filters> | |||
<filter> | |||
<artifact>*:*</artifact> |
@@ -1824,28 +1824,36 @@ | |||
</dependency> | |||
<!-- JUNIT 5 --> | |||
<dependency> | |||
<groupId>org.junit.platform</groupId> | |||
<artifactId>junit-platform-launcher</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.platform</groupId> | |||
<artifactId>junit-platform-console-standalone</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-engine</artifactId> | |||
<artifactId>junit-jupiter-api</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<dependency> | |||
<groupId>org.junit.vintage</groupId> | |||
<artifactId>junit-vintage-engine</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<!-- <dependency>--> | |||
<!-- <groupId>org.junit.platform</groupId>--> | |||
<!-- <artifactId>junit-platform-launcher</artifactId>--> | |||
<!-- <scope>test</scope>--> | |||
<!-- </dependency>--> | |||
<!-- <dependency>--> | |||
<!-- <groupId>org.junit.platform</groupId>--> | |||
<!-- <artifactId>junit-platform-console-standalone</artifactId>--> | |||
<!-- <scope>test</scope>--> | |||
<!-- </dependency>--> | |||
<!-- <dependency>--> | |||
<!-- <groupId>org.junit.jupiter</groupId>--> | |||
<!-- <artifactId>junit-jupiter-engine</artifactId>--> | |||
<!-- <scope>test</scope>--> | |||
<!-- </dependency>--> | |||
<!-- <dependency>--> | |||
<!-- <groupId>org.junit.vintage</groupId>--> | |||
<!-- <artifactId>junit-vintage-engine</artifactId>--> | |||
<!-- <scope>test</scope>--> | |||
<!-- </dependency>--> | |||
</dependencies> | |||