Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:05:32 GMT
  2. Package jalview.bin

File MemorySettingTest.java

 

Code metrics

2
47
1
1
116
64
2
0.04
47
1
2

Classes

Class Line # Actions
MemorySettingTest 28 47 2
0.9494%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.bin;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertTrue;
25   
26    import org.testng.annotations.Test;
27   
 
28    public class MemorySettingTest
29    {
30   
 
31  1 toggle @Test(groups = "Functional")
32    public void testGetMemorySetting()
33    {
34  1 long KB = 1024;
35  1 long MB = KB * KB;
36  1 long GB = MB * KB;
37    // long TB = GB * KB;
38   
39    /* some of these tests assume a host machine with RAM somewhere between 1GB and 1TB */
40   
41    // should return 100% of physical memory available (or 1TB whichever is
42    // smaller)
43  1 long mem1 = MemorySetting.getMemorySetting("1T", "100");
44  1 long fullmem = mem1 + 512 * MB; // mem1 gets 512MB removed for the OS
45  1 long mem1b = MemorySetting.getMemorySetting("1t", "100");
46  1 assertTrue(mem1 > 1 * GB);
47  1 assertEquals(mem1, mem1b);
48   
49    // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less
50    // than
51    // 5GB RAM.
52  1 String pc;
53  1 Float pcf;
54  1 if (mem1 > 5 * GB)
55    {
56  1 pc = "10";
57  1 pcf = 0.1f;
58    }
59    else
60    {
61  0 pc = "50";
62  0 pcf = 0.5f;
63    }
64  1 long mem1c = MemorySetting.getMemorySetting("1T", pc);
65  1 assertTrue(mem1c > (pcf - 0.01) * fullmem
66    && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point
67    // errors
68   
69    // should return 1GB (assuming host machine has more than 1GB RAM)
70  1 long mem2 = MemorySetting.getMemorySetting("1G", "100");
71  1 long mem2b = MemorySetting.getMemorySetting("1g", "100");
72  1 assertEquals(mem2, 1 * GB);
73  1 assertEquals(mem2, mem2b);
74   
75  1 long mem3 = MemorySetting.getMemorySetting("1024M", "100");
76  1 long mem3b = MemorySetting.getMemorySetting("1024m", "100");
77  1 assertEquals(mem3, 1024 * MB);
78  1 assertEquals(mem3, mem3b);
79   
80  1 long mem4 = MemorySetting.getMemorySetting("1048576K", "100");
81  1 long mem4b = MemorySetting.getMemorySetting("1048576k", "100");
82  1 assertEquals(mem4, 1048576 * KB);
83  1 assertEquals(mem4, mem4b);
84   
85  1 long mem5 = MemorySetting.getMemorySetting("1073741824B", "100");
86  1 long mem5b = MemorySetting.getMemorySetting("1073741824b", "100");
87  1 long mem5c = MemorySetting.getMemorySetting("1073741824", "100");
88  1 assertEquals(mem5, 1073741824L);
89  1 assertEquals(mem5, mem5b);
90  1 assertEquals(mem5, mem5c);
91   
92    // check g, m, k, b, "" acting as they should
93  1 assertEquals(mem2, mem3);
94  1 assertEquals(mem2, mem4);
95  1 assertEquals(mem2, mem5);
96   
97    // default should not be more than 90% memory or 32GB
98  1 long mem6 = MemorySetting.getMemorySetting();
99  1 assertTrue(mem6 <= (long) (0.905 * fullmem));
100  1 assertTrue(mem6 <= 32 * GB);
101   
102    // ensure enough memory for application
103  1 long mem7 = MemorySetting.getMemorySetting("1B", "0.000000001");
104  1 assertEquals(mem7, 512 * MB);
105   
106    // ensure enough memory for OS
107  1 long mem8 = MemorySetting.getMemorySetting("2T", "100"); // this should be
108    // short of 512MB
109  1 long mem8b = MemorySetting.getMemorySetting("2T", "50");
110    // allow 10k leeway
111  1 long diff = mem8b * 2 - mem8;
112  1 assertTrue(512 * MB - 10 * KB < diff && diff < 512 * MB + 10 * KB);
113    // assertEquals(mem8b * 2 - mem8, 512 * MB);
114    }
115   
116    }