11"""
2- Test scyjava JVM memory-related functions.
3- """
4-
5- import scyjava
6-
7- mb_initial = 50 # initial MB of memory to snarf up
2+ Test scyjava JVM memory-related functions.
3+ """
4+ import math
5+ from assertpy import assert_that
86
9- scyjava .config .set_heap_min (mb = mb_initial )
10- scyjava .config .set_heap_max (gb = 1 )
7+ import scyjava
118
12- assert not scyjava .jvm_started ()
13- scyjava .start_jvm ()
9+ mb_initial = 50 # initial MB of memory to snarf up
1410
15- assert scyjava .available_processors () >= 1
11+ scyjava .config .set_heap_min (mb = mb_initial )
12+ scyjava .config .set_heap_max (gb = 1 )
1613
17- mb_max = scyjava .memory_max () // 1024 // 1024
18- mb_total = scyjava .memory_total () // 1024 // 1024
19- mb_used = scyjava .memory_used () // 1024 // 1024
14+ assert not scyjava .jvm_started ()
15+ scyjava .start_jvm ()
2016
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 = } "
17+ assert scyjava .available_processors () >= 1
2418
25- # The maximum heap size should be approximately 1 GB.
26- assert 900 <= mb_max <= 1024 , f"{ mb_max = } "
19+ mb_max = scyjava .memory_max () // 1024 // 1024
20+ mb_total = scyjava .memory_total () // 1024 // 1024
21+ mb_used = scyjava .memory_used () // 1024 // 1024
2722
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 = } "
23+ assert_that ( mb_used , 'Used memory should be less than the current memory total' ). is_less_than_or_equal_to ( mb_total )
24+ assert_that ( mb_total , 'current memory total should be less than maximum memory' ). is_less_than_or_equal_to ( mb_max )
25+ assert_that ( mb_max , 'maximum heap size should be approx. 1 GB' ). is_between ( 900 , 1024 )
3126
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 = } "
27+ assert_that (mb_used , 'most memory should be available' ).is_less_than (5 )
28+ assert_that (mb_total , 'total memory should be close to initial' ).is_close_to (mb_initial , tolerance = 5 )
0 commit comments