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);
}
Aggregations