KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > test > performance > TestFill


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/test/performance/TestFill.java,v $
3  * Date : $Date: 2006/07/10 14:43:27 $
4  * Version: $Revision: 1.5 $
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.test.performance;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsResource;
36 import org.opencms.file.CmsResourceFilter;
37 import org.opencms.main.OpenCms;
38 import org.opencms.main.I_CmsEventListener;
39 import org.opencms.test.OpenCmsTestCase;
40 import org.opencms.test.OpenCmsTestProperties;
41
42 import java.util.List JavaDoc;
43 import java.util.Iterator JavaDoc;
44
45 import junit.extensions.TestSetup;
46 import junit.framework.Test;
47 import junit.framework.TestSuite;
48
49 /**
50  * Unit tests for lock operation.<p>
51  *
52  * @author Alexander Kandzior
53  *
54  * @version $Revision: 1.5 $
55  */

56 public class TestFill extends OpenCmsTestCase {
57
58     /**
59      * Default JUnit constructor.<p>
60      *
61      * @param arg0 JUnit parameters
62      */

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

73     public static Test suite() {
74
75         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
76
77         TestSuite suite = new TestSuite();
78         suite.setName(TestFill.class.getName());
79
80         //suite.addTest(new TestFill("testFillResources"));
81
suite.addTest(new TestFill("testResWithProps"));
82         suite.addTest(new TestFill("testReadFile"));
83
84         TestSetup wrapper = new TestSetup(suite) {
85
86             protected void setUp() {
87
88                 setupOpenCms("simpletest", "/sites/default/");
89             }
90
91             protected void tearDown() {
92
93                 removeOpenCms();
94             }
95         };
96
97         return wrapper;
98     }
99
100     /**
101      * fills the db with app in average: <br>
102      * <ul>
103      * <li>10 folders in 5 subfolders
104      * <li>20 files in each folder, 75% binary / 30% text files,<li>
105      * <li>with 10 properties, 60% individual / 30% shared properties.<li>
106      * </ul>
107      * that is a total of app. 10000 files, and 100000 property values. <p>
108      *
109      * @throws Throwable if something goes wrong
110      */

111     public void testFillResources() throws Throwable JavaDoc {
112
113         CmsObject cms = getCmsObject();
114         echo("Test filling the db with tons of files");
115         long t = System.currentTimeMillis();
116         int nFiles = generateContent(cms, "/", 10, 5, 10, 0.6, 20, 0.75);
117         t = System.currentTimeMillis() - t;
118         echo("" + nFiles + " files have been created in " + t + " msecs");
119     }
120
121     /**
122      * Performance test for readFile.<p>
123      * 10,000 files will be read and 20% of them are binary.<p>
124      *
125      * @throws Throwable if something goes wrong
126      */

127     public void testReadFile() throws Throwable JavaDoc {
128
129         CmsObject cms = getCmsObject();
130         int nFiles = generateContent(cms, "/", 10000, 0.2);
131
132         Iterator JavaDoc listIt = cms.readResources("/", CmsResourceFilter.ALL_MODIFIED).iterator();
133         OpenCms.fireCmsEvent(I_CmsEventListener.EVENT_CLEAR_CACHES, null);
134
135         long startT = System.currentTimeMillis();
136         while (listIt.hasNext()) {
137             CmsResource resource = (CmsResource)listIt.next();
138             if (resource.isFile()) {
139                 cms.readFile(resource.getName());
140             }
141         }
142         long endT = System.currentTimeMillis();
143         long workT = endT - startT;
144         echo("" + nFiles + " files have been read in " + workT + " msecs");
145     }
146
147     /**
148      * Tests the <code>{@link CmsObject#readResourcesWithProperty(String)}</code> method.<p>
149      *
150      * @throws Throwable if something goes wrong
151      */

152     public void testResWithProps() throws Throwable JavaDoc {
153
154         CmsObject cms = getCmsObject();
155         echo("Testing the CmsObject#readResourcesWithProperty(String) method");
156         String JavaDoc prop = "NavPos";
157         long t = System.currentTimeMillis();
158         List JavaDoc l = cms.readResourcesWithProperty(prop);
159         t = System.currentTimeMillis() - t;
160         echo("There are " + l.size() + " files with prop " + prop);
161         echo("readResourcesWithProperty(String) performance was: " + t + " msecs");
162     }
163 }
164
Popular Tags