Testing and Debugging
While developing your scheduling or constraint procedures, you'll likely need to do some debugging to get your procedures working as expected. Since these procedures operate on plans and simulation data, in order to properly execute and then debug the procedures, you'll need to provide that data as input.
There are two recommended methods you can use in order to test and/or debug your procedures:
- Create standalone tests for the procedures in Java, and then run those tests locally in your IDE. This option does not require you to stand up Aerie containers and interact with an Aerie deployment.
- Perform remote debugging against a deployed version of Aerie. In this option, you can attach your IDE with your procedure code to Aerie and then debug just like you would with a unit test.
Below are instructions on how to setup each option. Note that these instructions assume the use of junit as the testing framework and IntelliJ as the IDE. Instructions would likely look similar for other testing frameworks and IDEs.
Standalone Testing Procedures
Once you have developed your procedure, create a standalone test in java with a similar structure to the examples found in the mission modeling tutorial. There is one example for scheduling procedures and one for constraint procedures.
The example tests use some utilities from java packages that your build may not depend on yet. Take a look at one of the build.gradle
files in the constraints
or scheduling
directories of the mission modeling tutorial to see what dependencies exist.
Looking at one of the example tests, you'll notice a beforeAll()
method that instantiates a mission model with a particular simulation configuration and instantiates a simulation utility to assist allow plan simulation within individual tests.
There is a beforeEach()
method that creates an empty plan for individual tests to begin with. This plan is editable and can be fed directly to constraint and scheduling procedure run()
methods as seen in the example tests.
The invocation of the scheduling and/or constraint procedure occurs in the method/s annotated with @Test
, which is usually followed by some assertions checking the plan results against an expected value. Plans can be simulated at any time during a test with a plan.simulate()
.
Once you have built your test, you can debug your procedure using an IDE just like you would with any other code in a standard java application.
Remotely Debugging Procedures
Prior to starting up Aerie, make the following modifications to your docker-compose.yml
file:
- Find any containers with the name
aerie_scheduler_worker_*
(for a basic deployment, you might just have one of these) and add the following line under theJAVA_OPTS:
sub-section:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
- Add an additional port entry to the
ports:
sub-section ending in:5005
(same port number as the line above) while ensuring the first port number remains unique between containers. For example:
ports: ["27189:8080", "5006:5005"]
where 5006:5005
would be 5007:5005
for a second aerie_scheduler_worker
container and so on
Below is a breakdown of the line above in case you are interested:
-agentlib:jdwp=...
: tells the JVM to load the JDWP (Java Debug Wire Protocol) agent library, which enables debugging.transport=dt_socket
: use a socket transport for debugging (as opposed to shared memory).server=y
: tells the JVM to act as the debug server — it will listen for debugger connections.suspend=n
: tells the JVM not to suspend on start-up so the app (Aerie) will start running immediately.address=*:5005
: Listen on port 5005 on all interfaces (including inside a container), which allows external debuggers to connect.
Next, if you haven't already, open your project with your procedures in it in IntelliJ and select Run -> Edit Configurations from the menu bar. In the Run/Debug Configurations dialog that comes up, click the plus sign on the toolbar. The list shows the run/debug configuration templates. Select "Remote JVM Debug" to create a new debug configuration. Give your configuration a name such a "AerieProceduresDebugger" and ensure your settings look like the screenshot below (note you may have to change your host if you are not deploying locally).
Verify that the line under "Command line arguments for remote JVM:" matches the line you put in the docker_compose.yml
earlier. Click "OK" to complete your new configuration. You should notice that your configuration appears near the top right corner of the window along with any other run/debug configurations you may have.
Once you are ready, startup your Aerie instance and go to the plan you'd like to debug your procedure against. Before running your procedure in the Aerie instance, go to your IDE and start your remote debugger by hitting the bug icon next to your configuration in the right corner of the window. Put any breakpoints that you would like within the procedure code itself.
Finally, assuming you have already uploaded your procedure and associated it with your plan, run the procedure via the Aerie UI (or a third party client). If everything is working correctly, the breakpoints in your IDE should catch the execution of the procedure and you can debug like normal.