Author: vyemialyanchyk
Date: 2009-09-02 10:38:25 -0400 (Wed, 02 Sep 2009)
New Revision: 17417
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestsBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/ConsoleConfigUtils.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4740 - fix "memory leak"
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestsBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestsBase.java 2009-09-02
14:16:22 UTC (rev 17416)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestsBase.java 2009-09-02
14:38:25 UTC (rev 17417)
@@ -11,8 +11,6 @@
package org.hibernate.eclipse.console.test.mappingproject;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.CoreException;
@@ -22,9 +20,10 @@
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jdt.ui.IPackagesViewPart;
import org.eclipse.jdt.ui.JavaUI;
-import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.eclipse.console.HibernateConsolePerspectiveFactory;
@@ -55,6 +54,8 @@
protected int executions = 0;
+ protected int openEditors = 0;
+
public MappingTestsBase(String name) {
super(name);
}
@@ -62,9 +63,8 @@
protected void setUp() throws Exception {
super.setUp();
- testProject = new
ConfigurableTestProject("JUnitTestProj"+System.currentTimeMillis());
//$NON-NLS-1$
+ testProject = new ConfigurableTestProject("JUnitTestProj" +
System.currentTimeMillis()); //$NON-NLS-1$
-
consoleConfigName = testProject.getIProject().getName();
testPackage = null;
@@ -145,43 +145,22 @@
long st_pack_time = System.currentTimeMillis();
int prev_failCount = result.failureCount();
int prev_errCount = result.errorCount();
-
- Method m = null;
- try {
- m = Display.getCurrent().getClass().getDeclaredMethod("runAsyncMessages",
boolean.class);
- m.setAccessible(true);
- } catch (SecurityException e) {
- } catch (NoSuchMethodException e) {
- }
-
+ //
TestSuite suite = TestSet.createTestSuite(consoleConfigName, testPackage,
testProject);
-
+ //
customizeCfgXml(testPackage);
//==============================
//run all tests for package
- //suite.run(result);
+ /** /
+ suite.run(result);
+ /**/
for (int k = 0; k < suite.testCount(); k++) {
Test test = suite.testAt(k);
test.run(result);
- // ----------------------------------------------
- //
https://jira.jboss.org/jira/browse/JBIDE-4740
- // first way to fix OutOfMemory problems
closeAllEditors();
- int LIMIT = 50,
- ii = 0;
- while(ii<LIMIT && Display.getCurrent().readAndDispatch()) {
- //Display.getCurrent().sleep();
- ii++;
- }
}
- // Second way to fix
https://jira.jboss.org/jira/browse/JBIDE-4740
- // invoked to clean up RunnableLock[] in UISynchronizer
- try {
- m.invoke(Display.getCurrent(), Boolean.TRUE);
- } catch (IllegalArgumentException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- }
+ /**/
+ closeAllEditors();
//==============================
executions++;
if (Customization.USE_CONSOLE_OUTPUT) {
@@ -218,7 +197,17 @@
}
protected void closeAllEditors() {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ final IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow != null) {
+ final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ if (workbenchPage != null) {
+ openEditors += workbenchPage.getEditorReferences().length;
+ workbenchPage.closeAllEditors(false);
+ }
+ }
+ // clean up event queue to avoid "memory leak",
+ // this is necessary to fix
https://jira.jboss.org/jira/browse/JBIDE-4824
+ while (Display.getCurrent().readAndDispatch());
}
public String getConsoleConfigName() {
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java 2009-09-02
14:16:22 UTC (rev 17416)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java 2009-09-02
14:38:25 UTC (rev 17417)
@@ -14,7 +14,10 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
@@ -38,6 +41,8 @@
protected IPackageFragment testPackage = null;
+ protected int openEditors = 0;
+
public OpenMappingDiagramTest() {
}
@@ -51,7 +56,7 @@
protected void tearDown() throws Exception {
consoleConfigName = null;
testPackage = null;
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ closeAllEditors();
}
public void testOpenMappingDiagram() {
@@ -111,4 +116,18 @@
public void setTestPackage(IPackageFragment testPackage) {
this.testPackage = testPackage;
}
+
+ protected void closeAllEditors() {
+ final IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow != null) {
+ final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ if (workbenchPage != null) {
+ openEditors += workbenchPage.getEditorReferences().length;
+ workbenchPage.closeAllEditors(false);
+ }
+ }
+ // clean up event queue to avoid "memory leak",
+ // this is necessary to fix
https://jira.jboss.org/jira/browse/JBIDE-4824
+ while (Display.getCurrent().readAndDispatch());
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2009-09-02
14:16:22 UTC (rev 17416)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2009-09-02
14:38:25 UTC (rev 17417)
@@ -17,7 +17,10 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
@@ -44,6 +47,8 @@
protected IPackageFragment testPackage = null;
+ protected int openEditors = 0;
+
public OpenMappingFileTest() {
}
@@ -57,7 +62,7 @@
protected void tearDown() throws Exception {
consoleConfigName = null;
testPackage = null;
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ closeAllEditors();
}
public void testOpenMappingFileTest() {
@@ -185,4 +190,18 @@
public void setTestPackage(IPackageFragment testPackage) {
this.testPackage = testPackage;
}
+
+ protected void closeAllEditors() {
+ final IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow != null) {
+ final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ if (workbenchPage != null) {
+ openEditors += workbenchPage.getEditorReferences().length;
+ workbenchPage.closeAllEditors(false);
+ }
+ }
+ // clean up event queue to avoid "memory leak",
+ // this is necessary to fix
https://jira.jboss.org/jira/browse/JBIDE-4824
+ while (Display.getCurrent().readAndDispatch());
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2009-09-02
14:16:22 UTC (rev 17416)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2009-09-02
14:38:25 UTC (rev 17417)
@@ -17,7 +17,10 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
@@ -45,6 +48,8 @@
protected IPackageFragment testPackage = null;
+ protected int openEditors = 0;
+
public OpenSourceFileTest() {
}
@@ -58,7 +63,7 @@
protected void tearDown() throws Exception {
consoleConfigName = null;
testPackage = null;
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ closeAllEditors();
}
public void testOpenSourceFileTest() {
@@ -154,4 +159,18 @@
public void setTestPackage(IPackageFragment testPackage) {
this.testPackage = testPackage;
}
+
+ protected void closeAllEditors() {
+ final IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow != null) {
+ final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ if (workbenchPage != null) {
+ openEditors += workbenchPage.getEditorReferences().length;
+ workbenchPage.closeAllEditors(false);
+ }
+ }
+ // clean up event queue to avoid "memory leak",
+ // this is necessary to fix
https://jira.jboss.org/jira/browse/JBIDE-4824
+ while (Display.getCurrent().readAndDispatch());
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/ConsoleConfigUtils.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/ConsoleConfigUtils.java 2009-09-02
14:16:22 UTC (rev 17416)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/ConsoleConfigUtils.java 2009-09-02
14:38:25 UTC (rev 17417)
@@ -175,6 +175,9 @@
public static void deleteConsoleConfig(String name) {
final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
final ConsoleConfiguration consoleConfig = knownConfigurations.find(name);
+ if (consoleConfig != null) {
+ consoleConfig.reset();
+ }
knownConfigurations.removeConfiguration(consoleConfig, false);
}
}