Permalink
Browse files

Re-enable Nexus proxy tests, launch the mirrors from the tests

  • Loading branch information...
alexarchambault committed Mar 16, 2018
1 parent 0679645 commit f8884d4170243063e6b52870dc554312395042b7
View
@@ -67,7 +67,10 @@ lazy val `proxy-tests` = project
dontPublish,
hasITs,
coursierPrefix,
libs += Deps.scalaAsync.value,
libs ++= Seq(
Deps.dockerClient,
Deps.scalaAsync.value
),
utest,
sharedTestResources
)
View
@@ -16,6 +16,7 @@ object Deps {
def jackson = "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.8.4"
def scalatest = "org.scalatest" %% "scalatest" % "3.0.0"
def junit = "junit" % "junit" % "4.12"
def dockerClient = "com.spotify" % "docker-client" % "8.11.1"
def sbtPgp = Def.setting {
val sbtv = CrossVersion.binarySbtVersion(sbtVersion.in(pluginCrossBuild).value)
@@ -0,0 +1,11 @@
package coursier.test
object CentralNexus2ProxyTests extends CentralTests {
val repo = NexusDocker("sonatype/nexus:2.14.4", "nexus/content/repositories/central", 9081)
override def utestAfterAll(): Unit =
repo.shutdown()
override def centralBase = repo.base
}
@@ -0,0 +1,15 @@
package coursier.test
object CentralNexus3ProxyTests extends CentralTests {
val repo = NexusDocker(
"sonatype/nexus3:3.3.1",
"repository/maven-central/", // 400 error without the trailing '/'
9082
)
override def utestAfterAll(): Unit =
repo.shutdown()
override def centralBase = repo.base.stripSuffix("/")
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,96 @@
package coursier.test
import java.io.InputStream
import com.spotify.docker.client.DefaultDockerClient
import com.spotify.docker.client.messages.{ContainerConfig, HostConfig, PortBinding}
import coursier.internal.FileUtil
import scala.annotation.tailrec
import scala.collection.JavaConverters._
import scala.concurrent.duration.DurationInt
import scala.util.Try
final case class NexusDocker(base: String, shutdown: () => Unit)
object NexusDocker {
def apply(
image: String,
basePath: String,
// can't find a way to get back a randomly assigned port (even following https://github.com/spotify/docker-client/issues/625)
// so that one has to be specified
hostPort: Int
): NexusDocker = {
val addr = s"localhost:$hostPort"
def log(s: String): Unit =
Console.err.println(s"[$image @ $addr] $s")
val docker = DefaultDockerClient.fromEnv().build()
docker.pull(image)
val portBindings = Map("8081" -> Seq(PortBinding.of("0.0.0.0", hostPort)).asJava)
val hostConfig = HostConfig.builder().portBindings(portBindings.asJava).build()
val containerConfig = ContainerConfig.builder()
.hostConfig(hostConfig)
.image(image)
.exposedPorts(portBindings.keys.toSeq: _*)
.build()
var idOpt = Option.empty[String]
def shutdown(): Unit =
for (id <- idOpt) {
Try(docker.killContainer(id))
docker.removeContainer(id)
docker.close()
}
try {
val creation = docker.createContainer(containerConfig)
val id = creation.id()
idOpt = Some(id)
log(s"starting container $id")
docker.startContainer(id)
val base: String =
s"http://localhost:$hostPort/$basePath"
log(s"waiting for nexus server to be up-and-running")
val retryDuration = 2.seconds
@tailrec
def loop(retry: Int): Unit =
if (retry > 0) {
val url = new java.net.URL(base)
var is: InputStream = null
try {
is = url.openStream()
FileUtil.readFully(is)
log("nexus up")
} catch {
case e: java.io.IOException =>
if (is != null) is.close()
log(s"Caught $e, retrying in $retryDuration")
Thread.sleep(retryDuration.toMillis)
loop(retry - 1)
}
} else
throw new Exception(s"Timeout when waiting for container for $image to be up-and-running")
loop(60)
NexusDocker(base, () => shutdown())
} catch {
case t: Throwable =>
shutdown()
throw t
}
}
}
View

This file was deleted.

Oops, something went wrong.
View
@@ -39,12 +39,6 @@ launchTestRepo() {
./scripts/launch-test-repo.sh "$@"
}
launchProxyRepos() {
if [ "$(uname)" != "Darwin" ]; then
./scripts/launch-proxies.sh
fi
}
integrationTestsRequirements() {
# Required for ~/.ivy2/local repo tests
sbt ++2.11.12 coreJVM/publishLocal ++2.12.4 cli/publishLocal
@@ -189,9 +183,6 @@ else
runSbtShadingTests
fi
else
# Required for the proxy tests (currently CentralNexus2ProxyTests and CentralNexus3ProxyTests)
launchProxyRepos
runJvmTests
testBootstrap
@@ -18,7 +18,7 @@ abstract class CentralTests extends TestSuite {
final def isActualCentral = centralBase == "https://repo1.maven.org/maven2"
val repositories = Seq[Repository](
lazy val repositories = Seq[Repository](
MavenRepository(centralBase)
)

0 comments on commit f8884d4

Please sign in to comment.