Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[442133] Delegate and optimize resource unload when resource is removed
* Add extension point to let clients choose what is done at unload
* Add mechanism to get the right implementation for resource unloading.
* Switch default unload behavior to an optimized implementation that
don't do resource.unload() anymore.
* Add test
* Update performance test
* Update to use the new mechanism

Bug: 442133
Change-Id: I669ec17ca3d4b6f75e8fecd63bf5cdde04688829
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
  • Loading branch information
lfasani committed Mar 9, 2016
1 parent 957712e commit de35505
Show file tree
Hide file tree
Showing 21 changed files with 1,033 additions and 58 deletions.
17 changes: 17 additions & 0 deletions plugins/org.eclipse.sirius.tests.junit/data/unit/resource/My.uml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<uml:Package xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_aiqOAL9UEeW8h4FKucAEcA">
<packagedElement xmi:type="uml:Package" xmi:id="_nN2HML9UEeW8h4FKucAEcA">
<packagedElement xmi:type="uml:Class" xmi:id="_tYj9AL9UEeW8h4FKucAEcA" name="referenced">
<interfaceRealization xmi:id="_x3EvsL9UEeW8h4FKucAEcA" name="" client="_tYj9AL9UEeW8h4FKucAEcA" supplier="_xIi1wL9UEeW8h4FKucAEcA" contract="_xIi1wL9UEeW8h4FKucAEcA"/>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_xIi1wL9UEeW8h4FKucAEcA" name="referenced"/>
<packagedElement xmi:type="uml:Stereotype" xmi:id="_J-5VcNS4EeW1fZq5Zi9jKw" name="MyStereotype" redefinedClassifier="_xIi1wL9UEeW8h4FKucAEcA"/>
</packagedElement>
<packagedElement xmi:type="uml:Model" xmi:id="_n3NNQL9UEeW8h4FKucAEcA">
<packagedElement xmi:type="uml:Class" xmi:id="_p8HgANS4EeW1fZq5Zi9jKw" name="newClass"/>
<packagedElement xmi:type="uml:Class" xmi:id="_qSFwANS4EeW1fZq5Zi9jKw" name="newClass"/>
</packagedElement>
<packagedElement xmi:type="uml:Profile" xmi:id="_XNI4YNS4EeW1fZq5Zi9jKw" name="MyProfile">
<packagedElement xmi:type="uml:Stereotype" xmi:id="_dIe1cNS4EeW1fZq5Zi9jKw"/>
</packagedElement>
</uml:Package>
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style" xmi:id="_WhOY4L9UEeW8h4FKucAEcA" selectedViews="_iaBL0L9UEeW8h4FKucAEcA" version="11.0.0.201601261200">
<semanticResources>My.uml</semanticResources>
<ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_iaBL0L9UEeW8h4FKucAEcA">
<ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_pKensNS4EeW1fZq5Zi9jKw" name="new Classes">
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_pKfOwNS4EeW1fZq5Zi9jKw" source="DANNOTATION_CUSTOMIZATION_KEY">
<data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_pKfOwdS4EeW1fZq5Zi9jKw"/>
</ownedAnnotationEntries>
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_pLD2gNS4EeW1fZq5Zi9jKw" source="GMF_DIAGRAMS">
<data xmi:type="notation:Diagram" xmi:id="_pLD2gdS4EeW1fZq5Zi9jKw" type="Sirius" element="_pKensNS4EeW1fZq5Zi9jKw" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_p9L3ANS4EeW1fZq5Zi9jKw" type="2001" element="_p8R4ENS4EeW1fZq5Zi9jKw">
<children xmi:type="notation:Node" xmi:id="_p9v3sNS4EeW1fZq5Zi9jKw" type="5002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_p9v3sdS4EeW1fZq5Zi9jKw" y="5"/>
</children>
<children xmi:type="notation:Node" xmi:id="_p95BoNS4EeW1fZq5Zi9jKw" type="3003" element="_p8iWwNS4EeW1fZq5Zi9jKw">
<styles xmi:type="notation:ShapeStyle" xmi:id="_p95BodS4EeW1fZq5Zi9jKw" fontName="Segoe UI"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_p95BotS4EeW1fZq5Zi9jKw"/>
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_p9MeENS4EeW1fZq5Zi9jKw" fontName="Segoe UI" fontHeight="8"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_p9MeEdS4EeW1fZq5Zi9jKw" x="192" y="132" width="60" height="60"/>
</children>
<children xmi:type="notation:Node" xmi:id="_qSUZgNS4EeW1fZq5Zi9jKw" type="2001" element="_qSIMQNS4EeW1fZq5Zi9jKw">
<children xmi:type="notation:Node" xmi:id="_qSW1wNS4EeW1fZq5Zi9jKw" type="5002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_qSW1wdS4EeW1fZq5Zi9jKw" y="5"/>
</children>
<children xmi:type="notation:Node" xmi:id="_qSXc0NS4EeW1fZq5Zi9jKw" type="3003" element="_qSJaYNS4EeW1fZq5Zi9jKw">
<styles xmi:type="notation:ShapeStyle" xmi:id="_qSXc0dS4EeW1fZq5Zi9jKw" fontName="Segoe UI"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_qSXc0tS4EeW1fZq5Zi9jKw"/>
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_qSVnoNS4EeW1fZq5Zi9jKw" fontName="Segoe UI" fontHeight="8"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_qSVnodS4EeW1fZq5Zi9jKw" x="456" y="156" width="60" height="60"/>
</children>
<styles xmi:type="notation:DiagramStyle" xmi:id="_pLD2gtS4EeW1fZq5Zi9jKw"/>
</data>
</ownedAnnotationEntries>
<ownedDiagramElements xmi:type="diagram:DNode" xmi:id="_p8R4ENS4EeW1fZq5Zi9jKw" name="newClass" width="6" height="6" resizeKind="NSEW">
<target xmi:type="uml:Class" href="My.uml#_p8HgANS4EeW1fZq5Zi9jKw"/>
<semanticElements xmi:type="uml:Class" href="My.uml#_p8HgANS4EeW1fZq5Zi9jKw"/>
<ownedStyle xmi:type="diagram:Square" xmi:id="_p8iWwNS4EeW1fZq5Zi9jKw" borderColor="114,159,207" labelPosition="node" color="194,239,255">
<description xmi:type="style:SquareDescription" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']/@defaultLayer/@nodeMappings[name='Class']/@style"/>
</ownedStyle>
<actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']/@defaultLayer/@nodeMappings[name='Class']"/>
</ownedDiagramElements>
<ownedDiagramElements xmi:type="diagram:DNode" xmi:id="_qSIMQNS4EeW1fZq5Zi9jKw" name="newClass" width="6" height="6" resizeKind="NSEW">
<target xmi:type="uml:Class" href="My.uml#_qSFwANS4EeW1fZq5Zi9jKw"/>
<semanticElements xmi:type="uml:Class" href="My.uml#_qSFwANS4EeW1fZq5Zi9jKw"/>
<ownedStyle xmi:type="diagram:Square" xmi:id="_qSJaYNS4EeW1fZq5Zi9jKw" borderColor="114,159,207" labelPosition="node" color="194,239,255">
<description xmi:type="style:SquareDescription" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']/@defaultLayer/@nodeMappings[name='Class']/@style"/>
</ownedStyle>
<actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']/@defaultLayer/@nodeMappings[name='Class']"/>
</ownedDiagramElements>
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']"/>
<filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_pKfOwtS4EeW1fZq5Zi9jKw"/>
<activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='Classes']/@defaultLayer"/>
<target xmi:type="uml:Model" href="My.uml#_n3NNQL9UEeW8h4FKucAEcA"/>
</ownedRepresentations>
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.eclipse.sirius.tests.junit/data/table/unit/refresh/tables.odesign#//@ownedViewpoints[name='UML2%20tables%20for%20tests']"/>
</ownedViews>
</viewpoint:DAnalysis>
Expand Up @@ -35,6 +35,8 @@
import org.eclipse.sirius.tests.unit.api.navigator.GroupingContentProviderByContainingTest;
import org.eclipse.sirius.tests.unit.api.navigator.GroupingContentProviderTest;
import org.eclipse.sirius.tests.unit.api.refresh.ModifyHeaderLabelExpressionTest;
import org.eclipse.sirius.tests.unit.api.resource.ResourceStrategyForUmlTests;
import org.eclipse.sirius.tests.unit.api.resource.ResourceStrategyTests;
import org.eclipse.sirius.tests.unit.api.resource.SemanticResourceURIInAirdTests;
import org.eclipse.sirius.tests.unit.api.resource.WorkspaceDragAndDropSupportTests;
import org.eclipse.sirius.tests.unit.api.routing.EdgeRoutingStyleEdgeConditionalStyleTest;
Expand Down Expand Up @@ -302,6 +304,8 @@ public static void addGerritPart(TestSuite suite) {
suite.addTestSuite(SiriusControlAndCrossReferenceInMultiSessionTest.class);
suite.addTestSuite(ModelsToSemanticResourcesMigrationTest.class);
suite.addTestSuite(SemanticResourceURIInAirdTests.class);
suite.addTestSuite(ResourceStrategyTests.class);
suite.addTestSuite(ResourceStrategyForUmlTests.class);
suite.addTestSuite(OpenSessionTest.class);

suite.addTestSuite(SubMenusPrioritiesTest.class);
Expand Down
@@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.tests.unit.api.resource;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory;
import org.eclipse.sirius.tests.SiriusTestsPlugin;
import org.eclipse.sirius.tests.support.api.SiriusTestCase;
import org.eclipse.uml2.common.util.CacheAdapter;
import org.eclipse.uml2.uml.NamedElement;

import com.google.common.collect.Lists;

/**
* Check ResourceStrategy mechanisms for uml special case. Default resource
* strategy should avoid leak on {@link CacheAdapter}
*
* @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a>
*/
public class ResourceStrategyForUmlTests extends SiriusTestCase {

private static final String REPRESENTATIONS_FILE_PATH = "/data/unit/resource/";

private static final String REPRESENTATIONS_FILE_NAME = "representationsUml.aird";

private static final String MODEL_FILE_NAME = "My.uml";

@Override
protected IDiagramCommandFactory getCommandFactory() {
return null;
}

@Override
protected void setUp() throws Exception {
super.setUp();

initSession();
}

private void initSession() throws Exception {
copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, REPRESENTATIONS_FILE_PATH, REPRESENTATIONS_FILE_NAME, MODEL_FILE_NAME);

genericSetUp(Collections.<URI> emptyList(), Collections.<URI> emptyList(), true, toURI(TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_FILE_NAME, ResourceURIType.RESOURCE_PLATFORM_URI));
}

/**
* Check the usage of the contributed resource strategy or the default
* resource strategy.
*
* @throws Exception
*/
public void testDefaultOptimizedResourceStrategy() throws Exception {
Resource semRes = session.getSemanticResources().iterator().next();
EObject eObject = semRes.getContents().get(0);

// As CacheAdapter crossReferencer is static, it may contain elements
// added with previous test in the suite
// So we get only the crossReferenced object of this test
List<EObject> refObbjects = Lists.newArrayList();
TreeIterator<EObject> eAllContents = eObject.eAllContents();
while (eAllContents.hasNext()) {
EObject eObj = (EObject) eAllContents.next();
if (eObj instanceof NamedElement && "referenced".equals(((NamedElement) eObj).getName())) {
refObbjects.add(eObj);
}
}
ECrossReferenceAdapter crossReferenceAdapter = CacheAdapter.getCrossReferenceAdapter(eObject);
EcoreUtil.CrossReferencer inverseCrossReferencer = getInverseCrossReferencer(crossReferenceAdapter);
Collection<EObject> inverseRef = inverseCrossReferencer.keySet();
assertTrue("The CacheAdapter does not retain the uml resource content", inverseRef != null && inverseRef.containsAll(refObbjects));

session.close(new NullProgressMonitor());

inverseRef = inverseCrossReferencer.keySet();
assertTrue("The CacheAdapter still retains the uml resource content", inverseRef == null || (refObbjects.retainAll(inverseRef) && refObbjects.isEmpty()));

// Check that this ResourceStrategy has been used
assertTrue("The resource is unloaded : " + semRes, semRes.isLoaded());
}

private EcoreUtil.CrossReferencer getInverseCrossReferencer(ECrossReferenceAdapter crossReferenceAdapter) throws Exception {
Field inverseCrossReferencerField = ECrossReferenceAdapter.class.getDeclaredField("inverseCrossReferencer");
inverseCrossReferencerField.setAccessible(true);
return (EcoreUtil.CrossReferencer) inverseCrossReferencerField.get(crossReferenceAdapter);
}
}

0 comments on commit de35505

Please sign in to comment.