Parallel start run in junit?

Context: I have a junit test class that is run by Maven's fail-safe integration plugin, with multiple tests that can be effectively parallelized infinitely. They work against an already deployed cloud platform as a gateway for advertising promotion. Each of these tests has a quick burst of memory at the beginning, but its subsequent use is very low and it mostly polls until the action is completed.

I need all the tests to run in parallel (because they load the queue, which forces the scaling of the activities that make the job run faster), which is easy in uptime, but I also need to wiggle the memory spikes on so I run out of memory.

How can I daze them? The current implementation does Thread.sleep(random)

, but there is still a decent statistical chance that enough of them overlap to not work. Should I put Semaphore

in a test class and wait for it in a method @Before

? Is this something I can do with ease with JUnit?

+3


source to share


2 answers


The approach Semaphore

seems like a good idea to me, but you probably want finer control than use @Before

and @After

- for example, make the Semaphore static for the test class, get the resolution just before the memory splash, and release the resolution as soon as the memory becomes GC'able. You can then control how many concurrent bursts are allowed by the number of resolutions available at build time Semaphore

.



+2


source


Why not get the data that makes the memory spike from one synchronized method? This way, each test will generate memory one at a time.



+1


source







All Articles