The Java program runs fine but the test fails with the message:
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.BitSet.initWords(BitSet.java:167)
at java.base/java.util.BitSet.<init>(BitSet.java:162)
at lv.id.jc.ipv4.IntSet.<init>(IntSet.java:6)
at lv.id.jc.ipv4.IntSetTest.$spock_initializeFields(IntSetTest.groovy:11)
I already set GROOVY_OPTS
to -Xmx1g
but it doesn't help.
I use test framework Spock 2.0 and java code under test is
public class IntSet {
private final BitSet[] storage = {new BitSet(Integer.MAX_VALUE), new BitSet(Integer.MAX_VALUE)};
public void add(int i) {
if (i >= 0) {
storage[0].set(i);
} else {
storage[1].set(- i);
}
}
public long size() {
return (long) storage[0].cardinality() storage[1].cardinality();
}
}
I can't find in Spock Framework documentation how to solve such a problem. I use IntelliJ and gradle.
I will be grateful for any ideas.
Addition information. I set property in gradlew file:
DEFAULT_JVM_OPTS='"-Xmx2048m" "-Xms128m"'
I run the program using this command:
./gradlew run -q --console=plain --args="ip_addresses"
It works fine and prints the correct result. However, when I run the test with command:
./gradlew test
then I got an error message:
> Task :test FAILED
FAILURE: Build failed with an exception.
and the HTML report says:
org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (2 failures)
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
CodePudding user response:
Solved by adding configuration in build.gradle file:
test {
minHeapSize = "800m"
maxHeapSize = "2000m"
...