Search in sources :

Example 1 with USERDATA_KEY_SERIALIZED_SCRIPT

use of org.eclipse.n4js.resource.UserdataMapper.USERDATA_KEY_SERIALIZED_SCRIPT in project n4js by eclipse.

the class GHOLD_120_XtextIndexPersistence_PluginUITest method checkNoCustomResourceDescriptionsLeaksToBuilderState.

/**
 */
@Test
public void checkNoCustomResourceDescriptionsLeaksToBuilderState() throws CoreException {
    final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
    assertTrue("Test project is not accessible.", project.isAccessible());
    // Since we do not know whether the built-in initialization or the test project import happened earlier...
    // Make sure both test module and manifest get into the index.
    IResourcesSetupUtil.fullBuild();
    waitForAutoBuild();
    assertMarkers("Expected exactly zero issues.", project, 0);
    final Resource resource = persister.createResource();
    assertNotNull("Test resource was null.", resource);
    final Set<org.eclipse.emf.common.util.URI> beforeCrashBuilderState = from(builderState.getAllResourceDescriptions()).transform(desc -> desc.getURI()).toSet();
    final int builderStateBeforeReloadSize = Iterables.size(beforeCrashBuilderState);
    final FluentIterable<IEObjectDescription> beforeTModulesInBuilderState = from(builderState.getAllResourceDescriptions()).transformAndConcat(desc -> desc.getExportedObjects()).filter(desc -> desc.getEClass() == TypesPackage.eINSTANCE.getTModule());
    int beforeTModulesInBuilderStateSize = size(beforeTModulesInBuilderState);
    int beforeTModulesInBuilderStateWithUserDataSize = size(beforeTModulesInBuilderState.filter(desc -> null != desc.getUserData(USERDATA_KEY_SERIALIZED_SCRIPT)));
    persister.saveToResource(resource, builderState.getAllResourceDescriptions());
    final Iterable<EObject> beforeCrashResource = newArrayList(resource.getContents());
    final int persistedBeforeReloadSize = resource.getContents().size();
    // Imitate VM crash with force built-in unload and reload.
    unLoadBuiltIns();
    IResourcesSetupUtil.fullBuild();
    waitForAutoBuild();
    // Test module issues:
    // Cannot resolve import target :: resolving simple module import : found no matching modules
    // Couldn't resolve reference to IdentifiableElement 'Assert'.
    // Couldn't resolve reference to TExportableElement 'Assert'.
    // Import of Assert cannot be resolved.
    // Manifest issues:
    // Project does not exist with project ID: org.eclipse.n4js.mangelhaft.
    // Project does not exist with project ID: org.eclipse.n4js.mangelhaft.assert.
    // Project with test fragment should depend on org.eclipse.n4js.mangelhaft.
    assertMarkers("Expected exactly 7 issues.", project, 7);
    loadBuiltIns();
    IResourcesSetupUtil.fullBuild();
    waitForAutoBuild();
    resource.getContents().clear();
    assertMarkers("Expected exactly zero issues.", project, 0);
    final Set<org.eclipse.emf.common.util.URI> afterCrashBuilderState = from(builderState.getAllResourceDescriptions()).transform(desc -> desc.getURI()).toSet();
    final int builderStateAfterReloadSize = Iterables.size(afterCrashBuilderState);
    final FluentIterable<IEObjectDescription> afterTModulesInBuilderState = from(builderState.getAllResourceDescriptions()).transformAndConcat(desc -> desc.getExportedObjects()).filter(desc -> desc.getEClass() == TypesPackage.eINSTANCE.getTModule());
    int afterTModulesInBuilderStateSize = size(afterTModulesInBuilderState);
    int afterTModulesInBuilderStateWithUserDataSize = size(afterTModulesInBuilderState.filter(desc -> null != desc.getUserData(USERDATA_KEY_SERIALIZED_SCRIPT)));
    persister.saveToResource(resource, builderState.getAllResourceDescriptions());
    final Iterable<EObject> afterCrashResource = newArrayList(resource.getContents());
    final int persistedAfterReloadSize = resource.getContents().size();
    assertTrue("Expected same number of persisted and available resource description before and after crash. Was:" + "\nBuilder state before reload size: " + builderStateBeforeReloadSize + "\nBuilder state after reload size: " + builderStateAfterReloadSize + "\nPersisted before reload size: " + persistedBeforeReloadSize + "\nPersisted after reload size: " + persistedAfterReloadSize + "\nDifferences: " + printDiff(beforeCrashBuilderState, afterCrashBuilderState, beforeCrashResource, afterCrashResource), builderStateBeforeReloadSize == builderStateAfterReloadSize && persistedBeforeReloadSize == persistedAfterReloadSize && builderStateBeforeReloadSize == persistedBeforeReloadSize);
    assertTrue("Expected same number for EObject descriptions for TModules before and after crash. Before was: " + beforeTModulesInBuilderStateSize + " after was: " + afterTModulesInBuilderStateSize, beforeTModulesInBuilderStateSize == afterTModulesInBuilderStateSize);
    assertTrue("Expected same number for EObject descriptions for TModules with serialized user data before and after crash. Before was: " + beforeTModulesInBuilderStateWithUserDataSize + " after was: " + afterTModulesInBuilderStateWithUserDataSize, beforeTModulesInBuilderStateWithUserDataSize == afterTModulesInBuilderStateWithUserDataSize);
}
Also used : Iterables(com.google.common.collect.Iterables) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Inject(com.google.inject.Inject) CoreException(org.eclipse.core.runtime.CoreException) USERDATA_KEY_SERIALIZED_SCRIPT(org.eclipse.n4js.resource.UserdataMapper.USERDATA_KEY_SERIALIZED_SCRIPT) Iterables.size(com.google.common.collect.Iterables.size) Sets.difference(com.google.common.collect.Sets.difference) IProject(org.eclipse.core.resources.IProject) IResourcesSetupUtil(org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil) FluentIterable(com.google.common.collect.FluentIterable) FluentIterable.from(com.google.common.collect.FluentIterable.from) After(org.junit.After) ResourceDescriptionImpl(org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl) Before(org.junit.Before) ContributingResourceDescriptionPersister(org.eclipse.n4js.ui.internal.ContributingResourceDescriptionPersister) Set(java.util.Set) ResourceDescriptionWithoutModuleUserData(org.eclipse.n4js.ui.building.ResourceDescriptionWithoutModuleUserData) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) File(java.io.File) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) IBuilderState(org.eclipse.xtext.builder.builderState.IBuilderState) TypesPackage(org.eclipse.n4js.ts.types.TypesPackage) Resource(org.eclipse.emf.ecore.resource.Resource) ShippedCodeInitializeTestHelper(org.eclipse.n4js.tests.util.ShippedCodeInitializeTestHelper) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Joiner(com.google.common.base.Joiner) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) IProject(org.eclipse.core.resources.IProject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Aggregations

Joiner (com.google.common.base.Joiner)1 FluentIterable (com.google.common.collect.FluentIterable)1 FluentIterable.from (com.google.common.collect.FluentIterable.from)1 Iterables (com.google.common.collect.Iterables)1 Iterables.size (com.google.common.collect.Iterables.size)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets.difference (com.google.common.collect.Sets.difference)1 Inject (com.google.inject.Inject)1 File (java.io.File)1 Set (java.util.Set)1 IProject (org.eclipse.core.resources.IProject)1 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)1 CoreException (org.eclipse.core.runtime.CoreException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 USERDATA_KEY_SERIALIZED_SCRIPT (org.eclipse.n4js.resource.UserdataMapper.USERDATA_KEY_SERIALIZED_SCRIPT)1 ShippedCodeInitializeTestHelper (org.eclipse.n4js.tests.util.ShippedCodeInitializeTestHelper)1 TypesPackage (org.eclipse.n4js.ts.types.TypesPackage)1 ResourceDescriptionWithoutModuleUserData (org.eclipse.n4js.ui.building.ResourceDescriptionWithoutModuleUserData)1 ContributingResourceDescriptionPersister (org.eclipse.n4js.ui.internal.ContributingResourceDescriptionPersister)1