Debugging a Flux service
When debugging a Flux service, you gain the ability to inspect and change the flow of the service's execution. Martini Online and Desktop both support the adding of breakpoints, stepping through states and transitions, examining the context, performing evaluations, and more. In this section, we will go over these features and learn how they can be used to debug a Flux service.
Starting a debug session
To start a debug session, you need to run your Flux service in debug mode. When a service is running in debug mode, you will be able to perform debug operations on that service. There are two ways to start a service in debug mode: using the context menu from either the Flux editor or the Navigator view, or the debug button on the service toolbar.
If your Flux has input properties declared, Martini will prompt you to supply these properties before starting the debug session.
Attaching the debugger
If you have a Flux service that is currently running and you want to perform debug operations on it, you can use the Flux debugger. The Flux debugger has the ability to attach itself to a running Flux service (whether already in a debug session or not) and when it is attached, a new debug session is created and started. To do this:
- Access the Martini service manager.
- Right click the Flux service you want to attach to.
- Click Attach Debugger.
After the debugger successfully attaches itself, you should see a < Flux Debugger Attached >
message in the
Console view. You may now perform debug operations on that service.
You will also notice Martini prompting you to switch to the Debug perspective. This perspective contains all elements relevant for debugging services. Click the Yes button to switch immediately; No or Cancel to postpone.
Toggling breakpoints
Breakpoints are used as markers to suspend the execution of a service. In Flux, you can add them to the states either before or during debugging. To do this:
- Select one or more states.
- Right click then click Toggle Breakpoint.
Use the shortcut to quickly toggle breakpoints
You can use the shortcut to toggle a breakpoint when you have a state selected.
Breakpoints view
If you're in the Debug perspective, you'll be able to see all of your breakpoints under the Breakpoints view.
Commands for debugging
The Flux debugger provides different execution operations that you can apply to a service that's being debugged:
-
Resume
Resumes the debug execution until a breakpoint is hit or the service completes.
-
Pause
Suspends the debug execution. If a state or transition is currently being executed, execution will be suspended on the next transition or state instead, respectively.
-
Terminate
Stops the running service.
-
Step Into
When used on a state, the current state will be invoked and then the execution stops before the transition. When used on a transition, the transition will be invoked and then the execution stops before the next state.
-
Step Over
When used on a state, the current state and its transition will be invoked and then the execution stops before the next state. When used on a transition, the transition will be invoked then and then the execution stops before the next transition.
Martini also features shortcuts for each of these commands.
The Debug perspective
Flux's Debug perspective is similar to Gloop's Debug perspective wherein the workspace is re-arranged so that it shows all views relevant when debugging.
When debugging a Flux service, the user is given the option to use the Flux Debug perspective. The prompt is displayed after inputs have been set.
Debug view
This view shows the debug execution stack of services that are currently and have been debugged.
Variables view
This view shows the current context of the service being debugged. The context is made available for display when the service's execution is suspended. It consists mainly of Flux service inputs and outputs. If execution halts while on a state, then the state's input and output variables are added; if on a transition, then the transition's input and output variables are added.
Expressions view
This view allows you to run Groovy statements that use the variables available in the context; all you have to do is define and add the expressions.
In the example below, an expression was added to calculate the total price of all cart
items with an additional price
of 20
each:
Read-only evaluation
The evaluations made while debugging do not alter the values of the context.
Breakpoints view
This view shows all the breakpoints you have added via the Flux service editor. You could enable/disable the breakpoints by toggling the checkbox beside each entry.
Shortcuts
Command | Description | Shortcut |
---|---|---|
Debug | Debugs the service previously run | |
Toggle breakpoint | Adds or removes a breakpoint | |
Resume | Resumes the debug execution | |
Terminate | Stops the debug execution | |
Step Into | Executes the current state or transition and suspends the execution before entering the next state or transition | |
Step Over | Executes the current state and transition and suspends the execution before entering the next state |
Command | Description | Shortcut |
---|---|---|
Debug | Debugs the service previously run | |
Toggle breakpoint | Adds or removes a breakpoint | |
Resume | Resumes the debug execution | |
Pause | Suspends the debug execution | |
Terminate | Stops the debug execution | |
Step into | Executes the current state or transition and suspends the execution before entering the next state or transition | |
Step over | Executes the current state and transition and suspends the execution before entering the next state |