Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-2307: Migrate to JUnit5 #1554

Closed
wants to merge 35 commits into from
Closed

Conversation

justinleet
Copy link
Contributor

@justinleet justinleet commented Nov 4, 2019

Contributor Comments

Moves to JUnit 5. This came out of my forever ago desire to look into JUnit5 extensions to share test infra (Kafka, ZK, etc.) across our test classes, rather than spin up for each class.

  • Migrates everything to JUnit5 annotations.
  • Migrates everything to JUnit5 assertions. This includes making everything assertThrows
  • The only @Rules left are for temporary directories. This feature is experimental in JUnit5 (although I do use it once for a @ClassRule one. We could potentially migrate over, it's not like it'd be a huge deal to upgrade to whatever they choose in the future.
  • PowerMock is gone. Doesn't work in JUnit 5. Various methods are added to source to be able to mock out / spy on / whatever to get it to work. Tried to be pretty minimal about this change, since it hits outside of tests.
  • I believe a single test got deleted: One for a two line method in MetronRestApplication, iirc. Didn't seem super helpful to test that it ran the SpringApplication.

Build works (potentially barring the last couple cleanup commits which are going through my personal Travis), but I still need to spin it up on dev.

I'm not super thrilled about this being a large PR, but it was an enormous pain that kept finding things backwards in modules I thought I'd already cleared. It could probably be split out, but I'll be honest: If I see that request, I'll probably ignore it for awhile.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    
  • Have you ensured that any documentation diagrams have been updated, along with their source files, using draw.io? See Metron Development Guidelines for instructions.

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

@mmiklavc
Copy link
Contributor

mmiklavc commented Nov 5, 2019

@justinleet wowowow, this is an awesome contribution. It's going to take me a bit of time to work through this.

PowerMock is gone. Doesn't work in JUnit 5. Various methods are added to source to be able to mock out / spy on / whatever to get it to work. Tried to be pretty minimal about this change, since it hits outside of tests.

Any reason we specifically still need/want PowerMock? That was purely for special static mocking purposes, right? Personally, I'm happy to see this cleaned this up and have our testing infrastructure as super simple JUnit + Mockito.

I believe a single test got deleted: One for a two line method in MetronRestApplication, iirc. Didn't seem super helpful to test that it ran the SpringApplication.

Can you link that here? Sounds like a reasonable drop, per your description.

@justinleet
Copy link
Contributor Author

Any reason we specifically still need/want PowerMock? That was purely for special static mocking purposes, right? Personally, I'm happy to see this cleaned this up and have our testing infrastructure as super simple JUnit + Mockito.

To the best of my knowledge, no, we don't. Nothing we were doing was super out there. What I generally did was expose a bit more state; it suggests refactoring might make that cleaner, but it's way out of scope and honestly probably low priority anyway.

I actually made sure to drop it from all the poms. If there's any PowerMock left, it's an oversight.

I believe a single test got deleted: One for a two line method in MetronRestApplication, iirc. Didn't seem super helpful to test that it ran the SpringApplication.

Can you link that here? Sounds like a reasonable drop, per your description.

https://github.com/apache/metron/blob/2ee6cc7e0b448d8d27f56f873e2c15a603c53917/metron-interface/metron-rest/src/test/java/org/apache/metron/rest/MetronRestApplicationTest.java

@justinleet
Copy link
Contributor Author

justinleet commented Nov 6, 2019

@mmiklavc Given how large this PR is, here's a git command that should just pull out the src files that changed. git difftool will also work if you have that setup. I excluded the pom and dependencies_with_url files

 git diff master -- . ':!*/test/*' ':!*pom.xml*' ':dependencies_with_url.csv'

List of files (from git diff --name-only):

metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/HBaseConfig.java
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/HadoopConfig.java
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/KnoxSSOAuthenticationFilter.java
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/RestTemplateConfig.java
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/DockerStormCLIWrapper.java
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/HdfsServiceImpl.java
metron-platform/metron-elasticsearch/metron-elasticsearch-common/src/main/java/org/apache/metron/elasticsearch/writer/ElasticsearchWriter.java
metron-platform/metron-enrichment/metron-enrichment-common/src/main/java/org/apache/metron/enrichment/stellar/EnrichmentObjectGet.java
metron-platform/metron-enrichment/metron-enrichment-common/src/main/java/org/apache/metron/enrichment/stellar/ObjectGet.java
metron-platform/metron-indexing/metron-indexing-common/src/main/java/org/apache/metron/indexing/dao/metaalert/lucene/AbstractLuceneMetaAlertUpdateDao.java
metron-platform/metron-indexing/metron-indexing-common/src/main/java/org/apache/metron/indexing/dao/search/SortField.java
metron-platform/metron-integration-test/src/main/java/org/apache/metron/integration/StellarClasspathFunctionResolver.java
metron-platform/metron-integration-test/src/main/java/org/apache/metron/integration/components/FluxTopologyComponent.java
metron-platform/metron-parsing/metron-parsers-common/src/main/java/org/apache/metron/parsers/ParserRunnerImpl.java
metron-platform/metron-solr/metron-solr-common/src/main/java/org/apache/metron/solr/dao/SolrDao.java
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/StellarProcessorUtils.java

Looks like MetronRestApplicationTest isn't included, probably because it doesn't exist anymore in the PR. For some reason I thought MetronRestApplicationTest was one of the weird classes with tests that existed in the main src folders. This is not correct.

For completeness, if you only want the poms:

git diff --name-only master -- . ':!*/src/*' ':!dependencies_with_url.csv'

@justinleet
Copy link
Contributor Author

Running dev up gives some issues starting index

Running: /usr/jdk64/jdk1.8.0_112/bin/java -server -Ddaemon.name= -Dstorm.options= -Dstorm.home=/usr/hdp/2.6.5.1175-1/storm -Dstorm.log.dir=/var/log/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /usr/hdp/2.6.5.1175-1/storm/lib/minlog-1.3.0.jar:/usr/hdp/2.6.5.1175-1/storm/lib/reflectasm-1.10.1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/disruptor-3.3.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/storm-rename-hack-1.1.0.2.6.5.1175-1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-core-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/hdp/2.6.5.1175-1/storm/lib/objenesis-2.1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/kryo-3.0.3.jar:/usr/hdp/2.6.5.1175-1/storm/lib/clojure-1.7.0.jar:/usr/hdp/2.6.5.1175-1/storm/lib/slf4j-api-1.7.21.jar:/usr/hdp/2.6.5.1175-1/storm/lib/zookeeper.jar:/usr/hdp/2.6.5.1175-1/storm/lib/asm-5.0.3.jar:/usr/hdp/2.6.5.1175-1/storm/lib/ring-cors-0.1.5.jar:/usr/hdp/2.6.5.1175-1/storm/lib/servlet-api-2.5.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-api-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-slf4j-impl-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/storm-core-1.1.0.2.6.5.1175-1.jar org.apache.storm.daemon.ClientJarTransformerRunner org.apache.storm.hack.StormShadeTransformer /usr/metron/0.7.2/lib/metron-elasticsearch-storm-0.7.2-uber.jar /tmp/6668eb74015c11ea9224525400083e4d.jar
Exception in thread "main" java.lang.IllegalArgumentException
	at org.apache.storm.hack.shade.org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.apache.storm.hack.shade.org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.apache.storm.hack.shade.org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.apache.storm.hack.DefaultShader.addRemappedClass(DefaultShader.java:182)
	at org.apache.storm.hack.DefaultShader.shadeJarStream(DefaultShader.java:103)
	at org.apache.storm.hack.StormShadeTransformer.transform(StormShadeTransformer.java:35)
	at org.apache.storm.daemon.ClientJarTransformerRunner.main(ClientJarTransformerRunner.java:37)
Running: /usr/jdk64/jdk1.8.0_112/bin/java -Ddaemon.name= -Dstorm.options= -Dstorm.home=/usr/hdp/2.6.5.1175-1/storm -Dstorm.log.dir=/var/log/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib:/usr/hdp/current/storm-client/lib -Dstorm.conf.file= -cp /usr/hdp/2.6.5.1175-1/storm/lib/minlog-1.3.0.jar:/usr/hdp/2.6.5.1175-1/storm/lib/reflectasm-1.10.1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/disruptor-3.3.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/storm-rename-hack-1.1.0.2.6.5.1175-1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-core-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/hdp/2.6.5.1175-1/storm/lib/objenesis-2.1.jar:/usr/hdp/2.6.5.1175-1/storm/lib/kryo-3.0.3.jar:/usr/hdp/2.6.5.1175-1/storm/lib/clojure-1.7.0.jar:/usr/hdp/2.6.5.1175-1/storm/lib/slf4j-api-1.7.21.jar:/usr/hdp/2.6.5.1175-1/storm/lib/zookeeper.jar:/usr/hdp/2.6.5.1175-1/storm/lib/asm-5.0.3.jar:/usr/hdp/2.6.5.1175-1/storm/lib/ring-cors-0.1.5.jar:/usr/hdp/2.6.5.1175-1/storm/lib/servlet-api-2.5.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-api-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/log4j-slf4j-impl-2.8.2.jar:/usr/hdp/2.6.5.1175-1/storm/lib/storm-core-1.1.0.2.6.5.1175-1.jar:/tmp/6668eb74015c11ea9224525400083e4d.jar:/usr/hdp/current/storm-supervisor/conf:/usr/hdp/2.6.5.1175-1/storm/bin:/usr/metron/0.7.2/lib/stellar-common-0.7.2-uber.jar -Dstorm.jar=/tmp/6668eb74015c11ea9224525400083e4d.jar -Dstorm.dependency.jars=/usr/metron/0.7.2/lib/stellar-common-0.7.2-uber.jar -Dstorm.dependency.artifacts={} org.apache.storm.flux.Flux --remote /usr/metron/0.7.2/flux/indexing/batch/remote.yaml --filter /usr/metron/0.7.2/config/hdfs.properties
Error: Could not find or load main class org.apache.storm.flux.Flux

None of the pom changes touch anything involving Storm/Flux, so I'm not sure what the disconnect is, and metron-elasticsearch-storm-0.7.2-uber.jar does contain the Flux classes.

I'll have to dig in more, but if there's any leads/knowledge from the Storm upgrade stuff, I'd be happy to hear it.

@nickwallen
Copy link
Contributor

I'll have to dig in more, but if there's any leads/knowledge from the Storm upgrade stuff, I'd be happy to hear it.

@justinleet The HDP 3.1 upgrade work hasn't landed in master yet, so that should not be the cause of any problems. I will try and take a look too when I get some free cycles.

@justinleet
Copy link
Contributor Author

@nickwallen I meant more the last upgrade cycle. Right now we package up storm 1.0.x stuff, but dev deploys Storm 1.1.0, I believe. I'm wondering if that's causing some issues. Having said that, I would totally appreciate any insight you have to offer. There's not a huge rush, I have to free up some cycles myself to look into it.

@justinleet
Copy link
Contributor Author

I added the commit from #1557 into here. It seems to resolve the problem, but I'm honestly not sure entirely why. I assume some mismatched versions were being carried along and the changed dependencies caused issues.

@justinleet
Copy link
Contributor Author

justinleet commented Nov 11, 2019

@mmiklavc This should be good for review now , dependent on #1557 to fix our modules compiling against metron-integration-test. #1557 has been merged into the branch.

Copy link
Contributor

@mmiklavc mmiklavc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another 150 files down, 247 to go :)

