solr icon indicating copy to clipboard operation
solr copied to clipboard

SOLR-16311: Simplify assert statement

Open epugh opened this issue 3 years ago • 2 comments
trafficstars

https://issues.apache.org/jira/browse/SOLR-16311

Description

This may be very stylistic in a nature, some people may like the assertTrue used everywhere, instead of using the various condition specific asserts like assertArrayEquals etc...

However, these were flagged... And some of our logic is pretty complex!

Solution

Use the simplified version mentioned by intellij

Tests

ran them

Checklist

Please review the following and check all that apply:

  • [ ] I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • [ ] I have created a Jira issue and added the issue ID to my pull request title.
  • [ ] I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • [ ] I have developed this patch against the main branch.
  • [ ] I have run ./gradlew check.
  • [ ] I have added tests for my changes.
  • [ ] I have added documentation for the Reference Guide

epugh avatar Jul 26 '22 17:07 epugh

@epugh apologies for the merge conflicts, I think some of those came up because of my big set of changes speeding up the tests.

madrob avatar Aug 02 '22 18:08 madrob

Not an issue! It's the nature of any long lived PR that it has this. I'm waiting on the SolrJ ZK work to get done before moving forward on this. I'm expecting a bunch of merge conflicts ;-)

epugh avatar Aug 02 '22 20:08 epugh

Going to merge this after #947 gets in I think!

epugh avatar Oct 17 '22 20:10 epugh

merged main and addressed remaining simplifications of asserts.

risdenk avatar Oct 18 '22 04:10 risdenk

BUILD SUCCESSFUL in 21m 57s
585 actionable tasks: 534 executed, 51 up-to-date

🚀

risdenk avatar Oct 18 '22 14:10 risdenk

So @mkhludnev and @HoustonPutman thanks for the reviews.

There are some benefits to using SolrTestCase as the base for these tests. The randomization of Locale, thread leak checks, and more. These checks are beneficial that we get some nice things without doing any extra work. SolrTestCase extends from Assert eventually so its easy to get all the static methods from there.

The question about SolrTestCase vs TestCase vs SolrTestCase4j - I used SolrTestCase if there was no existing import for one and SolrTestCase4j if there was already an existing import using SolrTestCase4j. My theory being that SolrTestCase4j already was needed so extend from it. I didn't see any downside to doing this.

Regarding the casting - I'll take a look and see what is possible here.

Regarding the assert methods using SolrTestCase4j or SolrTestCase - I was trying to avoid static imports but can be swayed if this is important to not do this.

risdenk avatar Oct 18 '22 21:10 risdenk

I just want to say "thank you" for an unexpectedly thorough review by @mkhludnev on a PR that many of us saw and passed on (I did).

dsmiley avatar Oct 19 '22 04:10 dsmiley

@mkhludnev so two items from your review that I haven't addressed. One I don't think I can fix. The other I'm open to changing to static imports if really desired.

Changes like assertEquals(3, (long) tuple.getLong("myId")); - I left a comment about how I don't see a way to fix this outside of doing Long.valueOf(3) which seems worse. Are you ok with going ahead with this PR without this being changed to not have a cast?

The second being changes like SolrTestCaseJ4.assertNotNull where I had removed the static import and qualified these. How strongly do you feel about these being assertNotNull vs leaving the SolrTestCaseJ4.assertNotNull qualification.

risdenk avatar Oct 19 '22 18:10 risdenk

@risdenk why do you think about assertEquals(3, tuple.getLong("myId").longValue()); Is it better than cast? Just asking. Overall, I'm ok with your changes.

mkhludnev avatar Oct 19 '22 19:10 mkhludnev

assertEquals(3, tuple.getLong("myId").longValue()); Is it better than cast? Just asking. Overall, I'm ok with your changes.

OOOO I like that. I didn't try that option. I'll make that change now.

risdenk avatar Oct 19 '22 19:10 risdenk

6492b9a68252f92db11fbee074acbbbf05680a51 fixes a bunch of casts and some raw assert lines that I found along the way in the stream/sql test files that I was looking at.

risdenk avatar Oct 19 '22 20:10 risdenk

While reviewing this change and the casts - found there were a smattering of raw assert ... in tests that really should be assertTrue(...) and then those could be simplified. So 18520354d31a393b975bad339a1d7ca740a60194 takes care of that.

risdenk avatar Oct 19 '22 21:10 risdenk

one last merge of main. running tests again locally just to make sure. planning to merge this today

risdenk avatar Oct 20 '22 17:10 risdenk

./gradlew clean
...
./gradlew check -Pvalidation.errorprone=true
...
BUILD SUCCESSFUL in 22m 31s
586 actionable tasks: 576 executed, 10 up-to-date

risdenk avatar Oct 20 '22 17:10 risdenk