Skip to content
Advertisement

In Java, how to test a private code running in parallel with executor service wrapped in public method

I had an existing non-parallel code that we recently made concurrent by using executor service. Adding concurrency ensured limit the number of requests sent to another API in our scenario. So we are calling an external service and limiting requests, waiting for all requests to complete so as merge the responses later before sending the final response.

I am stuck on how to add a unit test/mock test to such a code, considering the private method is parallelized. I have added below my code structure to explain my situation.

I am trying to test here

JavaScript

Code

JavaScript

Advertisement

Answer

I was able to do so with unit tests and adding a mockito verify on how many times a method is called. If it’s running in parallel after chunkifying, then the method will be called more than once equal to number of chunks it’s going to process.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement