1 31 32 package org.opencms.monitor; 33 34 import org.opencms.main.CmsContextInfo; 35 import org.opencms.main.OpenCms; 36 import org.opencms.scheduler.CmsScheduledJobInfo; 37 import org.opencms.test.OpenCmsTestCase; 38 import org.opencms.test.OpenCmsTestProperties; 39 40 import junit.extensions.TestSetup; 41 import junit.framework.Test; 42 import junit.framework.TestSuite; 43 44 53 public class TestMemoryMonitor extends OpenCmsTestCase { 54 55 60 public TestMemoryMonitor(String arg0) { 61 62 super(arg0); 63 } 64 65 70 public static Test suite() { 71 72 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 73 74 TestSuite suite = new TestSuite(); 75 suite.setName(TestMemoryMonitor.class.getName()); 76 77 suite.addTest(new TestMemoryMonitor("testMemoryMonitor")); 78 79 TestSetup wrapper = new TestSetup(suite) { 80 81 protected void setUp() { 82 83 setupOpenCms("simpletest", "/sites/default/"); 84 } 85 86 protected void tearDown() { 87 88 removeOpenCms(); 89 } 90 }; 91 92 return wrapper; 93 } 94 95 100 public void testMemoryMonitor() throws Exception { 101 102 System.out.println("Testing the OpenCms memory monitor."); 103 104 CmsScheduledJobInfo jobInfo = new CmsScheduledJobInfo(); 106 CmsContextInfo contextInfo = new CmsContextInfo(OpenCms.getDefaultUsers().getUserAdmin()); 107 jobInfo.setContextInfo(contextInfo); 108 jobInfo.setJobName("Memory monitor"); 109 jobInfo.setClassName(CmsMemoryMonitor.class.getName()); 110 jobInfo.setReuseInstance(true); 111 jobInfo.setCronExpression("0/4 * * * * ?"); 112 113 OpenCms.getScheduleManager().scheduleJob(getCmsObject(), jobInfo); 115 116 int seconds = 0; 117 do { 118 try { 119 Thread.sleep(1000); 120 } catch (InterruptedException e) { 121 fail("Something caused the waiting test thread to interrupt!"); 122 } 123 seconds++; 124 } while (seconds < 19); 125 126 assertEquals(5, OpenCms.getMemoryMonitor().getLogCount()); 127 } 128 } 129 | Popular Tags |