From 2af3b437f0d89b9d45c4ca49f65991f30b34c67f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Jul 2017 18:38:58 +0200 Subject: [PATCH] Cleanup (warnings) --- .../testFramework/src/_FirstInSuiteTest.java | 13 ++++++--- .../testFramework/src/_LastInSuiteTest.java | 29 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/platform/testFramework/src/_FirstInSuiteTest.java b/platform/testFramework/src/_FirstInSuiteTest.java index 8cd586097199..6b37c2d6444c 100644 --- a/platform/testFramework/src/_FirstInSuiteTest.java +++ b/platform/testFramework/src/_FirstInSuiteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,12 @@ import java.util.prefs.Preferences; */ @SuppressWarnings({"JUnitTestClassNamingConvention", "UseOfSystemOutOrSystemErr"}) public class _FirstInSuiteTest extends TestCase { - public static long suiteStarted; - public static boolean nothingIsCalled; + private static long suiteStarted; + private static boolean nothingIsCalled; + + public static long getSuiteStartTime() { + return suiteStarted; + } public void testReportClassLoadingProblems() { List problems = TestAll.getLoadingClassProblems(); @@ -73,6 +77,7 @@ public class _FirstInSuiteTest extends TestCase { String tempDirectory = FileUtilRt.getTempDirectory(); String[] list = new File(tempDirectory).list(); + assert list != null; System.out.println("FileUtil.getTempDirectory() = " + tempDirectory + " (" + list.length + " files)"); Preferences.userRoot(); // starts (anonymous!) timer deep in JDK bowels. helps against thread leaks @@ -96,4 +101,4 @@ public class _FirstInSuiteTest extends TestCase { assertNotNull(encoding); assertFalse(Charset.forName(encoding).aliases().contains("default")); } -} +} \ No newline at end of file diff --git a/platform/testFramework/src/_LastInSuiteTest.java b/platform/testFramework/src/_LastInSuiteTest.java index b11fa3d2d501..688d2678aae3 100644 --- a/platform/testFramework/src/_LastInSuiteTest.java +++ b/platform/testFramework/src/_LastInSuiteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit; * * @author max */ -@SuppressWarnings("JUnitTestClassNamingConvention") +@SuppressWarnings({"JUnitTestClassNamingConvention", "UseOfSystemOutOrSystemErr"}) public class _LastInSuiteTest extends TestCase { @Override protected void setUp() throws Exception { @@ -57,10 +57,8 @@ public class _LastInSuiteTest extends TestCase { } public void testProjectLeak() throws Exception { - boolean guiTestMode = Boolean.getBoolean("idea.test.guimode"); - if (guiTestMode) { - final Application application = ApplicationManager.getApplication(); - + if (Boolean.getBoolean("idea.test.guimode")) { + Application application = ApplicationManager.getApplication(); TransactionGuard.getInstance().submitTransactionAndWait(() -> { IdeEventQueue.getInstance().flushQueue(); ((ApplicationImpl)application).exit(true, true, false); @@ -68,6 +66,7 @@ public class _LastInSuiteTest extends TestCase { ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS); return; } + UIUtil.invokeAndWaitIfNeeded((Runnable)() -> { try { LightPlatformTestCase.initApplication(); // in case nobody cared to init. LightPlatformTestCase.disposeApplication() would not work otherwise. @@ -80,13 +79,12 @@ public class _LastInSuiteTest extends TestCase { } PlatformTestUtil.cleanupAllProjects(); - + ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication(); System.out.println(application.writeActionStatistics()); System.out.println(ActionUtil.ActionPauses.STAT.statistics()); System.out.println(((AppScheduledExecutorService)AppExecutorUtil.getAppScheduledExecutorService()).statistics()); - System.out.println("ProcessIOExecutorService threads created: " + - ((ProcessIOExecutorService)ProcessIOExecutorService.INSTANCE).getThreadCounter()); + System.out.println("ProcessIOExecutorService threads created: " + ((ProcessIOExecutorService)ProcessIOExecutorService.INSTANCE).getThreadCounter()); try { LeakHunter.checkNonDefaultProjectLeak(); @@ -100,7 +98,6 @@ public class _LastInSuiteTest extends TestCase { LightPlatformTestCase.disposeApplication(); UIUtil.dispatchAllInvocationEvents(); } - }); try { @@ -112,10 +109,10 @@ public class _LastInSuiteTest extends TestCase { } } - @SuppressWarnings("UseOfSystemOutOrSystemErr") public void testStatistics() throws Exception { - if (_FirstInSuiteTest.suiteStarted != 0) { - long testSuiteDuration = System.nanoTime() - _FirstInSuiteTest.suiteStarted; + long started = _FirstInSuiteTest.getSuiteStartTime(); + if (started != 0) { + long testSuiteDuration = System.nanoTime() - started; System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.totalTimeMs' value='%d']", testSuiteDuration / 1000000)); } LightPlatformTestCase.reportTestExecutionStatistics(); @@ -126,14 +123,14 @@ public class _LastInSuiteTest extends TestCase { Method snapshot = ReflectionUtil.getMethod(Class.forName("com.intellij.util.ProfilingUtil"), "captureMemorySnapshot"); if (snapshot != null) { Object path = snapshot.invoke(null); - System.out.println("Memory snapshot captured to '"+path+"'"); + System.out.println("Memory snapshot captured to '" + path + "'"); } } catch (ClassNotFoundException e) { // ProfilingUtil is missing from the classpath, ignore } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(System.err); } } -} +} \ No newline at end of file