Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.bin

File MemorySettingTest.java

 

Code metrics

2
46
1
1
108
62
2
0.04
46
1
2

Classes

Class Line # Actions
MemorySettingTest 28 46 2
0.9387755493.9%
 

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 smaller)
42  1 long mem1 = MemorySetting.getMemorySetting("1T", "100");
43  1 long fullmem = mem1 + 512 * MB; // mem1 gets 512MB removed for the OS
44  1 long mem1b = MemorySetting.getMemorySetting("1t", "100");
45  1 assertTrue(mem1 > 1 * GB);
46  1 assertEquals(mem1, mem1b);
47   
48    // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less than
49    // 5GB RAM.
50  1 String pc;
51  1 Float pcf;
52  1 if (mem1 > 5 * GB)
53    {
54  1 pc = "10";
55  1 pcf = 0.1f;
56    }
57    else
58    {
59  0 pc = "50";
60  0 pcf = 0.5f;
61    }
62  1 long mem1c = MemorySetting.getMemorySetting("1T", pc);
63  1 assertTrue(mem1c > (pcf - 0.01) * fullmem && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point errors
64   
65    // should return 1GB (assuming host machine has more than 1GB RAM)
66  1 long mem2 = MemorySetting.getMemorySetting("1G", "100");
67  1 long mem2b = MemorySetting.getMemorySetting("1g", "100");
68  1 assertEquals(mem2, 1 * GB);
69  1 assertEquals(mem2, mem2b);
70   
71  1 long mem3 = MemorySetting.getMemorySetting("1024M", "100");
72  1 long mem3b = MemorySetting.getMemorySetting("1024m", "100");
73  1 assertEquals(mem3, 1024 * MB);
74  1 assertEquals(mem3, mem3b);
75   
76  1 long mem4 = MemorySetting.getMemorySetting("1048576K", "100");
77  1 long mem4b = MemorySetting.getMemorySetting("1048576k", "100");
78  1 assertEquals(mem4, 1048576 * KB);
79  1 assertEquals(mem4, mem4b);
80   
81  1 long mem5 = MemorySetting.getMemorySetting("1073741824B", "100");
82  1 long mem5b = MemorySetting.getMemorySetting("1073741824b", "100");
83  1 long mem5c = MemorySetting.getMemorySetting("1073741824", "100");
84  1 assertEquals(mem5, 1073741824L);
85  1 assertEquals(mem5, mem5b);
86  1 assertEquals(mem5, mem5c);
87   
88    // check g, m, k, b, "" acting as they should
89  1 assertEquals(mem2, mem3);
90  1 assertEquals(mem2, mem4);
91  1 assertEquals(mem2, mem5);
92   
93    // default should not be more than 90% memory or 32GB
94  1 long mem6 = MemorySetting.getMemorySetting();
95  1 assertTrue(mem6 <= (long) (0.905 * fullmem));
96  1 assertTrue(mem6 <= 32 * GB);
97   
98    // ensure enough memory for application
99  1 long mem7 = MemorySetting.getMemorySetting("1B", "0.000000001");
100  1 assertEquals(mem7, 512 * MB);
101   
102    // ensure enough memory for OS
103  1 long mem8 = MemorySetting.getMemorySetting("2TB", "100"); // this should be short of 512MB
104  1 long mem8b = MemorySetting.getMemorySetting("2TB", "50");
105  1 assertEquals(mem8b * 2 - mem8, 512 * MB);
106    }
107   
108    }