1 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 ; 43 import java.util.Iterator ; 44 45 import junit.extensions.TestSetup; 46 import junit.framework.Test; 47 import junit.framework.TestSuite; 48 49 56 public class TestFill extends OpenCmsTestCase { 57 58 63 public TestFill(String arg0) { 64 65 super(arg0); 66 } 67 68 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("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 111 public void testFillResources() throws Throwable { 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 127 public void testReadFile() throws Throwable { 128 129 CmsObject cms = getCmsObject(); 130 int nFiles = generateContent(cms, "/", 10000, 0.2); 131 132 Iterator 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 152 public void testResWithProps() throws Throwable { 153 154 CmsObject cms = getCmsObject(); 155 echo("Testing the CmsObject#readResourcesWithProperty(String) method"); 156 String prop = "NavPos"; 157 long t = System.currentTimeMillis(); 158 List 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 |