This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-website.git
The following commit(s) were added to refs/heads/main by this push:
new f93ec504 Blogpost: Debug Camel route in test with Camel 3.18 and VS
Code
f93ec504 is described below
commit f93ec5042a390b322b06a7299581a6a85468efb0
Author: Aurélien Pupier <[email protected]>
AuthorDate: Mon Jul 25 11:11:32 2022 +0200
Blogpost: Debug Camel route in test with Camel 3.18 and VS Code
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../index.md | 2 +
.../index.md | 73 ++++++++--------------
2 files changed, 29 insertions(+), 46 deletions(-)
diff --git
a/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
b/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
index 4bc30b67..1e3a7e15 100644
---
a/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
+++
b/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
@@ -6,6 +6,8 @@ categories: ["Tooling"]
preview: "How to use Camel textual Route Debugger with Unit test in VS Code"
---
+EDIT: I recommend to read this [new
article](/blog/2022/07/HowToUseCamelRouteTextualDebuggerWithUnitTest) if using
Camel 3.18+.
+
Textual debug for Camel routes allows to set breakpoints at Route definition.
It is convenient to leverage this feature with a Unit test.
This article will explain how it is possible to configure the project and the
VS Code IDE for that. Similar functionality should be possible with other IDEs
but not covered in this article.
diff --git
a/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
b/content/blog/2022/07/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
similarity index 51%
copy from
content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
copy to
content/blog/2022/07/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
index 4bc30b67..266e0a76 100644
---
a/content/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
+++
b/content/blog/2022/07/HowToUseCamelRouteTextualDebuggerWithUnitTest/index.md
@@ -1,23 +1,25 @@
---
-title: "How to use Camel textual Route Debugger with Unit test in VS Code"
-date: 2022-06-22
+title: "How to use Camel textual Route Debugger with Unit test in VS Code -
Updated with Camel 3.18"
+date: 2022-07-26
authors: [apupier]
categories: ["Tooling"]
-preview: "How to use Camel textual Route Debugger with Unit test in VS Code"
+preview: "How to use Camel textual Route Debugger with Unit test in VS Code -
Updated with Camel 3.18"
---
Textual debug for Camel routes allows to set breakpoints at Route definition.
It is convenient to leverage this feature with a Unit test.
-This article will explain how it is possible to configure the project and the
VS Code IDE for that. Similar functionality should be possible with other IDEs
but not covered in this article.
+Last month, I published a
[blogpost](/blog/2022/06/HowToUseCamelRouteTextualDebuggerWithUnitTest) but it
had several limitations listed. Most of them have been fixed. This article is
an updated version that will explain how it is possible to configure the
project and the VS Code IDE for that. Similar functionality should be possible
with other IDEs but not covered in this article.
+
+Note: If you prefer to watch than read, you can go to [this
video](https://youtu.be/_hKIg81WJUs).
# Requirements
-In this article, we will focus on using VS Code IDE. It implies the following
requirements:
+In this article, we will focus on using the [VS Code
IDE](https://code.visualstudio.com/). It implies the following requirements:
- [VS Code client for Debug Adapter for
Camel](https://github.com/camel-tooling/camel-dap-client-vscode/issues)
installed in your VS Code instance
-- Maven available on system path
+- [Maven](https://maven.apache.org/) available on system path
- Java 11+ installed
-- Camel 3.17+
+- Camel 3.18+
# Project configuration
@@ -47,56 +49,45 @@ In this article, we will focus on using VS Code IDE. It
implies the following re
## Test class configuration
-Two methods must have a specific value:
-
-- `isUseDebugger` method must return false. This is the default
implementation, just ensure that it is not overridden.
-- `useJMX` method must return true. This needs to be overridden.
-
-
-We also need to ensure that the test is starting after Debugger is attached
and breakpoint set. For now, the only solution that I can propose is to insert
a (ugly) `Thread.sleep` at the beginning of the test. It will work only if the
test is triggering the route execution. If your route is automatically
triggered like for a `timer`, some route executions might happen before the
debugger is attached and breakpoints enabled.
-
-You should end up with something like that:
+You might need to provide a longer timeout to let you time to debug, something
like:
```java
class MainTest extends CamelMainTestSupport {
@Test
void myTest() throws Exception {
- Thread.sleep(2000); // to let time to Debugger to attach and
install breakpoints
- template.asyncSendBody("direct:demo", ""); // Take care to
start the route in an async way
NotifyBuilder notify = new NotifyBuilder(context)
.whenCompleted(1).whenBodiesDone("Bye World").create();
assertTrue(
- notify.matches(60, TimeUnit.SECONDS), "1 message should
be completed"
+ notify.matches(90, TimeUnit.SECONDS), "1 message should
be completed"
);
}
-
- @Override
- protected boolean useJmx() {
- return true;
- }
}
```
-You might also want to introduce a longer timeout to let you time to debug.
-
# IDE configuration
## VS Code Task configuration
-The following VS Code task must be created in the `.vscode/tasks.json` file:
+A VS Code task must be created in the `.vscode/tasks.json` file to start the
test with correct settings. You can use the snippet available on completion. It
will create something like:
```json
{
"version": "2.0.0",
"tasks": [
{
- "label": "Start test with camel.debug profile",
+ "label": "Launch Camel test with Maven with camel.debug
profile",
"type": "shell",
"command": "mvn", // mvn binary of Maven must be
available on command-line
"args": [
"test",
+ "-Dtest=*", // If more than one test is
present, a specific one must be specified as a single test can be Camel
debugged per launch.
"-Pcamel.debug" // This depends on your
project. The goal here is to have camel-debug on the classpath.
],
+ "options": {
+ "env": {
+ "CAMEL_DEBUGGER_SUSPEND": "true" // Set
to true by default. A debugger must be attached for message to be processed.
+ }
+ },
"problemMatcher": "$camel.debug.problemMatcher",
"presentation": {
"reveal": "always"
@@ -107,11 +98,10 @@ The following VS Code task must be created in the
`.vscode/tasks.json` file:
}
```
-It allows to start the test with `camel-debug` on the classpath.
+## VS Code Launch configuration
-## VSCode Launch configuration
+A launch configuration must be created in the `.vscode/launch.json`. It allows
to call the VS Code tasks starting the test and attach debugger when the Camel
debugger is ready. A snippet completiion is available to guide to create it.
You will end up with something like:
-The following launch configuration must be created in the
`.vscode/launch.json`:
```json
{
@@ -121,36 +111,27 @@ The following launch configuration must be created in the
`.vscode/launch.json`:
"name": "Start test and attach Camel Debugger",
"type": "apache.camel",
"request": "attach",
- "preLaunchTask": "Start test with camel.debug profile"
// must reference the label of the VS Code task previously created
+ "preLaunchTask": "Launch Camel test with Maven with
camel.debug profile" // must reference the label of the VS Code task previously
created
}
]
}
```
-It allows to call the VS Code tasks starting the test and attach debugger when
the Camel debugger is ready.
-
# Run & Debug
-Place the breakpoint on your Camel Route.
+Place the breakpoint on your Camel Route *before* launching the test.
-Then you can launch the test with Camel debugger which will be automatically
attached. You just have to enjoy your debug session!
+Then you can launch the test with Camel debugger which will be automatically
attached. It is now time to enjoy your debug session!
# Resources
-See the full configuration steps in [this video](https://youtu.be/be8XajY5G84).
+See the full configuration steps in [this video](https://youtu.be/_hKIg81WJUs).
-You can see an adapted official example with checked-in VS Code settings
[here](https://github.com/apupier/camel-examples/tree/Blogpost-Example-Debug-Camel-In-Test/examples/main).
+You can see an adapted official example with checked-in VS Code settings
[here](https://github.com/apupier/camel-examples/tree/demo-blogpost-test-v2/examples/main).
# Limitations
-We have seen one way to debug a Camel route textually which is part of a test.
You might have noticed that it comes with several limitations. Let's summarize
them:
-
-- One test at a time
-- Requires modification of test code to activate JMX
-- Requires modification of test code to ensure debugger is ready on first
route execution in the test
-- Cannot use [Camel test Java Debugger](/manual/debugger.html)
-
-Stay tuned as I expect several of these limitations to be overcome in
following weeks.
+We have seen one way to debug a Camel route textually which is part of a test.
You might have noticed that it remains one important limitations which is that
we can launch a single test at a time.
# What's next