diff options
3 files changed, 29 insertions, 15 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java index 60a62d5b3..39c127bfb 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java @@ -127,7 +127,7 @@ public class BreakpointTests extends AbstractDebugTest { }, this, testTimeout, c -> "Breakpoint not restored in view"); } finally { if (!viewVisible) { - view.dispose(); + DebugUIPlugin.getActiveWorkbenchWindow().getActivePage().hideView(view); } } } diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java index b6a3b3c73..361995c89 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java @@ -22,6 +22,7 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.nio.charset.Charset; import java.util.Set; +import java.util.function.Supplier; import org.eclipse.core.runtime.Platform; import org.eclipse.debug.internal.core.DebugCoreMessages; @@ -95,8 +96,12 @@ public class InputStreamMonitorTests extends AbstractDebugTest { @Test @SuppressWarnings("resource") public void testClose() throws Exception { - Set<Thread> allThreads = Thread.getAllStackTraces().keySet(); - long alreadyLeakedThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); + Supplier<Long> getInputStreamMonitorThreads = () -> { + Set<Thread> allThreads = Thread.getAllStackTraces().keySet(); + long numMonitorThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); + return numMonitorThreads; + }; + long alreadyLeakedThreads = getInputStreamMonitorThreads.get(); if (alreadyLeakedThreads > 0) { Platform.getLog(TestsPlugin.class).warn("Test started with " + alreadyLeakedThreads + " leaked monitor threads."); } @@ -130,9 +135,8 @@ public class InputStreamMonitorTests extends AbstractDebugTest { assertEquals("Stream not closed or to often.", 1, testStream.numClosed); } - allThreads = Thread.getAllStackTraces().keySet(); - long numMonitorThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); - assertEquals("Leaked monitor threads.", 0, numMonitorThreads); + TestUtil.waitWhile(() -> getInputStreamMonitorThreads.get() > 0, 500); + assertEquals("Leaked monitor threads.", 0, (long) getInputStreamMonitorThreads.get()); } /** diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java index 239aee37d..0d361021f 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java @@ -73,7 +73,7 @@ public class OutputStreamMonitorTests extends AbstractDebugTest { @Before @SuppressWarnings("resource") public void setUp() throws IOException { - monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), null); + monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), StandardCharsets.UTF_8); } /** @@ -161,18 +161,28 @@ public class OutputStreamMonitorTests extends AbstractDebugTest { * Test that passing <code>null</code> as charset does not raise exceptions. */ @Test + @SuppressWarnings("resource") public void testNullCharset() throws Exception { String input = "o\u00F6O\u00EFiI\u00D6\u00D8\u00F8"; - monitor.addListener(fStreamListener); - monitor.startMonitoring(); - try (PrintStream out = new PrintStream(sysout)) { - out.print(input); - } - sysout.flush(); + sysout.close(); + sysout = new PipedOutputStream(); + monitor.close(); + monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), null); + try { + monitor.addListener(fStreamListener); + monitor.startMonitoring(); + try (PrintStream out = new PrintStream(sysout)) { + out.print(input); + } + sysout.flush(); - TestUtil.waitWhile(() -> notifiedChars.length() < input.length(), 500); - assertEquals("Monitor read wrong content.", input, notifiedChars.toString()); + TestUtil.waitWhile(() -> notifiedChars.length() < input.length(), 500); + assertEquals("Monitor read wrong content.", input, notifiedChars.toString()); + } finally { + sysout.close(); + monitor.close(); + } } /** |