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

JUnit dependency in com.hazelcast.test.mocknetwork.MockJoiner #8868

Closed
rvanheest opened this issue Sep 12, 2016 · 4 comments
Closed

JUnit dependency in com.hazelcast.test.mocknetwork.MockJoiner #8868

rvanheest opened this issue Sep 12, 2016 · 4 comments

Comments

@rvanheest
Copy link

I came across the testing/mocking framework that you provided in the hazelcast library. So I just started to use new TestHazelcastInstanceFactory(1).newHazelcastInstance(config) in my tests rather than spinning up a real instance. One improvement is that running the corresponding tests is now 4 times as fast!

However, as I use Scala with ScalaTest as my testing framework, I found I also have to import the JUnit library. The reason for this is because com.hazelcast.test.mocknetwork.MockJoiner has a dependency on org.junit.Assert. When the JUnit dependency is not included by hand (e.g. in my own pom.xml), I get a java.lang.NoClassDefFoundError: org/junit/Assert while the test instance is spinning up:

Sep 12, 2016 9:13:28 AM com.hazelcast.system
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Hazelcast 3.6.4 (20160701 - 5b94d9f) starting at Address[127.0.0.1]:5001
Sep 12, 2016 9:13:28 AM com.hazelcast.system
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
Sep 12, 2016 9:13:28 AM com.hazelcast.system
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Configured Hazelcast Serialization version : 1
Sep 12, 2016 9:13:28 AM com.hazelcast.spi.OperationService
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Backpressure is disabled
Sep 12, 2016 9:13:28 AM com.hazelcast.spi.impl.operationexecutor.classic.ClassicOperationExecutor
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Starting with 4 generic operation threads and 8 partition operation threads.
Sep 12, 2016 9:13:28 AM com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5001 [dev] [3.6.4] Address[127.0.0.1]:5001 is STARTING
Sep 12, 2016 9:13:28 AM com.hazelcast.instance.Node
SEVERE: [127.0.0.1]:5001 [dev] [3.6.4] Error while joining the cluster!
java.lang.NoClassDefFoundError: org/junit/Assert
    at com.hazelcast.test.mocknetwork.MockJoiner.doJoin(MockJoiner.java:55)
    at com.hazelcast.cluster.impl.AbstractJoiner.join(AbstractJoiner.java:103)
    at com.hazelcast.instance.Node.join(Node.java:581)
    at com.hazelcast.instance.Node.start(Node.java:339)
    at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:131)
    at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:160)
    at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:143)
    at com.hazelcast.test.TestHazelcastInstanceFactory.newHazelcastInstance(TestHazelcastInstanceFactory.java:112)

<more stack trace stuff>

Caused by: java.lang.ClassNotFoundException: org.junit.Assert
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 75 more

Below are listed the hazelcast dependencies in my pom.xml:

<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast</artifactId>
    <version>3.6.4</version>
</dependency>
<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast</artifactId>
    <version>3.6.4</version>
    <classifier>tests</classifier>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast-client</artifactId>
    <version>3.6.4</version>
</dependency>
<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast-scala_2.11</artifactId>
    <version>3.6.0</version>
</dependency>

Do you have any suggestions how to fix this? I would prefer not to have the JUnit dependency in my project as I'm using another testing framework. Would it be possible to make MockJoiner (and maybe other classes that have the same dependency) agnostic to testing frameworks (e.g. not depend on JUnit)?

@jerrinot
Copy link
Contributor

Hi @rvanheest,

I'm glad it makes your tests faster! A few notes:

  • Unlike regular Hazelcast API there is no compatibility guarantee on test-support classes.
  • There are some other parts of the test-support with hard dependencies on JUnit - see HazelcastTestSupport. So removing this dependency in total is probably not feasible.

However it should not be that hard to do so in the MockJoiner. Do you have any idea what to use instead? Would you like to a send a PR?

@rvanheest
Copy link
Author

I guess an alternative to consider is using the assert keyword from Java itself instead. If I'm not mistaken this keyword is mainly used for testing invariants. Sure I can do a PR for that and remove some of the JUnit dependencies in classes like MockJoiner. As I do not have much time, this may take a couple of days though. Let's keep in touch on this issue!

Btw. if you got a better idea than the assert keyword, let me know!

@jerrinot
Copy link
Contributor

maybe HazelcastTestSupport ?

@rvanheest
Copy link
Author

Closing, this is fixed in #8872

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

No branches or pull requests

2 participants