Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2015-07-08 12:01:10 +0000
committerEsteban Dugueperoux2015-07-09 14:32:12 +0000
commit361c2b38cff7893a59e835b02cda45ce0c42c54f (patch)
tree68d8e042da89d69188b030adcd2aeb07198ab62b
parentabaa9eaad2a170642ace85540c639aba13115ac6 (diff)
downloadorg.eclipse.sirius-361c2b38cff7893a59e835b02cda45ce0c42c54f.tar.gz
org.eclipse.sirius-361c2b38cff7893a59e835b02cda45ce0c42c54f.tar.xz
org.eclipse.sirius-361c2b38cff7893a59e835b02cda45ce0c42c54f.zip
[471456] Fix regression on editor restoring after session closing
- On editor restoring after session closing the SessionEditorInput.getSession() must recreate the Session because the weak reference to the old can be closed. This weak reference could not be garbage collected yet because the garbage collector is not yet executed or another object keep reference to this closed Session. - RestoreSessionFromEditorInputTests has been updated to test this case. Bug: 471456 Change-Id: Ifb0c8696410feb84911cdf2b7c7db02792c39d65 Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java53
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java2
2 files changed, 44 insertions, 11 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
index 496d3e52e4..6f98a1357c 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,8 +32,8 @@ import com.google.common.collect.Lists;
* (especially when reopening an editor from Navigation History).
*
* @author alagarde
- *
*/
+@SuppressWarnings("restriction")
public class RestoreSessionFromEditorInputTests extends SiriusDiagramTestCase {
private static final String SEMANTIC_ROOT = "/vp-2067/2067.ecore";
@@ -69,16 +69,45 @@ public class RestoreSessionFromEditorInputTests extends SiriusDiagramTestCase {
public void testRestoreSessionFromHistory() {
if (TestsUtil.shouldSkipUnreliableTests()) {
/*
- junit.framework.AssertionFailedError: Wrong initial state: expecting only one active session expected:<1> but was:<2>
- at junit.framework.Assert.fail(Assert.java:57)
- at junit.framework.Assert.failNotEquals(Assert.java:329)
- at junit.framework.Assert.assertEquals(Assert.java:78)
- at junit.framework.Assert.assertEquals(Assert.java:234)
- at junit.framework.TestCase.assertEquals(TestCase.java:401)
- at org.eclipse.sirius.tests.unit.common.RestoreSessionFromEditorInputTests.testRestoreSessionFromHistory(RestoreSessionFromEditorInputTests.java:61)
- */
+ * junit.framework.AssertionFailedError: Wrong initial state:
+ * expecting only one active session expected:<1> but was:<2> at
+ * junit.framework.Assert.fail(Assert.java:57) at
+ * junit.framework.Assert.failNotEquals(Assert.java:329) at
+ * junit.framework.Assert.assertEquals(Assert.java:78) at
+ * junit.framework.Assert.assertEquals(Assert.java:234) at
+ * junit.framework.TestCase.assertEquals(TestCase.java:401) at
+ * org.eclipse.sirius.tests.unit.common.
+ * RestoreSessionFromEditorInputTests.testRestoreSessionFromHistory(
+ * RestoreSessionFromEditorInputTests.java:61)
+ */
return;
}
+ testRestoreSessionFromHistory(false);
+ }
+
+ /**
+ * Same test as previous but close the session before restoring the editor.
+ */
+ public void testRestoreSessionFromHistoryWithClosedSession() {
+ if (TestsUtil.shouldSkipUnreliableTests()) {
+ /*
+ * junit.framework.AssertionFailedError: Wrong initial state:
+ * expecting only one active session expected:<1> but was:<2> at
+ * junit.framework.Assert.fail(Assert.java:57) at
+ * junit.framework.Assert.failNotEquals(Assert.java:329) at
+ * junit.framework.Assert.assertEquals(Assert.java:78) at
+ * junit.framework.Assert.assertEquals(Assert.java:234) at
+ * junit.framework.TestCase.assertEquals(TestCase.java:401) at
+ * org.eclipse.sirius.tests.unit.common.
+ * RestoreSessionFromEditorInputTests.testRestoreSessionFromHistory(
+ * RestoreSessionFromEditorInputTests.java:61)
+ */
+ return;
+ }
+ testRestoreSessionFromHistory(true);
+ }
+
+ private void testRestoreSessionFromHistory(boolean closeSession) {
assertEquals("Wrong initial state: expecting only one active session", 1, SessionManager.INSTANCE.getSessions().size());
// Step 1: open editor on the controlled representation
@@ -89,6 +118,10 @@ public class RestoreSessionFromEditorInputTests extends SiriusDiagramTestCase {
DialectUIManager.INSTANCE.closeEditor(editor, false);
TestsUtil.synchronizationWithUIThread();
+ if (closeSession) {
+ closeSession(session);
+ }
+
// Step 3: restore editor from navigation history
new NavigationHistoryAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), false).run();
TestsUtil.synchronizationWithUIThread();
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
index c2c5145beb..18b940bbb8 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
@@ -108,7 +108,7 @@ public class SessionEditorInput extends URIEditorInput {
*/
private Session getSession(boolean restore) {
Session session = sessionRef != null ? sessionRef.get() : null;
- if (session == null) {
+ if (session == null || !session.isOpen()) {
URI sessionModelURI = getURI().trimFragment();
if (sessionResourceURI != null) {
sessionModelURI = sessionResourceURI;

Back to the top