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

[SPARK-5735] Replace uses of EasyMock with Mockito #4578

Closed
wants to merge 5 commits into from

Conversation

JoshRosen
Copy link
Contributor

This patch replaces all uses of EasyMock with Mockito. There are two motivations for this:

  1. We should use a single mocking framework in our tests in order to keep things consistent.
  2. EasyMock may be responsible for non-deterministic unit test failures due to its Objensis dependency (see SPARK-5626 for more details).

Most of these changes are fairly mechanical translations of Mockito code to EasyMock, although I made a small change that strengthens the assertions in one test in KinesisReceiverSuite.

@SparkQA
Copy link

SparkQA commented Feb 12, 2015

Test build #27390 has started for PR 4578 at commit 977565b.

  • This patch merges cleanly.

@ksakellis
Copy link

I was meaning to do this at some point. Thanks Josh. LGTM!

recordProcessor.shutdown(checkpointerMock, ShutdownReason.ZOMBIE)
recordProcessor.shutdown(checkpointerMock, null)

verify(checkpointerMock, never()).checkpoint()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assertion might not actually be necessary: I guess that EasyMock throws AssertionError if non-stubbed methods are called on a mock.

@JoshRosen
Copy link
Contributor Author

It would be helpful if reviewers could help me to confirm that I haven't changed the semantics of these tests. One major difference between EasyMock and Mockito seems to be in how they handle calls to non-stubbed methods. I think that EasyMock will throw exceptions if non-mocked methods are called, whereas Mockito will return a default value based on the method's return type (source).

It looks like we could use Mockito's verifyNoMoreInteractions() to assert that only explicitly expected method calls took place. Given that our original tests were written with EasyMock-style semantics, I'm going to add verifyNoMoreInteractions(...) to our after() methods so that it's clearer that we've properly preserved the old test semantics.

val actualVal = KinesisRecordProcessor.retryRandom(receiverMock.isStopped(), 2, 100)
assert(actualVal == expectedIsStopped)

verify(receiverMock, times(1)).isStopped()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: times(1) is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized this while writing the tests. Originally I had just plain verify(receiverMock) but I noticed that all of our other Mockito tests used an explicit times(1) and decided to match that style.

@vanzin
Copy link
Contributor

vanzin commented Feb 12, 2015

LGTM, although I didn't pay too much attention to the test semantics.

@SparkQA
Copy link

SparkQA commented Feb 12, 2015

Test build #27392 has started for PR 4578 at commit 0ab192b.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Feb 12, 2015

Test build #27390 has finished for PR 4578 at commit 977565b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/27390/
Test PASSed.

@SparkQA
Copy link

SparkQA commented Feb 13, 2015

Test build #27392 has finished for PR 4578 at commit 0ab192b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class MesosSchedulerBackendSuite extends FunSuite with LocalSparkContext with MockitoSugar

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/27392/
Test PASSed.

import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
import org.mockito.Matchers._
import org.mockito.{Matchers, ArgumentCaptor}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you reorganize this?

@andrewor14
Copy link
Contributor

Ok LGTM, this is a fairly straightforward and hopefully it fixes the objenesis flaky test problem. Merging into master 1.3

asfgit pushed a commit that referenced this pull request Feb 13, 2015
This patch replaces all uses of EasyMock with Mockito.  There are two motivations for this:

1. We should use a single mocking framework in our tests in order to keep things consistent.
2. EasyMock may be responsible for non-deterministic unit test failures due to its Objensis dependency (see SPARK-5626 for more details).

Most of these changes are fairly mechanical translations of Mockito code to EasyMock, although I made a small change that strengthens the assertions in one test in KinesisReceiverSuite.

Author: Josh Rosen <[email protected]>

Closes #4578 from JoshRosen/SPARK-5735-remove-easymock and squashes the following commits:

0ab192b [Josh Rosen] Import sorting plus two minor changes to more closely match old semantics.
977565b [Josh Rosen] Remove EasyMock from build.
fae1d8f [Josh Rosen] Remove EasyMock usage in KinesisReceiverSuite.
7cca486 [Josh Rosen] Remove EasyMock usage in MesosSchedulerBackendSuite
fc5e94d [Josh Rosen] Remove EasyMock in CacheManagerSuite

(cherry picked from commit 077eec2)
Signed-off-by: Andrew Or <[email protected]>
@asfgit asfgit closed this in 077eec2 Feb 13, 2015
@JoshRosen JoshRosen deleted the SPARK-5735-remove-easymock branch February 13, 2015 21:09
@dragos
Copy link
Contributor

dragos commented May 12, 2015

Not that it matters, but mockito also depends on objenesis. :)

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

Successfully merging this pull request may close these issues.

7 participants