summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2013-04-12 07:49:24 (EDT)
committer Petya Sabeva2013-04-12 07:49:24 (EDT)
commit9705150c7191bf81fe290a28f935b7a6b4977dcf (patch)
tree0178f0d5d963665fcfd7b0677cc8b9fc0de4419c
parent78a681b423ec4931b874e533712b068caf0dccde (diff)
downloadwebtools.dali-9705150c7191bf81fe290a28f935b7a6b4977dcf.zip
webtools.dali-9705150c7191bf81fe290a28f935b7a6b4977dcf.tar.gz
webtools.dali-9705150c7191bf81fe290a28f935b7a6b4977dcf.tar.bz2
Improve debug tests info messages
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/entity/EntitiesInDiagramSWTBotTest.java3
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/AbstractSwtBotEditorTest.java17
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java230
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/EditorProxy.java20
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/Utils.java223
5 files changed, 245 insertions, 248 deletions
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/entity/EntitiesInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/entity/EntitiesInDiagramSWTBotTest.java
index 81e18da..649dc67 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/entity/EntitiesInDiagramSWTBotTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/entity/EntitiesInDiagramSWTBotTest.java
@@ -9,6 +9,7 @@ import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.conditions.ElementAppearsInDiagram;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.conditions.ElementIsShown;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.AbstractSwtBotEditorTest;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.utils.Utils;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
@@ -635,7 +636,7 @@ public class EntitiesInDiagramSWTBotTest extends AbstractSwtBotEditorTest {
assertTrue("The diagram must be empty.", jpaDiagramEditor
.mainEditPart().children().isEmpty());
- factory.createEntity(jpaProject, "com.sap.test.Customer");
+ JPACreateFactory.instance().createEntity(jpaProject, "com.sap.test.Customer");
assertTrue(jpaDiagramEditor.mainEditPart().children().isEmpty());
jpaDiagramEditor
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/AbstractSwtBotEditorTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/AbstractSwtBotEditorTest.java
index 2a4674e..b457050 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/AbstractSwtBotEditorTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/AbstractSwtBotEditorTest.java
@@ -36,7 +36,6 @@ import org.junit.After;
@SuppressWarnings("restriction")
public class AbstractSwtBotEditorTest extends SWTBotGefTestCase{
- protected static JPACreateFactory factory = JPACreateFactory.instance();
protected static JpaProject jpaProject;
protected static SWTGefBot bot = new SWTGefBot();
@@ -89,10 +88,10 @@ public class AbstractSwtBotEditorTest extends SWTBotGefTestCase{
}
private static void setOrmXml() throws InterruptedException, CoreException {
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
jpaDiagramEditorPropertiesPage(jpaProject.getName());
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
//assert that the orm.xml file exists.
@@ -103,11 +102,12 @@ public class AbstractSwtBotEditorTest extends SWTBotGefTestCase{
private static void createProject(String name, String version)
throws CoreException {
- factory = JPACreateFactory.instance();
+ Utils.printlnFormatted("-----> Start JPA project creation!");
+
if(version.equals("1.0")){
- jpaProject = factory.createJPAProject(name);
+ jpaProject = JPACreateFactory.instance().createJPAProject(name);
} else {
- jpaProject = factory.createJPA20Project(name);
+ jpaProject = JPACreateFactory.instance().createJPA20Project(name);
}
assertNotNull(jpaProject);
assertEquals(name, jpaProject.getName());
@@ -148,9 +148,8 @@ public class AbstractSwtBotEditorTest extends SWTBotGefTestCase{
propertiesPageBot.button("Apply").click();
try {
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
@@ -246,7 +245,7 @@ public class AbstractSwtBotEditorTest extends SWTBotGefTestCase{
jpaProject.getContextModelRoot().synchronizeWithResourceModel();
try {
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
} catch (InterruptedException e) {
e.printStackTrace();
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java
index 992babe..410620c 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java
@@ -19,7 +19,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -36,7 +35,6 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -107,6 +105,7 @@ public class JPACreateFactory {
addPersistenceJarIntoProject(javaProject);
int cnt = 0;
JpaProject jpaProject = null;
+ Utils.printlnFormatted("========> Wait a project to appears in the Project Explorer view!");
while ((jpaProject == null) && (cnt < 1000)){
try {
Thread.sleep(500);
@@ -115,7 +114,10 @@ public class JPACreateFactory {
}
jpaProject = this.getJpaProject(project);
cnt++;
+ Utils.printlnFormatted("---> Project appears in " + cnt + " seconds...");
}
+ Utils.printlnFormatted("========> Project appears in the Project Explorer view!");
+
jpaProject.setDiscoversAnnotatedClasses(true);
// jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject));
return jpaProject;
@@ -192,7 +194,7 @@ public class JPACreateFactory {
public IJavaProject createJavaProject(IProject project,
boolean autoBuild) throws CoreException {
facetedProject = createFacetedProject(project);
- installFacet(facetedProject, "jst.java", "5.0");
+ installFacet(facetedProject, "jst.java", "6.0");
javaProject = JavaCore.create(project);
//sourceFolder = javaProject.getPackageFragmentRoot(project.getFolder("src"));
return javaProject;
@@ -621,226 +623,4 @@ public class JPACreateFactory {
IFolder folder = project.getFolder(path);
return createFieldAnnotatedEntity(folder, packageName , entityName);
}
-
- /**
- * Wait all build and refresh jobs to complete by joining them.
- */
- public static void joinBuildAndRerfreshJobs() {
- ArrayList<Job> jobs = new ArrayList<Job>();
- Job[] jobsArray;
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH);
- jobs.addAll(Arrays.asList(jobsArray));
- Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish...");
- for (int i = 0; i < jobs.size(); i++) {
- Job job = jobs.get(i);
- int jobState = job.getState();
- if ((jobState == Job.RUNNING) || (jobState == Job.WAITING)) {
- try {
- job.join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
-
- /**
- * Wait all build and refresh jobs to complete or until 30 seconds timeout
- * pass.
- */
- public static void waitBuildAndRerfreshJobs() {
- Utils.printlnFormatted("Entered into joinBuildAndRerfreshJobs.");
- ArrayList<Job> jobs = new ArrayList<Job>();
- Job[] jobsArray;
- int timeout = SIDE_JOBS_COMPLETE_TIMEOUT;
-
- while (timeout > 0) {
- jobs.clear();
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
- jobs.addAll(Arrays.asList(jobsArray));
- jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH);
- jobs.addAll(Arrays.asList(jobsArray));
- if (jobs.size() == 0) {
- return;
- }
- Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish...");
- for (Job job : jobsArray) {
- Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job));
- }
- timeout -= 1000;
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- }
- }
-
- private static String jobStateToString(Job job) {
- int state = job.getState();
- switch (state) {
- case Job.NONE:
- return "NONE";
- case Job.RUNNING:
- return "RUNNING";
- case Job.SLEEPING:
- return "SLEEPING";
- case Job.WAITING:
- return "SLEEPING";
- }
- return "UNKNOWN";
- }
-
-
-
- /**
- * Waits a certain time for any non system job to complete and if there is
- * still jobs after the certain periord,<br/>
- * removes all of them so the test will have a clean environment
- *
- * @return flag
- * @throws InterruptedException
- */
- public static boolean waitNonSystemJobs() throws InterruptedException {
- Utils.printlnFormatted("Entered into waitNonSystemJobs.");
- return waitNonSystemJobs(SIDE_JOBS_COMPLETE_TIMEOUT, true);
- }
-
- /**
- * Waits a certain time for any non system job to complete and if there is still jobs after the certain periord,<br/>
- * removes all of them so the test will have a clean environment
- *
- * @param timeout
- * time after which the jobs will be canceled.
- * @return
- * @throws InterruptedException
- */
- public static boolean waitNonSystemJobs(int timeout) throws InterruptedException {
- return waitNonSystemJobs(timeout, true);
- }
-
- /**
- * Waits a certain time for any non system job to complete and if there is
- * still jobs after the certain periord,<br/>
- * removes all of them so the test will have a clean environment
- *
- * @param timeout
- * time after which the jobs will be canceled.
- * @param cancelWaitForBrowser
- * will cancel rightaway the wait for browser jobs
- * @return
- * @throws InterruptedException
- */
- public static boolean waitNonSystemJobs(int timeout, boolean cancelWaitForBrowser) throws InterruptedException {
- Job[] find = null;
- int count = 0;
-
- while (timeout > 0) {
- count = 0;
- find = Job.getJobManager().find(null);
- for (Job job : find) {
- if (!job.isSystem()) {
- count++;
- if (!DUMPER_JOB_NAME.equals(job.getName())) {
- Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job));
- }
- }
- }
- if (DEBUG && (count == 1)) {
- return true;
- } else if (!DEBUG && (count == 0)) {
- return true;
- }
- timeout -= 1000;
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- }
- Utils.println("Cancelling any running job...");
-
- find = Job.getJobManager().find(null);
- for (Job job : find) {
- if (!job.isSystem() && !DUMPER_JOB_NAME.equals(job.getName())) {
- printTrace(job);
- cancelJob(job);
- }
- }
-
- find = Job.getJobManager().find(null);
- count = 0;
- for (Job job : find) {
- if (!job.isSystem()) {
- count++;
- }
- }
- if (count == 0) {
- Utils.printlnFormatted("All jobs removed");
- return true;
- }
-
- Utils.printlnFormatted("There are still unremoved job. This may cause the test to block.");
- return false;
- }
-
- /**
- * Cancels all running system jobs.
- *
- * @return true if no jobs are running at the end.
- * @throws InterruptedException
- */
- public static boolean cancelAllNonSystemJobs() throws InterruptedException {
- waitNonSystemJobs(0);
- return waitNonSystemJobs();
- }
-
- private static void printTrace(Job job) {
- Thread thread = job.getThread();
- if (thread == null) {
- Utils.println("Null Thread ....");
- return;
- }
- StackTraceElement[] stackTrace = thread.getStackTrace();
- if (stackTrace != null) {
- for (StackTraceElement traceElement : stackTrace) {
- if (traceElement != null) {
- Utils.println("\tat " + traceElement.toString());
- }
- }
- }
- }
-
- /**
- * Will call cancel job and produce a log
- *
- * @param job
- */
- private static void cancelJob(Job job) {
- Utils.printlnFormatted("* [" + job.getName() + "]...");
- job.cancel();
- Utils.printlnFormatted("* [" + job.getName() + "]...cancelled.");
- }
-
-
- // used to decide whether to print Job Manager's state
- private static boolean DEBUG = false;
-
- // seconds
- private static final String DUMPER_JOB_NAME = "Dumper 1";
-
- private static final int SIDE_JOBS_COMPLETE_TIMEOUT = 30 * 1000; // 30
-
-
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/EditorProxy.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/EditorProxy.java
index 49da039..7051643 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/EditorProxy.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/EditorProxy.java
@@ -147,9 +147,9 @@ public class EditorProxy {
}
public SWTBotGefEditor openDiagramOnJPAProjectNode(String name) {
- JPACreateFactory.waitBuildAndRerfreshJobs();
+ Utils.waitBuildAndRerfreshJobs();
try {
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -626,7 +626,7 @@ public class EditorProxy {
public void deleteDiagramElements(boolean isOrmXml) {
try {
- JPACreateFactory.waitNonSystemJobs(60000);
+ Utils.waitNonSystemJobs(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -664,7 +664,7 @@ public class EditorProxy {
jpaDiagramEditor.save();
try {
- JPACreateFactory.waitNonSystemJobs();
+ Utils.waitNonSystemJobs();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -693,7 +693,7 @@ public class EditorProxy {
public void deleteAttributeInJPT(SWTBotGefEditPart jpt, String attributeName) {
try {
- JPACreateFactory.waitNonSystemJobs(60000);
+ Utils.waitNonSystemJobs(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -1670,7 +1670,7 @@ public class EditorProxy {
public void deleteJPTViaButton(SWTBotGefEditPart jptType, boolean must) {
try {
- JPACreateFactory.waitNonSystemJobs(60000);
+ Utils.waitNonSystemJobs(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -1704,7 +1704,7 @@ public class EditorProxy {
public void deleteJPTViaMenu(SWTBotGefEditPart jptType) {
try {
- JPACreateFactory.waitNonSystemJobs(60000);
+ Utils.waitNonSystemJobs(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -2970,12 +2970,6 @@ public class EditorProxy {
embeddable, refType, embeddedMappingKey, linkLabel,
elementsInDiagramCount);
-// try {
-// JPACreateFactory.waitNonSystemJobs();
-// } catch (InterruptedException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
deleteAttributeInJPT(embeddingEntity, attributeName);
waitASecond();
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/Utils.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/Utils.java
index b53cbbe..0b28e1b 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/Utils.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/utils/Utils.java
@@ -1,9 +1,14 @@
package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.utils;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.Semaphore;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.Job;
+
/**
* Utility for testing purposes
@@ -20,7 +25,13 @@ public class Utils {
public final static String NEW_LINE = (System.getProperty("line.separator") != null ? System.getProperty("line.separator") : "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ // used to decide whether to print Job Manager's state
+ private static boolean DEBUG = false;
+ // seconds
+ private static final String DUMPER_JOB_NAME = "Dumper 1";
+
+ private static final int SIDE_JOBS_COMPLETE_TIMEOUT = 30 * 1000; // 30
/** A constant for java validation error markers*/
@@ -151,5 +162,217 @@ public class Utils {
}
return builder.toString();
}
+
+
+ /**
+ * Wait all build and refresh jobs to complete by joining them.
+ */
+ public static void joinBuildAndRerfreshJobs() {
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ Job[] jobsArray;
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH);
+ jobs.addAll(Arrays.asList(jobsArray));
+ Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish...");
+ for (int i = 0; i < jobs.size(); i++) {
+ Job job = jobs.get(i);
+ int jobState = job.getState();
+ if ((jobState == Job.RUNNING) || (jobState == Job.WAITING)) {
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * Wait all build and refresh jobs to complete or until 30 seconds timeout
+ * pass.
+ */
+ public static void waitBuildAndRerfreshJobs() {
+ Utils.printlnFormatted("Entered into joinBuildAndRerfreshJobs.");
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ Job[] jobsArray;
+ int timeout = SIDE_JOBS_COMPLETE_TIMEOUT;
+
+ while (timeout > 0) {
+ jobs.clear();
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
+ jobs.addAll(Arrays.asList(jobsArray));
+ jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH);
+ jobs.addAll(Arrays.asList(jobsArray));
+ if (jobs.size() == 0) {
+ return;
+ }
+ Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish...");
+ for (Job job : jobsArray) {
+ Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job));
+ }
+ timeout -= 1000;
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ }
+ }
+
+ private static String jobStateToString(Job job) {
+ int state = job.getState();
+ switch (state) {
+ case Job.NONE:
+ return "NONE";
+ case Job.RUNNING:
+ return "RUNNING";
+ case Job.SLEEPING:
+ return "SLEEPING";
+ case Job.WAITING:
+ return "SLEEPING";
+ }
+ return "UNKNOWN";
+ }
+
+
+
+ /**
+ * Waits a certain time for any non system job to complete and if there is
+ * still jobs after the certain periord,<br/>
+ * removes all of them so the test will have a clean environment
+ *
+ * @return flag
+ * @throws InterruptedException
+ */
+ public static boolean waitNonSystemJobs() throws InterruptedException {
+ Utils.printlnFormatted("Entered into waitNonSystemJobs.");
+ return waitNonSystemJobs(SIDE_JOBS_COMPLETE_TIMEOUT, true);
+ }
+
+ /**
+ * Waits a certain time for any non system job to complete and if there is still jobs after the certain periord,<br/>
+ * removes all of them so the test will have a clean environment
+ *
+ * @param timeout
+ * time after which the jobs will be canceled.
+ * @return
+ * @throws InterruptedException
+ */
+ public static boolean waitNonSystemJobs(int timeout) throws InterruptedException {
+ return waitNonSystemJobs(timeout, true);
+ }
+
+ /**
+ * Waits a certain time for any non system job to complete and if there is
+ * still jobs after the certain periord,<br/>
+ * removes all of them so the test will have a clean environment
+ *
+ * @param timeout
+ * time after which the jobs will be canceled.
+ * @param cancelWaitForBrowser
+ * will cancel rightaway the wait for browser jobs
+ * @return
+ * @throws InterruptedException
+ */
+ public static boolean waitNonSystemJobs(int timeout, boolean cancelWaitForBrowser) throws InterruptedException {
+ Job[] find = null;
+ int count = 0;
+
+ while (timeout > 0) {
+ count = 0;
+ find = Job.getJobManager().find(null);
+ for (Job job : find) {
+ if (!job.isSystem()) {
+ count++;
+ if (!DUMPER_JOB_NAME.equals(job.getName())) {
+ Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job));
+ }
+ }
+ }
+ if (DEBUG && (count == 1)) {
+ return true;
+ } else if (!DEBUG && (count == 0)) {
+ return true;
+ }
+ timeout -= 1000;
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ }
+ Utils.println("Cancelling any running job...");
+
+ find = Job.getJobManager().find(null);
+ for (Job job : find) {
+ if (!job.isSystem() && !DUMPER_JOB_NAME.equals(job.getName())) {
+ printTrace(job);
+ cancelJob(job);
+ }
+ }
+
+ find = Job.getJobManager().find(null);
+ count = 0;
+ for (Job job : find) {
+ if (!job.isSystem()) {
+ count++;
+ }
+ }
+ if (count == 0) {
+ Utils.printlnFormatted("All jobs removed");
+ return true;
+ }
+
+ Utils.printlnFormatted("There are still unremoved job. This may cause the test to block.");
+ return false;
+ }
+
+ /**
+ * Cancels all running system jobs.
+ *
+ * @return true if no jobs are running at the end.
+ * @throws InterruptedException
+ */
+ public static boolean cancelAllNonSystemJobs() throws InterruptedException {
+ waitNonSystemJobs(0);
+ return waitNonSystemJobs();
+ }
+
+ private static void printTrace(Job job) {
+ Thread thread = job.getThread();
+ if (thread == null) {
+ Utils.println("Null Thread ....");
+ return;
+ }
+ StackTraceElement[] stackTrace = thread.getStackTrace();
+ if (stackTrace != null) {
+ for (StackTraceElement traceElement : stackTrace) {
+ if (traceElement != null) {
+ Utils.println("\tat " + traceElement.toString());
+ }
+ }
+ }
+ }
+
+ /**
+ * Will call cancel job and produce a log
+ *
+ * @param job
+ */
+ private static void cancelJob(Job job) {
+ Utils.printlnFormatted("* [" + job.getName() + "]...");
+ job.cancel();
+ Utils.printlnFormatted("* [" + job.getName() + "]...cancelled.");
+ }
}