Search code examples
javajunitmockitoignite

java - Unit test with IgniteFuture


In my code, I have the following:

// for the test:
// executor is an ExecutorService that will run in the current thread
// compute is an IgniteCompute (can be mocked)

String other = "blah";
IgniteFuture<String> future = compute.callAsync(callable).chainAsync(i -> myCreate(i, other), executor);

The method myCreate is a private method in the class that I would like to ensure gets unit tested. I tried mocking the IgniteCompute but then the result of callAsync and chainAsync both get mocked resulting the in my method not getting called. Any ideas on how I can get the real myCreate method to run in a test that runs the above line?


Solution

  • You can start Ignite in embedded in-memory mode for testing. To start a node use Ignition.start(...) method.

    Ignite nodes are pretty lightweight and don't require much resources to start. I think, it's easier and more transparent than mocking IgniteCompute.