Search in sources :

Example 1 with SequentialTaskExecutor

use of com.intellij.util.concurrency.SequentialTaskExecutor in project android by JetBrains.

the class ResourceFolderRepositoryTest method testInitFromHelperThread.

public void testInitFromHelperThread() throws Exception {
    // By default, unit tests run from the EDT thread, which automatically have read access. Try loading a repository from a
    // helper thread that doesn't have read access to make sure we grab the appropriate read locks.
    // Use a data binding file, which we currently know uses a PsiDataBindingResourceItem.
    VirtualFile file1 = myFixture.copyFileToProject(LAYOUT_WITH_DATA_BINDING, "res/layout-land/layout_with_data_binding.xml");
    final PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
    assertNotNull(psiFile1);
    VirtualFile file2 = myFixture.copyFileToProject(VALUES_WITH_DUPES, "res/values-en/values_with_dupes.xml");
    ExecutorService executorService = new SequentialTaskExecutor("", PooledThreadExecutor.INSTANCE);
    Future<ResourceFolderRepository> loadJob = executorService.submit(new Callable<ResourceFolderRepository>() {

        @Override
        public ResourceFolderRepository call() throws Exception {
            return createRepository();
        }
    });
    final ResourceFolderRepository resources = loadJob.get();
    assertNotNull(resources);
    AndroidFacet facet = resources.getFacet();
    assertEquals(1, resources.getDataBindingResourceFiles().size());
    assertEquals("land", getOnlyItem(resources, ResourceType.LAYOUT, "layout_with_data_binding").getQualifiers());
    ResourceItem dupedStringItem = resources.getResourceItem(ResourceType.STRING, "app_name").get(0);
    assertNotNull(dupedStringItem);
    assertEquals("en", dupedStringItem.getQualifiers());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SequentialTaskExecutor(com.intellij.util.concurrency.SequentialTaskExecutor) ExecutorService(java.util.concurrent.ExecutorService) PsiFile(com.intellij.psi.PsiFile) ResourceItem(com.android.ide.common.res2.ResourceItem) IOException(java.io.IOException) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

ResourceItem (com.android.ide.common.res2.ResourceItem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 SequentialTaskExecutor (com.intellij.util.concurrency.SequentialTaskExecutor)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1