01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.runtime;
06:
07: import com.tc.test.TCTestCase;
08:
09: import java.lang.management.ManagementFactory;
10: import java.lang.management.MemoryPoolMXBean;
11: import java.util.Iterator;
12: import java.util.List;
13:
14: public class MemoryPoolsTest extends TCTestCase {
15:
16: public MemoryPoolsTest() {
17: //
18: }
19:
20: public void testMemoryPools() throws Exception {
21: List pools = ManagementFactory.getMemoryPoolMXBeans();
22: for (Iterator i = pools.iterator(); i.hasNext();) {
23: MemoryPoolMXBean mpBean = (MemoryPoolMXBean) i.next();
24: System.err.println(mpBean);
25: System.err.println(" Name = " + mpBean.getName());
26: System.err.println(" Usage Threashold supported = "
27: + mpBean.isUsageThresholdSupported());
28: System.err.println(" Collection Usage = "
29: + mpBean.getCollectionUsage());
30: System.err.println(" Type = " + mpBean.getType());
31: System.err.println(" Usage = " + mpBean.getUsage());
32: System.err.println("=====================");
33: }
34: JVMMemoryManager memManager = new TCMemoryManagerJdk15PoolMonitor();
35: assertTrue(memManager.isMemoryPoolMonitoringSupported());
36: MemoryUsage mu1 = memManager.getOldGenUsage();
37: assertNotNull(mu1);
38: long collectorCount1 = mu1.getCollectionCount();
39: System.err.println("Collector Count = " + collectorCount1);
40: assertTrue(collectorCount1 > -1);
41: System.gc();
42: MemoryUsage mu2 = memManager.getOldGenUsage();
43: assertNotNull(mu2);
44: long collectorCount2 = mu2.getCollectionCount();
45: System.err.println("Now the Collector Count is "
46: + collectorCount2);
47: assertTrue(collectorCount2 > collectorCount1);
48: }
49: }
|