-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-utils-stress: memory usage statistics added
Signed-off-by: Ketoth Xupack <ketoth.xupack@gmail.com>
- Loading branch information
1 parent
408167f
commit b893a9c
Showing
4 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
projects/test-utils/test-utils-stress/src/main/java/org/nohope/test/stress/Memory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.nohope.test.stress; | ||
|
||
import static org.apache.commons.io.FileUtils.byteCountToDisplaySize; | ||
|
||
/** | ||
* @author <a href="mailto:ketoth.xupack@gmail.com">Ketoth Xupack</a> | ||
* @since 2014-03-18 12:15 | ||
*/ | ||
class Memory { | ||
private final long maxMemory; | ||
private final long totalMemory; | ||
private final long freeMemory; | ||
|
||
private Memory(final long maxMemory, final long totalMemory, final long freeMemory) { | ||
this.maxMemory = maxMemory; | ||
this.totalMemory = totalMemory; | ||
this.freeMemory = freeMemory; | ||
} | ||
|
||
public static Memory getCurrent() { | ||
final Runtime runtime = Runtime.getRuntime(); | ||
System.gc(); | ||
return new Memory(runtime.maxMemory(), runtime.totalMemory(), runtime.freeMemory()); | ||
} | ||
|
||
public long getMaxMemory() { | ||
return maxMemory; | ||
} | ||
|
||
public long getTotalMemory() { | ||
return totalMemory; | ||
} | ||
|
||
public long getFreeMemory() { | ||
return freeMemory; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "max: " + byteCountToDisplaySize(maxMemory) | ||
+ ", total: " + byteCountToDisplaySize(totalMemory) | ||
+ ", free: " + byteCountToDisplaySize(freeMemory) | ||
+ ", heap: " + byteCountToDisplaySize(totalMemory - freeMemory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
projects/test-utils/test-utils-stress/src/test/java/org/nohope/test/stress/MemoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.nohope.test.stress; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author <a href="mailto:ketoth.xupack@gmail.com">Ketoth Xupack</a> | ||
* @since 2014-03-18 12:33 | ||
*/ | ||
public class MemoryTest { | ||
@Test | ||
public void basic() { | ||
final Memory current = Memory.getCurrent(); | ||
assertTrue(current.getTotalMemory() > current.getFreeMemory()); | ||
assertTrue(current.getMaxMemory() >= current.getTotalMemory()); | ||
assertTrue(current.getMaxMemory() > current.getFreeMemory()); | ||
assertNotNull(current.toString()); | ||
} | ||
} |