1 /******************************************************************************* 2 * Copyright (c) 2019 Andrey Loskutov and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Andrey Loskutov - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.debug.tests.breakpoints; 15 16 import java.util.Arrays; 17 import java.util.List; 18 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.core.ILaunch; 21 import org.eclipse.debug.core.ILaunchManager; 22 import org.eclipse.debug.core.model.IDebugTarget; 23 import org.eclipse.debug.internal.ui.views.console.ProcessConsole; 24 import org.eclipse.jdt.core.IJavaProject; 25 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 26 import org.eclipse.jdt.debug.core.IJavaLineBreakpoint; 27 import org.eclipse.jdt.debug.core.IJavaThread; 28 import org.eclipse.jdt.debug.tests.AbstractDebugTest; 29 import org.eclipse.jdt.debug.tests.TestUtil; 30 31 /** 32 * Tests lambda breakpoints. 33 */ 34 public class LambdaBreakpointsInJava8Tests extends AbstractDebugTest { 35 LambdaBreakpointsInJava8Tests(String name)36 public LambdaBreakpointsInJava8Tests(String name) { 37 super(name); 38 } 39 40 @Override getProjectContext()41 protected IJavaProject getProjectContext() { 42 return get18Project(); 43 } 44 45 @Override setUp()46 protected void setUp() throws Exception { 47 super.setUp(); 48 assertNoErrorMarkersExist(); 49 } 50 51 @Override tearDown()52 protected void tearDown() throws Exception { 53 terminateAndRemoveJavaLaunches(); 54 removeAllBreakpoints(); 55 super.tearDown(); 56 } 57 58 /** 59 * Test for bug 543385 - we should stop multiple times on same line with many lambdas 60 */ testBug541110_unconditional()61 public void testBug541110_unconditional() throws Exception { 62 String typeName = "Bug541110"; 63 int breakpointLineNumber = 22; 64 65 IJavaLineBreakpoint bp = createLineBreakpoint(breakpointLineNumber, typeName); 66 67 IJavaThread thread = null; 68 try { 69 thread = launchToLineBreakpoint(typeName, bp); 70 thread.resume(); 71 // now we should stop again in the lambda 72 TestUtil.waitForJobs(getName(), 1000, DEFAULT_TIMEOUT, ProcessConsole.class); 73 assertTrue("Thread should be suspended", thread.isSuspended()); 74 } finally { 75 terminateAndRemove(thread); 76 removeAllBreakpoints(); 77 } 78 } 79 80 /** 81 * Test for bug 543385/541110 - we should stop only once if there is a condition. 82 * 83 * Note: if we implement proper lambda debugging support some time later, this test will probably fail. 84 */ testBug541110_conditional()85 public void testBug541110_conditional() throws Exception { 86 String typeName = "Bug541110"; 87 String breakpointCondition = "true"; 88 int breakpointLineNumber = 22; 89 90 IJavaLineBreakpoint bp = createConditionalLineBreakpoint(breakpointLineNumber, typeName, breakpointCondition, true); 91 92 IJavaThread thread = null; 93 try { 94 thread = launchToLineBreakpoint(typeName, bp); 95 thread.resume(); 96 // now we should NOT stop again in the lambda (a more complex condition would most likely fail) 97 TestUtil.waitForJobs(getName(), 1000, DEFAULT_TIMEOUT, ProcessConsole.class); 98 assertTrue("Thread should be suspended", thread.isTerminated()); 99 } finally { 100 terminateAndRemove(thread); 101 removeAllBreakpoints(); 102 } 103 } 104 terminateAndRemoveJavaLaunches()105 private void terminateAndRemoveJavaLaunches() { 106 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); 107 List<ILaunch> launches = Arrays.asList(launchManager.getLaunches()); 108 for (ILaunch launch : launches) { 109 IDebugTarget debugTarget = launch.getDebugTarget(); 110 if (debugTarget instanceof IJavaDebugTarget) { 111 terminateAndRemove((IJavaDebugTarget) debugTarget); 112 } 113 } 114 } 115 116 } 117