001: /*******************************************************************************
002: * Copyright (c) 2007 BEA Systems, Inc.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * wharley@bea.com - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.apt.pluggable.tests;
011:
012: import java.io.File;
013:
014: import junit.framework.Test;
015: import junit.framework.TestSuite;
016:
017: import org.eclipse.core.resources.IFolder;
018: import org.eclipse.core.resources.IProject;
019: import org.eclipse.core.resources.IResource;
020: import org.eclipse.core.resources.ResourcesPlugin;
021: import org.eclipse.core.runtime.IPath;
022: import org.eclipse.jdt.apt.core.util.AptConfig;
023: import org.eclipse.jdt.core.IJavaProject;
024:
025: /**
026: *
027: */
028: public class ScalingTests extends TestBase {
029: private final boolean VERBOSE = true;
030:
031: public ScalingTests(String name) {
032: super (name);
033: }
034:
035: public static Test suite() {
036: return new TestSuite(ScalingTests.class);
037: }
038:
039: public void setUp() throws Exception {
040: super .setUp();
041: }
042:
043: /**
044: * A customer reports that projects with ~2000 files abort generation.
045: * Note, this test will take quite a long time to run.
046: */
047: @SuppressWarnings("nls")
048: public void testGeneratingLotsOfFiles() throws Exception {
049: final int FILES_TO_GENERATE = 4000; // total number of files to create
050: final int PAUSE_EVERY = 200; // wait for indexer to catch up after creating this many files
051: final int PAUSE_TIME = 2000; // milliseconds to wait for indexer
052:
053: // set up project with unique name
054: IJavaProject jproj = createJavaProject(_projectName);
055:
056: IProject project = jproj.getProject();
057: IFolder srcFolder = project.getFolder("src");
058: IPath srcRoot = srcFolder.getFullPath();
059:
060: String template = "package p;\n"
061: + "import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6;\n"
062: + "@GenClass6(pkg=\"g\", name=\"Generated%05d\")\n"
063: + "public class Test%05d {}";
064: for (int i = 1; i <= FILES_TO_GENERATE; ++i) {
065: String name = String.format("Test%05d", i);
066: String contents = String.format(template, i, i);
067: env.addClass(srcRoot, "p", name, contents); //$NON-NLS-1$ //$NON-NLS-2$
068:
069: // pause to let indexer catch up
070: if (i % PAUSE_EVERY == 0) {
071: if (VERBOSE)
072: System.out.println("Created " + i
073: + " files; pausing for indexer");
074: Thread.sleep(PAUSE_TIME);
075: }
076: }
077:
078: if (VERBOSE)
079: System.out.println("Done creating source files");
080:
081: // Set some per-project preferences
082: AptConfig.setEnabled(jproj, true);
083:
084: long start = System.currentTimeMillis();
085: fullBuild(project.getFullPath());
086: if (VERBOSE)
087: System.out.println("Done with build after "
088: + ((System.currentTimeMillis() - start) / 1000L)
089: + " sec");
090:
091: expectingNoProblems();
092:
093: IPath projPath = jproj.getProject().getLocation();
094: for (int i = 1; i <= FILES_TO_GENERATE; ++i) {
095: // check that file was generated
096: String genFileName = String.format(
097: ".apt_generated/g/Generated%05d.java", i);
098: File genFile = new File(projPath.append(genFileName)
099: .toOSString());
100: assertTrue("Expected generated source file " + genFileName
101: + " was not found", genFile != null
102: && genFile.exists());
103: // check that generated file was compiled
104: String genClassName = String.format(
105: "bin/g/Generated%05d.class", i);
106: File genClass = new File(projPath.append(genClassName)
107: .toOSString());
108: assertTrue("Compiled file " + genClassName
109: + " was not found", genClass != null
110: && genClass.exists());
111: }
112:
113: if (VERBOSE)
114: System.out.println("Done checking output");
115:
116: // Now delete the project!
117: ResourcesPlugin.getWorkspace().delete(
118: new IResource[] { project }, true, null);
119:
120: }
121:
122: }
|