Error when running Corda flow tests from IntelliJ
Asked Answered
G

4

8

When I run Corda flow tests from IntelliJ, the tests fail with the following errors:

QUASAR WARNING: Quasar Java Agent isn't running. If you're using another instrumentation method you can ignore this message; otherwise, please refer to the Getting Started section in the Quasar documentation.

and

java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM. See https://docs.corda.net/troubleshooting.html - 'Fiber classes not instrumented' for more details.

How can I fix this?

Genic answered 21/11, 2017 at 10:55 Comment(0)
G
17

Corda flows need to be instrumented using Quasar before they are run, so that they can be suspended mid-execution.

To achieve this in IntelliJ, you need to:

  • Create a run config for your tests
  • Open the run config and change the VM options to -ea -javaagent:PATH-TO-QUASAR-JAR
    • In the CorDapp example and templates, quasar.jar is located at lib/quasar.jar, so you'd use -ea -javaagent:../lib/quasar.jar

Alternatively, you can edit the default JUnit run config to use the Quasar javaagent by default, avoiding you having to do this every time you pick a new test to run.

Genic answered 21/11, 2017 at 10:55 Comment(4)
Is there a way to include this within gradle or test dependencies? What if we don't want it to be included as a VM argument within our run configs?Flaring
It’ll be added automatically when nodes are run normally. This is only required for tests. There is no way around it currently.Genic
If you use TestNG you can use a TestNG listener to load it automatically.Dilapidation
I get stuck on "Starting Gradle Daemo..." and "Test events were not received".Shrinkage
O
6

This is a basic error that you get if you don't set Quasar, you need to select your test-> go to Intellij top bar-> Run -> Edit Configurations and then set up like this photo in VM options: enter image description here

Orometer answered 21/11, 2017 at 16:58 Comment(0)
U
0

From template readme

We recommend editing your IntelliJ preferences so that you use the Gradle runner - this means that the quasar utils plugin will make sure that some flags (like -javaagent - see below) are set for you.

To switch to using the Gradle runner:

Navigate to Build, Execution, Deployment -> Build Tools -> Gradle -> Runner (or search for runner) Windows: this is in "Settings" MacOS: this is in "Preferences" Set "Delegate IDE build/run actions to gradle" to true Set "Run test using:" to "Gradle Test Runner" If you would prefer to use the built in IntelliJ JUnit test runner, you can run gradlew installQuasar which will copy your quasar JAR file to the lib directory. You will then need to specify -javaagent:lib/quasar.jar and set the run directory to the project root directory for each test.

Unbalance answered 24/10, 2019 at 3:8 Comment(0)
L
0

Btw, if you face same error in VSCode, you can add

"java.test.config": {
    "vmArgs": ["-ea", "-javaagent:../lib/quasar.jar"]
},

to settings.json. The path ../lib/quasar.jar may be different in your project.

Limeade answered 24/9, 2022 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.