[jbosstools-commits] JBoss Tools SVN: r6894 - in trunk/seam/tests/org.jboss.tools.seam.core.test: projects/SeamWebWarTestProject/src/action and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Mar 12 10:56:12 EDT 2008


Author: scabanovich
Date: 2008-03-12 10:56:11 -0400 (Wed, 12 Mar 2008)
New Revision: 6894

Added:
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/p/
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/p/placeholder
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/template.txt
   trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectGenerator.java
   trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java
Modified:
   trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java
Log:
JBIDE-1785 Test added

Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/p/placeholder
===================================================================

Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/template.txt
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/template.txt	                        (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/template.txt	2008-03-12 14:56:11 UTC (rev 6894)
@@ -0,0 +1,43 @@
+package %p%;
+
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+
+ at Name("%x#%.%T%")
+public class %T% {
+	
+	@In @Out
+	private String %s%;
+
+	@In @Out
+	private String %t%;
+
+	@Factory("%s%")
+	public String s() {
+		return "a";
+	}
+
+	@Factory("%t%")
+	public String t() {
+		return "a";
+	}
+
+	public String get%S%() {
+		return %s%;
+	}
+	
+	public void set%S%(String s) {
+		this.%s% = s;
+	}
+
+	public String get%T%() {
+		return %t%;
+	}
+	
+	public void set%T%(String t) {
+		this.%t% = t;
+	}
+
+}

Added: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectGenerator.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectGenerator.java	                        (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectGenerator.java	2008-03-12 14:56:11 UTC (rev 6894)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.test;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.common.util.FileUtil;
+
+public class SeamBigProjectGenerator {
+	int classesCount = 1000;
+	int filesInFolderLimit = 6;
+	int folderDepth = 6;
+	
+	public void generate(IResource resource, File templateFile) {
+		File root = resource.getLocation().toFile();
+		String pack = root.getName();
+		if(!templateFile.isFile()) {
+			throw new IllegalArgumentException("No template file found " + templateFile);
+		}
+		String text = FileUtil.readFile(templateFile);
+		
+		int depth = 0;
+		int i = 0;
+		while(i < classesCount) {
+			while(getFolderCount(root) >= filesInFolderLimit || (getFileCount(root) >= filesInFolderLimit && depth == folderDepth) || depth > folderDepth) {
+				root = root.getParentFile();
+				int q = pack.lastIndexOf('.');
+				if(q >= 0) pack = pack.substring(0, q);
+				depth--;
+			}
+			i++;
+			if(getFileCount(root) >= filesInFolderLimit) {
+				root = new File(root, "p" + i);
+				root.mkdirs();
+				pack += "." + root.getName();
+				depth++;
+			}
+			File f = new File(root, "T" + i + ".java");
+
+			FileUtil.writeFile(f, replace(text, i, pack));
+			
+		}
+		
+		try {
+			resource.refreshLocal(IResource.DEPTH_INFINITE, null);
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+
+	}
+
+	String replace(String text, int n, String pack) {
+		StringBuffer sb = new StringBuffer();
+		int i = 0;
+		while(true) {
+			int jb = text.indexOf('%', i);
+			if(jb < 0) break;
+			int je = text.indexOf('%', jb + 1);
+			if(je < 0) break;
+			sb.append(text.substring(i, jb));
+			String r = text.substring(jb + 1, je);
+			if(r.equals("p")) {
+				r = pack;
+			} else if(r.endsWith("#")) {
+				r = r.substring(0, r.length() - 1) + (int)(10 * Math.random());
+			} else {
+				r += "" + n;
+			}
+			sb.append(r);
+			i = je + 1;
+		}
+		
+		if(i < text.length() && i >= 0) sb.append(text.substring(i));
+		
+		return sb.toString();
+	}
+	
+	int getFolderCount(File f) {
+		File[] fs = f.listFiles();
+		int c = 0;
+		for (int i = 0; i < fs.length; i++) {
+			if(fs[i].isDirectory()) c++;
+		}
+		return c;
+	}
+
+	int getFileCount(File f) {
+		File[] fs = f.listFiles();
+		int c = 0;
+		for (int i = 0; i < fs.length; i++) {
+			if(fs[i].isFile()) c++;
+		}
+		return c;
+	}
+
+}

Added: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java	                        (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java	2008-03-12 14:56:11 UTC (rev 6894)
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.test.util.TestProjectProvider;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.internal.core.SeamProject;
+import org.jboss.tools.test.util.JUnitUtils;
+import org.jboss.tools.test.util.xpl.EditorTestHelper;
+import org.osgi.framework.Bundle;
+
+import junit.framework.TestCase;
+
+/**
+ * Test checks that loading Seam model does not depend as N*N on the number of components N.
+ * It works as follows:
+ * 1. Copy project template to workspace and import it.
+ * 2. Create N=1000 java files with seam components in the project and refresh it.
+ * 3. Reload Seam model and compute times T1 and T2 needed 
+ *    to process first K=200 files and last K=200 files.
+ * 4. Test files if T2 is 3 or more times larger than T1, 
+ *    which positively implies N*N dependency.  
+ * 
+ * @author Viacheslav Kabanovich
+ * 
+ */
+public class SeamBigProjectTest extends TestCase {
+	static String BUNDLE = "org.jboss.tools.seam.core.test";
+	IProject project;
+	TestProjectProvider provider;
+
+	protected void setUp() throws Exception {
+		provider = new TestProjectProvider(BUNDLE,"/projects/SeamWebWarTestProject" , "SeamWebWarTestProject", true);
+		project = provider.getProject();
+		IFolder folder = project.getFolder(new Path("src/action/p"));
+		File template = getTemplateFile();
+		SeamBigProjectGenerator g = new SeamBigProjectGenerator();
+		g.generate(folder, template);
+		EditorTestHelper.joinBackgroundActivities();
+	}
+	
+	private File getTemplateFile() {
+		Bundle bundle = Platform.getBundle(BUNDLE);
+		URL url = null;
+		try {
+			url = FileLocator.resolve(bundle.getEntry("/projects/template.txt"));
+		} catch (IOException e) {
+			return null; 
+		}
+		String location = url.getFile();
+		return new File(location);
+	}
+	
+	public void testBigProject() {
+		ISeamProject sp = getSeamProject();
+		Set<ISeamComponent> cs = sp.getComponents();
+		int components = cs.size();
+		if(components < 500) {
+			fail("Found only " + components + " components. Must be more than 500.");
+		}
+		SeamProject impl = (SeamProject)sp;
+		System.out.println("Full build of " + components + " components completed in " + impl.fullBuildTime + "ms");
+		long time = impl.reload();
+		System.out.println("Reloaded " + sp.getComponents().size() + " components in " + time + "ms");
+		List<Long> statistics = impl.statistics;
+		impl.statistics = null;
+		assertTrue("Statistics contains less than 500 items", statistics.size() >= 500);
+		long t1 = 0, t2 = 0;
+		for (int i = 0; i < 200; i++) {
+			t1 += statistics.get(i);
+			t2 += statistics.get(statistics.size() - 1 - i);
+		}
+		System.out.println("First 200 paths are loaded in " + t1 + "ms");
+		System.out.println("Last 200 paths are loaded in " + t2 + "ms");
+		double d = 1d * t2 / t1;
+		if(d > 2d) {
+			fail("It takes " + d + " times longer to load path in the end " 
+				+ "of seam model loading than in the beginning.\n"
+				+ "That implies that time depends as N*N on the number of components N.");
+		}
+	}
+
+
+	private ISeamProject getSeamProject() {
+		ISeamProject seamProject = null;
+		try {
+			seamProject = (ISeamProject)project.getNature(SeamProject.NATURE_ID);
+		} catch (Exception e) {
+			JUnitUtils.fail("Cannot get seam nature.",e);
+		}
+		assertNotNull("Seam project is null", seamProject);
+		return seamProject;
+	}
+	
+	@Override
+	protected void tearDown() throws Exception {
+		ISeamProject sp = getSeamProject();
+		SeamProject impl = (SeamProject)sp;
+		if(impl != null) impl.clearStorage();
+		EditorTestHelper.joinJobs(1000, 10000, 500);
+		provider.dispose();
+	}
+
+}

Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java	2008-03-12 14:55:53 UTC (rev 6893)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java	2008-03-12 14:56:11 UTC (rev 6894)
@@ -28,6 +28,7 @@
 		suite.setName("All tests for " + PLUGIN_ID);
 		suite.addTestSuite(ScannerTest.class);
 		suite.addTestSuite(SerializationTest.class);
+		suite.addTestSuite(SeamBigProjectTest.class);
 		suite.addTestSuite(SeamEARTest.class);
 		suite.addTestSuite(SeamRuntimeListConverterTest.class);
 		suite.addTestSuite(SeamRuntimeManagerTest.class);




More information about the jbosstools-commits mailing list