Skip to content

Commit ed313be

Browse files
committed
Add integration test for scyjava's heap functions
There are two classes of functions: 1. scyjava.config functions to instruct Java how much memory to use; and 2. scyjava._java functions to report back how much it is actually using. This integration test uses both to validate that it all works properly.
1 parent d80f664 commit ed313be

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/it/java_heap.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Test scyjava JVM memory-related functions.
3+
"""
4+
5+
import scyjava
6+
7+
mb_initial = 50 # initial MB of memory to snarf up
8+
9+
scyjava.config.set_heap_min(mb=mb_initial)
10+
scyjava.config.set_heap_max(gb=1)
11+
12+
assert not scyjava.jvm_started()
13+
scyjava.start_jvm()
14+
15+
assert scyjava.available_processors() >= 1
16+
17+
mb_max = scyjava.memory_max() // 1024 // 1024
18+
mb_total = scyjava.memory_total() // 1024 // 1024
19+
mb_used = scyjava.memory_used() // 1024 // 1024
20+
21+
# Used memory should be less than the current memory total,
22+
# which should be less than the maximum heap size.
23+
assert mb_used <= mb_total <= mb_max, f"{mb_used=} {mb_total=} {mb_max=}"
24+
25+
# The maximum heap size should be approximately 1 GB.
26+
assert 900 <= mb_max <= 1024, f"{mb_max=}"
27+
28+
# Most of that memory should still be free; i.e.,
29+
# we should not be using more than a few MB yet.
30+
assert mb_used <= 5, f"{mb_used=}"
31+
32+
# The total MB available to Java at this moment
33+
# should be close to our requested initial amount.
34+
assert abs(mb_total - mb_initial) < 5, f"{mb_total=} {mb_initial=}"

0 commit comments

Comments
 (0)