Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.ui.tests.performance;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -28,14 +28,16 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.resources.ProjectExplorer;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.osgi.framework.Bundle;


Expand All @@ -61,72 +63,79 @@
* "sleep" to simulate computations, it only effects Elapsed Time (not CPU
* Time).
*/
public class OpenProjectExplorerFolderTest extends PerformanceTestCaseJunit4 {
public class OpenProjectExplorerFolderTest {

@ClassRule
public static final UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
@RegisterExtension
static UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
Comment on lines +68 to +69
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The uiPerformanceTestRule field should remain public and final to match the original JUnit 4 implementation and follow best practices for registered extensions. This ensures the extension is not accidentally modified and remains accessible if needed by the framework or other tests.

Suggested change
@RegisterExtension
static UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
@RegisterExtension
public static final UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();


/*
* performance testcase for bug 106158
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=106158
*/
@Test
public void testOpenNavigatorFolder() {
IProject project = createProject("testViewAndContentTypeProject");
Bundle bundle = Platform.getBundle("org.eclipse.ui.tests.performance");
URL url = bundle.getEntry("data/testContentType.zip");
try (ZipInputStream zis = new ZipInputStream(url.openStream())) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
byte[] content = new byte[0];
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] b = new byte[2048];
int read = zis.read(b);
while (read != -1) {
baos.write(b, 0, read);
read = zis.read(b);
public void testOpenNavigatorFolder(TestInfo testInfo) {
Performance perf = Performance.getDefault();
String scenarioId = getClass().getName() + "." + testInfo.getDisplayName();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using testInfo.getDisplayName() will change the performance scenario ID by including parentheses (e.g., testOpenNavigatorFolder()), whereas the JUnit 4 version used only the method name. This change will likely break performance trend tracking in the build system as the ID will no longer match historical data. It is recommended to use testInfo.getTestMethod().get().getName() to maintain the exact same scenario ID as before.

Suggested change
String scenarioId = getClass().getName() + "." + testInfo.getDisplayName();
String scenarioId = getClass().getName() + "." + testInfo.getTestMethod().get().getName();

PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
try {
IProject project = createProject("testViewAndContentTypeProject");
Bundle bundle = Platform.getBundle("org.eclipse.ui.tests.performance");
URL url = bundle.getEntry("data/testContentType.zip");
try (ZipInputStream zis = new ZipInputStream(url.openStream())) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
byte[] content = new byte[0];
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] b = new byte[2048];
int read = zis.read(b);
while (read != -1) {
baos.write(b, 0, read);
read = zis.read(b);
}
content = baos.toByteArray();
}
content = baos.toByteArray();
}
catch (IOException e) {
fail(e.getMessage());
}
IFile file = project.getFile(entry.getName());
try (ByteArrayInputStream bais = new ByteArrayInputStream(content)) {
if (!file.exists())
file.create(bais, true, new NullProgressMonitor());
else
file.setContents(bais, true, false, new NullProgressMonitor());
}
catch (CoreException e) {
fail(e.getMessage());
catch (IOException e) {
fail(e.getMessage());
}
IFile file = project.getFile(entry.getName());
try (ByteArrayInputStream bais = new ByteArrayInputStream(content)) {
if (!file.exists())
file.create(bais, true, new NullProgressMonitor());
else
file.setContents(bais, true, false, new NullProgressMonitor());
}
catch (CoreException e) {
fail(e.getMessage());
}
entry = zis.getNextEntry();
}
entry = zis.getNextEntry();
}
catch (IOException e) {
fail(e.getMessage());
}
meter.start();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = null;
try {
view = activePage.showView(ProjectExplorer.VIEW_ID);
}
catch (PartInitException e) {
fail(e.getMessage());
}
ProjectExplorer projectExplorer = null;
try {
projectExplorer = (ProjectExplorer) view;
}
catch (ClassCastException e) {
fail(e.getMessage());
}
projectExplorer.getCommonViewer().expandAll();
meter.stop();
meter.commit();
perf.assertPerformance(meter);
} finally {
meter.dispose();
}
catch (IOException e) {
fail(e.getMessage());
}
startMeasuring();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = null;
try {
view = activePage.showView(ProjectExplorer.VIEW_ID);
}
catch (PartInitException e) {
fail(e.getMessage());
}
ProjectExplorer projectExplorer = null;
try {
projectExplorer = (ProjectExplorer) view;
}
catch (ClassCastException e) {
fail(e.getMessage());
}
projectExplorer.getCommonViewer().expandAll();
stopMeasuring();
commitMeasurements();
assertPerformance();
}

private IProject createProject(String name) {
Expand Down
Loading