KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > monitor > TestMemoryMonitor


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/monitor/TestMemoryMonitor.java,v $
3  * Date : $Date: 2005/06/27 23:22:20 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

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 /**
45  * Tests for the memory monitor.<p>
46  *
47  * @author Alexander Kandzior
48  *
49  * @version $Revision: 1.9 $
50  *
51  * @since 6.0.0
52  */

53 public class TestMemoryMonitor extends OpenCmsTestCase {
54
55     /**
56      * Default JUnit constructor.<p>
57      *
58      * @param arg0 JUnit parameters
59      */

60     public TestMemoryMonitor(String JavaDoc arg0) {
61
62         super(arg0);
63     }
64
65     /**
66      * Test suite for this test class.<p>
67      *
68      * @return the test suite
69      */

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     /**
96      * Tests the memory monitor.<p>
97      *
98      * @throws Exception if something goes wrong
99      */

100     public void testMemoryMonitor() throws Exception JavaDoc {
101
102         System.out.println("Testing the OpenCms memory monitor.");
103
104         // generate job description
105
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         // add the job to the manager
114
OpenCms.getScheduleManager().scheduleJob(getCmsObject(), jobInfo);
115
116         int seconds = 0;
117         do {
118             try {
119                 Thread.sleep(1000);
120             } catch (InterruptedException JavaDoc 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