I have the following test which I am trying to run through Mockito(in a Spring Boot Project):
@ExtendWith(MockitoExtension.class)
public class TestClass {
@Test
void arrayTest() {
int arrSize = Integer.MAX_VALUE;
Integer[] arr = new Integer[arrSize];
for (int index = 0; index < arr.length; index += 1000) {
for (int j = index; j < Math.min(index + 1000, arr.length); j++) {
arr[j] = 500;
}
}
Assertions.assertEquals(arrSize, arr.length);
}
}
Pretty simple test just takes an array and sets its values to an integer number.
But when I run this test though IntelliJ I get the following output in the GUI:
When I change arrSize
to lets say 10
. The test works as its suppose to.
What is going on here ?
Why is Mockito skipping the test ? It should give me an OOM error correct ? Not skip the test.
Is anyone else getting the same behaviour with a similar test ?
Thanks
It seems to be an OOM issue looking at the verbose logs:
The problem still happens with different objects:
@Test
void arrayTest() {
int arrSize = 1_00_00_000;
Map[] arr = new Map[arrSize];
for (int index = 0; index < arr.length; index += 1000) {
for (int j = index; j < Math.min(index + 1000, arr.length); j++) {
arr[j] = new HashMap();
}
}
Assertions.assertEquals(arrSize, arr.length);
}
Send console output of
arrayTest()
. I think that it's because you use Integer.MAX_VALUE and it has value 2147483647. So last value in-work is 2147483000 and next 2147484000 is already out of int type size. So index variable just cannot be assigned to this value.So
Edit after adding OutOfMemoryException trace in the question:
You have no RAM memory resources to allocate array of this size. 2147483647 * 4 bytes = 8.6 GB RAM memory