use of org.eclipse.xtext.resource.NullResource in project xtext-core by eclipse.
the class SynchronizedXtextResourceSetTest method testSynchronization.
@Test
public void testSynchronization() {
try {
XtextResourceSet _createEmptyResourceSet = this.createEmptyResourceSet();
final SynchronizedXtextResourceSet resourceSet = ((SynchronizedXtextResourceSet) _createEmptyResourceSet);
final Resource.Factory _function = (URI uri) -> {
NullResource _xblockexpression = null;
{
final NullResource result = new NullResource();
result.setURI(uri);
_xblockexpression = result;
}
return _xblockexpression;
};
final Resource.Factory nullFactory = _function;
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", nullFactory);
final ArrayList<Thread> threads = CollectionLiterals.<Thread>newArrayList();
final Consumer<Integer> _function_1 = (Integer i) -> {
final Runnable _function_2 = () -> {
final ArrayList<Resource> resources = CollectionLiterals.<Resource>newArrayList();
for (int j = 0; (j < 5000); j++) {
{
String _plus = (i + " ");
String _plus_1 = (_plus + Integer.valueOf(j));
String _plus_2 = (_plus_1 + ".xmi");
final Resource resource = resourceSet.createResource(URI.createURI(_plus_2));
Assert.assertNotNull(resource);
resources.add(resource);
URI _uRI = resource.getURI();
String _plus_3 = (_uRI + "b");
resource.setURI(URI.createURI(_plus_3));
}
}
};
Thread _thread = new Thread(_function_2);
threads.add(_thread);
};
new IntegerRange(1, 10).forEach(_function_1);
for (final Thread thread : threads) {
thread.start();
}
for (final Thread thread_1 : threads) {
thread_1.join();
}
Assert.assertEquals(50000, resourceSet.getResources().size());
Assert.assertEquals(IterableExtensions.<Resource>toSet(resourceSet.getResources()).size(), IterableExtensions.<Resource>toSet(resourceSet.getURIResourceMap().values()).size());
final Function1<Resource, List<URI>> _function_2 = (Resource it) -> {
URI _uRI = it.getURI();
URI _normalize = resourceSet.getURIConverter().normalize(it.getURI());
return Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uRI, _normalize));
};
Assert.assertEquals(IterableExtensions.<URI>toSet(Iterables.<URI>concat(ListExtensions.<Resource, List<URI>>map(resourceSet.getResources(), _function_2))), resourceSet.getURIResourceMap().keySet());
final Function1<Resource, String> _function_3 = (Resource it) -> {
return it.getURI().toString();
};
final Function1<URI, String> _function_4 = (URI it) -> {
return it.toString();
};
Assert.assertEquals(IterableExtensions.join(IterableExtensions.<String>sort(IterableExtensions.<String>toList(ListExtensions.<Resource, String>map(resourceSet.getResources(), _function_3))), "\n"), IterableExtensions.join(IterableExtensions.<String>sort(IterableExtensions.<String>toList(IterableExtensions.<URI, String>map(resourceSet.getNormalizationMap().keySet(), _function_4))), "\n"));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.NullResource in project xtext-core by eclipse.
the class AbstractResourceSetTest method testDemandLoadedResourcesAreInMap.
@Test
public void testDemandLoadedResourcesAreInMap() {
final ResourceSetImpl rs = this.createEmptyResourceSet();
final Resource.Factory _function = (URI uri) -> {
NullResource _xblockexpression = null;
{
final NullResource result = new NullResource();
result.setURI(uri);
_xblockexpression = result;
}
return _xblockexpression;
};
final Resource.Factory nullFactory = _function;
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", nullFactory);
Assert.assertEquals(0, rs.getURIResourceMap().size());
final URI uri = URI.createURI("file:/does/not/exist.xmi");
final Resource demandLoaded = rs.getResource(uri, true);
Assert.assertNotNull(demandLoaded);
final Resource second = rs.getResource(uri, true);
Assert.assertSame(demandLoaded, second);
Assert.assertEquals(1, rs.getURIResourceMap().size());
}
Aggregations