diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllPropertiesTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllPropertiesTests.java index 26f71f63865..2c94144c146 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllPropertiesTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllPropertiesTests.java @@ -18,8 +18,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({ PropertyManagerTest.class, -// Bug468PerformanceTest.class -}) + +@Suite.SuiteClasses({ PropertyManagerTest.class }) public class AllPropertiesTests { } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/Bug468PerformanceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/Bug468PerformanceTest.java deleted file mode 100644 index 6cb2503e3ae..00000000000 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/Bug468PerformanceTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) ETAS GmbH 2023, all rights reserved. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * ETAS GmbH - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.tests.internal.properties; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import junit.framework.TestCase; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.ICoreRunnable; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.QualifiedName; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -//Test case for GitHub Issue 468 -public class Bug468PerformanceTest extends TestCase { - - private static final String TO_BE_DELETED_FILE_NAME_PREFIX = "file_"; - - private static final String TEMP_FOLDER_NAME = "temp"; - - private IProject project; - - /** - * Creates project with below folder and file structure. - *
    - *
  1. Project contains 1 single temp folder.
  2. - *
  3. 'temp' folder contains 10 folders and 6000 files as direct children.
  4. - *
  5. each folder under 'temp' contains 10 folders (called as GrandChildren) - * and a single file.
  6. - *
  7. each GrandChildren, inturn contains another 10 folders (3rd level folder) - * and a single file.
  8. - *
  9. each 3rd level folder contains a single file. - *
  10. - *
- * A dummy property is created for all the files to ensure that the folder - * structure are created in the workspace .metadata area. - * - * @throws Exception - * If anything goes wrong during the set up. - */ - @Override - @Before - protected void setUp() throws Exception { - - super.setUp(); - ResourcesPlugin.getWorkspace().run((ICoreRunnable) monitor -> { - createTestProject(); - List childFolders = new ArrayList<>(); - List grandChildFolders = new ArrayList<>(); - IFolder tempFolder = Bug468PerformanceTest.this.project.getFolder(TEMP_FOLDER_NAME); - tempFolder.create(true, true, new NullProgressMonitor()); - // 'temp' folder contains 10 folder and 6000 files as direct children. - for (int fileIndex = 0; fileIndex < 6000; fileIndex++) { - createFile(tempFolder, TO_BE_DELETED_FILE_NAME_PREFIX + fileIndex); - } - for (int childIndex = 0; childIndex < 10; childIndex++) { - IFolder childFolder = createFolder(tempFolder, "temp_child_" + childIndex); - // each child contains 10 folders and a single file. - createTempFile(childFolder); - childFolders.add(childFolder); - } - for (int grandChildIndex = 0; grandChildIndex < 10; grandChildIndex++) { - IFolder grandChildFolder = createFolder(childFolders.get(grandChildIndex), - "temp_grandChild_" + grandChildIndex); - // each GrandChildren, intern contains another 10 folders and a single file. - createTempFile(grandChildFolder); - grandChildFolders.add(grandChildFolder); - - } - for (int thirdLevelIndex = 0; thirdLevelIndex < 10; thirdLevelIndex++) { - IFolder thirdLvLChildFolder = createFolder(grandChildFolders.get(thirdLevelIndex), - "temp_3rdLvlChild_" + thirdLevelIndex); - // each 3rd level folder contains a single file. - createTempFile(thirdLvLChildFolder); - } - }, this.project, IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); - } - - private void createTestProject() throws CoreException { - Bug468PerformanceTest.this.project = ResourcesPlugin.getWorkspace().getRoot() - .getProject(getName() + "_TestProject"); - Bug468PerformanceTest.this.project.create(new NullProgressMonitor()); - Bug468PerformanceTest.this.project.open(new NullProgressMonitor()); - } - - private IFolder createFolder(final IFolder parent, final String folderName) throws CoreException { - IFolder childFolder = parent.getFolder(folderName); - childFolder.create(true, true, new NullProgressMonitor()); - return childFolder; - } - - private IFile createFile(final IFolder parent, final String fileName) throws CoreException { - IFile file = parent.getFile(fileName); - InputStream source = new ByteArrayInputStream(file.getName().getBytes()); - file.create(source, true, new NullProgressMonitor()); - file.setPersistentProperty(new QualifiedName(this.getClass().getName(), file.getName()), file.getName()); - return file; - } - - private IFile createTempFile(final IFolder parent) throws CoreException { - return createFile(parent, "tempFile"); - } - - /** - * Deletes the project - * - * @throws Exception - * if any exception happens during the deleting of the project. - */ - @Override - @After - protected void tearDown() throws Exception { - this.project.delete(true, new NullProgressMonitor()); - super.tearDown(); - } - - /* - * Test the timings for file deletion - */ - // For 3 tries, the time was around 18000 ms to 25000 ms in windows 10 machine, - // so, set a limit of 1 minute. - @Test - @Ignore("See https://github.com/eclipse-platform/eclipse.platform/issues/715") - public void _test() throws CoreException { - IFolder tempFolder = this.project.getFolder(TEMP_FOLDER_NAME); - long[] timeTakenForDeletingFiles = new long[1]; - - ResourcesPlugin.getWorkspace().run((ICoreRunnable) monitor -> { - long startTime = System.currentTimeMillis(); - - for (int fileIndex = 0; fileIndex < 6000; fileIndex++) { - IFile fileToBeDeleted = tempFolder.getFile(TO_BE_DELETED_FILE_NAME_PREFIX + fileIndex); - fileToBeDeleted.delete(true, new NullProgressMonitor()); - } - - long endTime = System.currentTimeMillis(); - timeTakenForDeletingFiles[0] = endTime - startTime; - }, this.project, IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); - - long maxTime = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES); - assertTrue("The expected min time(ms): " + 0 + ", actual time(ms): " + timeTakenForDeletingFiles[0], - 0 <= timeTakenForDeletingFiles[0]); - assertTrue("The expected max time(ms): " + maxTime + ", actual time(ms): " + timeTakenForDeletingFiles[0], - timeTakenForDeletingFiles[0] <= maxTime); - } -} diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java index f7422cce1a3..ca98510a931 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -43,11 +43,15 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.tests.resources.WorkspaceTestRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; public class PropertyManagerTest { @@ -550,4 +554,39 @@ public void testSimpleUpdate() throws CoreException { } } + /** + * Whenever a delete operation is called on an IFile it's properties also + * deleted from .index file. This Test case validates for given IFile resource + * Zero depth is calculated to traverse through folders for loading right index + * file and delete its properties, because the required index file is present + * under corresponding bucket of the folder same as the IFile and no need to + * traverse to Infinite depth. + */ + @Test + public void testFileDeleteTraversalDepth() throws CoreException { + Workspace ws; + PropertyManager2 manager; + + ArgumentCaptor resourceArgCaptor = ArgumentCaptor.forClass(IResource.class); + ArgumentCaptor depthArgCapture = ArgumentCaptor.forClass(Integer.class); + + IFolder tempFolder = project.getFolder("temp"); + tempFolder.create(true, true, new NullProgressMonitor()); + + IFile fileToBeDeleted = tempFolder.getFile("testfile" + 0); + fileToBeDeleted.create(createRandomContentsStream(), true, createTestMonitor()); + fileToBeDeleted.setPersistentProperty(new QualifiedName(this.getClass().getName(), fileToBeDeleted.getName()), + fileToBeDeleted.getName()); + + MockitoAnnotations.openMocks(this); + ws = Mockito.spy(new Workspace()); + manager = Mockito.spy(new PropertyManager2(ws)); + + manager.deleteResource(fileToBeDeleted); + + Mockito.verify(manager).deleteProperties(resourceArgCaptor.capture(), depthArgCapture.capture()); + Integer expectedDepth = 0; + assertEquals(expectedDepth, depthArgCapture.getValue()); + + } }