@justinleet
Copy link
Contributor Author

justinleet commented Nov 20, 2019

Merged master, primarily to pull in #1561. I'm letting Travis build and run the tests, but at this point we shouldn't have any JUnit 4 at all. The deps file has had JUnit removed, and from #1561 we shouldn't have any in our uber jars.

@justinleet
Copy link
Contributor Author

justinleet commented Nov 20, 2019

@mmiklavc This is pretty important, so I'm flagging you directly on the comment.

I'm looking into some weirdness with our verify_licenses.sh. It produces different results for me on Travis than locally and implies I need to readd the deps (because seems right: e.g. JUnit is a correct dependency of our compiled source: specifically metron-integration-test).

The difference between local and Travis seems to be that our shell scripts are faulty. They try to exit if an error occurs, but exit during a pipe chain doesn't stop the chain, so it ends up passing along to builtins that exit with 0 (because for grep, sort, etc, nothing went wrong). Note that mvn dependency:list should pretty much always fail midway because we don't have the Metron artifacts built, so we can't run a build all the way through (because it can't find intermodule deps).

To see this sort of thing in action:

{ echo "test" && exit 1 } | grep t
echo $?

This will still run the grep on test, and because the grep succeeds, the return code is 0.

I've changed this branch to reflect, and will open a PR PR is #1568.

@justinleet
Copy link
Contributor Author

Unrelated, the older things like JUnit 3.8.1 that come in from dependencies that are test themselves, e.g. solr-test-framework. I honestly have no idea why these show up in the branch, but not master. Seems like dependency:tree should find it in both spots.

Copy link
Contributor

@mmiklavc mmiklavc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now made it through the entire change list. I'll start circling back to your recent comments and fixes now @justinleet.

metron-platform/metron-solr/metron-solr-common/pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
@justinleet
Copy link
Contributor Author

@mmiklavc merged in master and resolved conflicts. I think everything's been taken care of or address. I don't recall, are you able to resolve conversations you've started that have been taken care of or am I the only one that can do it?

@mmiklavc
Copy link
Contributor

mmiklavc commented Dec 5, 2019

@justinleet 2 minor comments and I think we're about there.

@mmiklavc
Copy link
Contributor

mmiklavc commented Dec 6, 2019

+1. Huge contribution @justinleet, thanks and nice work!

@nickwallen
Copy link
Contributor

Many thanks @justinleet! Kudos for the contribution.

@asfgit asfgit closed this in b71ddce Dec 7, 2019
@justinleet justinleet deleted the junit5 branch December 7, 2019 15:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants