You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@toree.apache.org by Jakob Odersky <ja...@odersky.com> on 2017/02/11 22:45:13 UTC

Classloader exceptions when testing

Hi everyone,

I may have found a fix for the classloader issues I'm having when
running unit tests
(https://groups.google.com/forum/#!topic/akka-user/U0mLX3mCmAk).
Basically the issue appears to happen when a test suite that uses the
Akka TestKit base class does not define an explicit classloader.

I.e. the following will result in a cryptic error:

class ExecuteRequestHandlerSpec extends TestKit(
  ActorSystem("ExecuteRequestHandlerSpec")) { //tests }

whereas explicitly defining a classloader for the actor system works fine:

class ExecuteRequestHandlerSpec extends TestKit(
  ActorSystem("ExecuteRequestHandlerSpec",
    org.apache.toree.Main.getClass.getClassLoader)) { //tests }

I have seen that latter approach used in various tests, however the
classloaders are not specified consistently in all tests. My proposed
approach to fixing the tests is to make classloaders explicit
everywhere (thinking about creating a utility mixin, instead of using
TestKit directly).

I'm not very well versed in all the class loader magic that happens
within Spark, Akka and sbt, and would greatly appreciate any input as
to why the exceptions are raised in the first place and whether my
proposal is actually a clean fix or just some quick hack.

cheers,
--Jakob

Re: Classloader exceptions when testing

Posted by Marius van Niekerk <ma...@gmail.com>.
That's great news.

I recall some other parts of Akka where migrating the code to spark 2.0 /
scala 2.11 required specifying a bunch of classloaders in the source.

On Sat, 11 Feb 2017 at 17:45 Jakob Odersky <ja...@odersky.com> wrote:

> Hi everyone,
>
> I may have found a fix for the classloader issues I'm having when
> running unit tests
> (https://groups.google.com/forum/#!topic/akka-user/U0mLX3mCmAk).
> Basically the issue appears to happen when a test suite that uses the
> Akka TestKit base class does not define an explicit classloader.
>
> I.e. the following will result in a cryptic error:
>
> class ExecuteRequestHandlerSpec extends TestKit(
>   ActorSystem("ExecuteRequestHandlerSpec")) { //tests }
>
> whereas explicitly defining a classloader for the actor system works fine:
>
> class ExecuteRequestHandlerSpec extends TestKit(
>   ActorSystem("ExecuteRequestHandlerSpec",
>     org.apache.toree.Main.getClass.getClassLoader)) { //tests }
>
> I have seen that latter approach used in various tests, however the
> classloaders are not specified consistently in all tests. My proposed
> approach to fixing the tests is to make classloaders explicit
> everywhere (thinking about creating a utility mixin, instead of using
> TestKit directly).
>
> I'm not very well versed in all the class loader magic that happens
> within Spark, Akka and sbt, and would greatly appreciate any input as
> to why the exceptions are raised in the first place and whether my
> proposal is actually a clean fix or just some quick hack.
>
> cheers,
> --Jakob
>
-- 
regards
Marius van Niekerk