1
1
"""
2
- Test scyjava JVM memory-related functions.
3
- """
4
- import math
5
- from assertpy import assert_that
2
+ Test scyjava JVM memory-related functions.
3
+ """
4
+ import math
5
+ from assertpy import assert_that
6
+
7
+ import scyjava
8
+
9
+
10
+ def magnitude (x : int ) -> int :
11
+ return math .floor (math .log10 (abs (x )))
12
+
6
13
7
- import scyjava
14
+ mb_initial = 50 # initial MB of memory to snarf up
8
15
9
- mb_initial = 50 # initial MB of memory to snarf up
16
+ scyjava .config .set_heap_min (mb = mb_initial )
17
+ scyjava .config .set_heap_max (gb = 1 )
10
18
11
- scyjava .config . set_heap_min ( mb = mb_initial )
12
- scyjava .config . set_heap_max ( gb = 1 )
19
+ assert not scyjava .jvm_started ( )
20
+ scyjava .start_jvm ( )
13
21
14
- assert not scyjava .jvm_started ()
15
- scyjava .start_jvm ()
22
+ assert scyjava .available_processors () >= 1
16
23
17
- assert scyjava .available_processors () >= 1
24
+ mb_max = scyjava .memory_max () // 1024 // 1024
25
+ mb_total = scyjava .memory_total () // 1024 // 1024
26
+ mb_used = scyjava .memory_used () // 1024 // 1024
18
27
19
- mb_max = scyjava . memory_max () // 1024 // 1024
20
- mb_total = scyjava . memory_total () // 1024 // 1024
21
- mb_used = scyjava . memory_used () // 1024 // 1024
28
+ assert_that ( mb_used , 'Used memory should be less than the current memory total' ). is_less_than_or_equal_to ( mb_total )
29
+ assert_that ( mb_total , 'current memory total should be less than maximum memory' ). is_less_than_or_equal_to ( mb_max )
30
+ assert_that ( mb_max , 'maximum heap size should be approx. 1 GB' ). is_between ( 900 , 1024 )
22
31
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 )
32
+ tolerance = pow (10 , magnitude (mb_initial ))
26
33
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 )
34
+ assert_that (mb_used , 'most memory should be available' ).is_less_than (tolerance )
35
+ assert_that (mb_total , 'total memory should be close to initial' ).is_close_to (mb_initial , tolerance = tolerance )
0 commit comments