diff options
author | Christian W. Damus | 2015-12-05 16:45:16 +0000 |
---|---|---|
committer | Christian W. Damus | 2015-12-05 21:21:26 +0000 |
commit | 5a5961b1d34daab85311db5503c35a5f11965306 (patch) | |
tree | cc455cc1a13192a63a7371d18e531b1557aba2ec | |
parent | 305b32e0a9bcb390190400c5ed3a6450edccb046 (diff) | |
download | org.eclipse.papyrus-5a5961b1d34daab85311db5503c35a5f11965306.tar.gz org.eclipse.papyrus-5a5961b1d34daab85311db5503c35a5f11965306.tar.xz org.eclipse.papyrus-5a5961b1d34daab85311db5503c35a5f11965306.zip |
Bug 483721: [Tests] Memory leak test failures
https://bugs.eclipse.org/bugs/show_bug.cgi?id=483721
Ensure that the tests run in the Papyrus perspective.
Also, for good measure, avoid using the UML label provider to create
failure messages for model elements because that accesses stereotypes,
which puts those elements in the CacheAdapter even after they have
been unloaded.
3 files changed, 61 insertions, 27 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditingMemoryLeakFixture.java b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditingMemoryLeakFixture.java index 2fb52b1d45a..a406ceb41ba 100644 --- a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditingMemoryLeakFixture.java +++ b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditingMemoryLeakFixture.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 CEA and others. + * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Christian W. Damus (CEA) - Initial API and implementation + * Christian W. Damus - bug 483721 * */ package org.eclipse.papyrus.editor.integration.tests.tests; @@ -83,7 +84,7 @@ class EditingMemoryLeakFixture extends TestWatcher { editor.getView(PROPERTY_SHEET, true); editor.getView(OUTLINE, true); - + editor.activate(); } @@ -108,19 +109,19 @@ class EditingMemoryLeakFixture extends TestWatcher { // Is the active inner editor a diagram editor? DiagramEditor diagram = getDiagramEditor(); - if(diagram != null) { + if (diagram != null) { result = diagram.getEditingDomain(); } - if(result == null) { + if (result == null) { // Maybe it's a table editor IEditorPart active = getActiveEditor(); - if(active != null) { + if (active != null) { result = new Duck(active).quackp("get.+", TransactionalEditingDomain.class); } } - if(result == null) { + if (result == null) { // Fall back to the outer editor result = editor.getEditingDomain(); } @@ -160,16 +161,16 @@ class EditingMemoryLeakFixture extends TestWatcher { ISetSelectionTarget result = null; IViewPart explorer = editor.getView(PROJECT_EXPLORER, false); - if(explorer == null) { + if (explorer == null) { // Maybe we're in the Java perspective explorer = editor.getView(PACKAGE_EXPLORER, false); - if(explorer == null) { + if (explorer == null) { // Force the Project Explorer, then explorer = editor.getView(PROJECT_EXPLORER, true); } } - result = (ISetSelectionTarget)explorer; + result = (ISetSelectionTarget) explorer; return result; } @@ -178,12 +179,14 @@ class EditingMemoryLeakFixture extends TestWatcher { // Test lifecycle // + @Override public Statement apply(Statement base, Description description) { return editor.apply(super.apply(base, description), description); } @Override protected void starting(Description description) { + editor.ensurePapyrusPerspective(); selectModelInModelExplorer(); } diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/rules/MemoryLeakRule.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/rules/MemoryLeakRule.java index cb08cbf3316..6fbd9611fad 100644 --- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/rules/MemoryLeakRule.java +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/rules/MemoryLeakRule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 CEA, Christian W. Damus, and others. + * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bug 451013 + * Christian W. Damus - bug 483721 * */ package org.eclipse.papyrus.junit.framework.classification.rules; @@ -29,8 +30,10 @@ import java.util.List; import java.util.Map; import java.util.WeakHashMap; -import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runner.JUnitCore; @@ -38,7 +41,6 @@ import org.junit.runner.Request; import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Strings; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -76,8 +78,6 @@ public class MemoryLeakRule extends TestWatcher { private boolean isSoftReferenceSensitive; - private ComposedAdapterFactory factory; - public MemoryLeakRule() { super(); } @@ -88,7 +88,6 @@ public class MemoryLeakRule extends TestWatcher { if (queue == null) { queue = new ReferenceQueue<Object>(); tracker = Lists.newArrayList(); - factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); } tracker.add(new WeakReference<Object>(leak, queue)); @@ -157,14 +156,6 @@ public class MemoryLeakRule extends TestWatcher { // Clean up tracker = null; queue = null; - disposeFactory(); - } - - void disposeFactory() { - if (factory != null) { - factory.dispose(); - factory = null; - } } Reference<?> dequeueTracker() { @@ -196,11 +187,31 @@ public class MemoryLeakRule extends TestWatcher { } String label(Object input) { - IItemLabelProvider provider = (IItemLabelProvider) factory.adapt(input, IItemLabelProvider.class); - String result = (provider == null) ? String.valueOf(input) : provider.getText(input); + String result = null; - if (Strings.isNullOrEmpty(result)) { + if (!(input instanceof EObject)) { result = String.valueOf(input); + } else { + EObject object = (EObject) input; + EClass eclass = object.eClass(); + String label = null; + + EStructuralFeature nameFeature = eclass.getEStructuralFeature("name"); //$NON-NLS-1$ + if (nameFeature != null) { + label = String.valueOf(object.eGet(nameFeature)); + } else { + // Look for anything label-like + for (EAttribute next : eclass.getEAllAttributes()) { + if (!next.isMany() && next.getEAttributeType().getInstanceClass() == String.class) { + label = (String) object.eGet(next); + if ((label != null) && !label.isEmpty()) { + break; + } + } + } + } + + result = String.format("<%s> %s", eclass.getName(), label); } return result; diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java index 3be5de43202..693850b0633 100644 --- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java @@ -11,6 +11,7 @@ * Christian W. Damus - bug 433206 * Christian W. Damus - bug 465416 * Christian W. Damus - bug 434983 + * Christian W. Damus - bug 483721 * */ package org.eclipse.papyrus.junit.utils.rules; @@ -100,6 +101,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IPerspectiveDescriptor; import org.eclipse.ui.ISaveablePart; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbench; @@ -1235,4 +1237,22 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit return result; } + public void ensurePapyrusPerspective() { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + final String papyrus = "org.eclipse.papyrus.infra.core.perspective"; //$NON-NLS-1$ + final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IPerspectiveDescriptor perspective = activePage.getPerspective(); + if (!papyrus.equals(perspective.getId())) { + perspective = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(papyrus); + if (perspective != null) { + activePage.setPerspective(perspective); + flushDisplayEvents(); + } + } + } + }); + } } |