Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException Being Thrown Failing Tests #109

Open
ChristopherDavenport opened this issue Jan 25, 2018 · 1 comment
Open

ClassNotFoundException Being Thrown Failing Tests #109

ChristopherDavenport opened this issue Jan 25, 2018 · 1 comment

Comments

@ChristopherDavenport
Copy link

Running from the example for Postgres I am getting a ClassNotFoundException. I have tried both Specs2 and ScalaTest and get the same results.

Any insights?

StackTrace:

[info] com.banno.transaction.exporter.history.PostgresServiceSpec *** ABORTED ***
[info]   java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
[info]   at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
[info]   at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
[info]   at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)
[info]   at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80)
[info]   at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:81)
[info]   at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:297)
[info]   at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:76)
[info]   at com.spotify.docker.client.DefaultDockerClient.resource(DefaultDockerClient.java:2602)
[info]   at com.spotify.docker.client.DefaultDockerClient.listImages(DefaultDockerClient.java:624)
[info]   at com.whisk.docker.impl.spotify.SpotifyDockerCommandExecutor.$anonfun$listImages$1(SpotifyDockerCommandExecutor.scala:184)

TestCode:

import java.sql.DriverManager

import scala.concurrent.ExecutionContext
import scala.util.Try
import com.whisk.docker._

trait DockerPostgresService extends DockerKit {
  import scala.concurrent.duration._
  import DockerPostgresService._
  def PostgresAdvertisedPort = 5432
  def PostgresExposedPort = 44444
  val PostgresUser = "nph"
  val PostgresPassword = "suitup"

  val postgresContainer = DockerContainer("postgres:9.5.3")
    .withPorts((PostgresAdvertisedPort, Some(PostgresExposedPort)))
    .withEnv(s"POSTGRES_USER=$PostgresUser", s"POSTGRES_PASSWORD=$PostgresPassword")
    .withReadyChecker(
      new PostgresReadyChecker(PostgresUser, PostgresPassword, Some(PostgresExposedPort))
        .looped(15, 1.second)
    )

  abstract override def dockerContainers: List[DockerContainer] =
    postgresContainer :: super.dockerContainers
}

object DockerPostgresService {
  class PostgresReadyChecker(user: String, password: String, port: Option[Int] = None)
    extends DockerReadyChecker {

    override def apply(container: DockerContainerState)
                      (implicit docker: DockerCommandExecutor,
                       ec: ExecutionContext) =
      container
        .getPorts()
        .map(ports =>
          Try {
            Class.forName("org.postgresql.Driver")
            val url = s"jdbc:postgresql://${docker.host}:${port.getOrElse(ports.values.head)}/"
            Option(DriverManager.getConnection(url, user, password)).map(_.close).isDefined
          }.getOrElse(false))
  }


}

import com.whisk.docker.DockerKit
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time._
import org.scalatest.{BeforeAndAfterAll, Suite}
//import org.slf4j.LoggerFactory

trait DockerTestKit extends BeforeAndAfterAll with ScalaFutures with DockerKit { self: Suite =>

//  private lazy val log = LoggerFactory.getLogger(this.getClass)

  def dockerInitPatienceInterval =
    PatienceConfig(scaled(Span(20, Seconds)), scaled(Span(10, Millis)))

  def dockerPullImagesPatienceInterval =
    PatienceConfig(scaled(Span(1200, Seconds)), scaled(Span(250, Millis)))

  override def beforeAll(): Unit = {
    super.beforeAll()
    startAllOrFail()
  }

  override def afterAll(): Unit = {
    stopAllQuietly()
    super.afterAll()

  }
}

import com.spotify.docker.client.DefaultDockerClient
import com.whisk.docker.impl.spotify.SpotifyDockerFactory
import org.scalatest.time.{Second, Seconds, Span}
import org.scalatest.{FlatSpec, Matchers}

class PostgresServiceSpec
  extends FlatSpec
    with Matchers
    with DockerTestKit
    with DockerPostgresService {

  implicit val pc = PatienceConfig(Span(20, Seconds), Span(1, Second))

  override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(
    DefaultDockerClient.fromEnv().build())

  "postgres node" should "be ready with log line checker" in {
    isContainerReady(postgresContainer).futureValue shouldBe true
  }
}
@AlexITC
Copy link

AlexITC commented Jun 12, 2018

From what I have saw, this is probably related to a problem with another dependency, I got a similar exception while adding the elastic4s dependency:

[info]   java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
[info]   at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
[info]   at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
[info]   at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)
[info]   at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80)
[info]   at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:81)
[info]   at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:297)
[info]   at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:76)
[info]   at com.spotify.docker.client.DefaultDockerClient.resource(DefaultDockerClient.java:2599)
[info]   at com.spotify.docker.client.DefaultDockerClient.listImages(DefaultDockerClient.java:621)
[info]   at com.whisk.docker.impl.spotify.SpotifyDockerCommandExecutor$$anonfun$listImages$1.apply(SpotifyDockerCommandExecutor.scala:187)
[info]   ...
[info]   Cause: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
[info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info]   at java.lang.Class.forName0(Native Method)
[info]   at java.lang.Class.forName(Class.java:264)
[info]   at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:62)
[info]   at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:155)
[info]   at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105)
[info]   at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
[info]   at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants