# DebugSqlSpec and integration tests

**URL:** <https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [December 3, 2018, 4:31pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219 "2018-12-03T16:31:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 3, 2018, 4:31pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/1 "2018-12-03T16:31:10Z")

</div>

Hi,

I can't make the `DebugSqlSpec` test class work.

When I run an Elasticsearch local server (`./gradlew run --debug-jvm -Drun.license_type=trial -Dxpack.security.enabled=false`) and then run an empty implementation of the `DebugSqlSpec` test class against this local instance, I got the error below:

```
java.security.AccessControlException: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")
	at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
	at java.base/java.security.AccessController.checkPermission(AccessController.java:895)
	at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
	at java.base/java.lang.reflect.AccessibleObject.checkPermission(AccessibleObject.java:83)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:169)
	at com.intellij.junit4.JUnit4IdeaTestRunner.getSuiteMethodDescription(JUnit4IdeaTestRunner.java:139)
	at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:84)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

```

I tried the `idea.no.launcher=true` trick, but no luck.

Integration tests with only no-arg constructors seem to work fine, but the `DebugSqlSpec` has a constructor with arguments because it's a parametrized test.

Could an Elastic insider explain the typical SQL support development workflow (reproduce / debug / fix / test) please?

Thanks a lot,  
Chris

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 3, 2018, 7:06pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/2 "2018-12-03T19:06:39Z")

</div>

I tend to add the test to the spec file that it feels best in and then run:

```auto
./gradlew -p x-pack/plugin/sql/qa/single-node/ integTest -Dtests.class='*SpecIT'

```

I don't tend to use the DebugSpecs. You can also use `-Dtests.method='*some*glob*'` to limit which test cases are run which is nice for keeping the output more organized. The process of starting gradle and starting the single node makes the whole thing kind of heavy but it is the burden that comes with integration testing.

---

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 3, 2018, 7:31pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/3 "2018-12-03T19:31:11Z")

</div>

Thank you @nik9000, are you then able to debug the started node instance?

Maybe with tweaked `ES_JAVA_OPTS`?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 3, 2018, 7:44pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/4 "2018-12-03T19:44:34Z")

</div>

I don't typically debug the instance but this looks like it works:

```auto
ES_JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y" ./gradlew -p x-pack/plugin/sql/qsingle-node/ integTest -Dtests.class='*SpecIT'

```

Gradle pauses with

```auto
:x-pack:plugin:sql:qa:single-node:integTestCluster#wait

```

up. I think it'll wait 30 seconds or something before giving up. That really isn't very long to be honest.

---

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 3, 2018, 9:54pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/5 "2018-12-03T21:54:35Z")

</div>

That is great, thank you @nik9000, I’ll give it a try tomorrow and let you know.

---

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 4, 2018, 10:05am UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/6 "2018-12-04T10:05:57Z")

</div>

Nope, unfortunately, it didn't work.

# Attempt 1

I've also tried with a shell `export`, but still no luck.

```
export ES_JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=y"

./gradlew -p x-pack/plugin/sql/qa/single-node/ integTest -Dtests.class='*DebugSqlSpecIT'

```

And the remote debugging output is still:

```
Error running 'remote': Unable to open debugger port (localhost:8000): java.net.ConnectException "Connection refused (Connection refused)"

```

# Attempt 2

I've tried to tweak Gradle build file `x-pack/plugin/sql/qa/single-node/build.gradle` by adding:

```
integTestCluster {
  setting 'xpack.security.enabled', 'false'
  setting 'xpack.license.self_generated.type', 'trial'
  
  String jvmArgsStr = " -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"
  jvmArgs jvmArgsStr
}

```

Then I can connect the remote debugger, but the Gradle integration test task waits for 30 seconds and run the test without halting on my breakpoint.

# Attempt 3

I tried another JVM argument string variant, but still no luck.

```
integTestCluster {
  setting 'xpack.security.enabled', 'false'
  setting 'xpack.license.self_generated.type', 'trial'
  
  String jvmArgsStr = " -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=y"
  jvmArgs jvmArgsStr
}

```

Do you usually use a debugger to troubleshoot x-pack issues or do you use some kind of print statements?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 4, 2018, 2:50pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/7 "2018-12-04T14:50:24Z")

</div>

For the most part I user unit tests and log messages. It has been about a year since I connected a debugger to Elasticsearch. I'm unsure what happened here. When I did it on the command line it _looked_ like it stopped and was waiting for me but I didn't try to connect because I didn't have Eclipse running at the time.

---

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 4, 2018, 3:28pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/8 "2018-12-04T15:28:51Z")

</div>

That’s okay, thank you @nik9000 👍 I will launch a local instance with Gradle and `--debug-jvm` option, load the `test_emp` data set and use cURL, as usual, it will be fine.

---

<div class="post-metadata">

**Author:** ![cbismuth](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cbismuth](https://discuss.elastic.co/u/cbismuth)\
**Post date:** [December 4, 2018, 4:24pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/9 "2018-12-04T16:24:36Z")

</div>

I've just seen this main entry point `org.elasticsearch.xpack.sql.qa.jdbc.DataLoader#main`, looks awesome 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 1, 2019, 4:28pm UTC](https://discuss.elastic.co/t/debugsqlspec-and-integration-tests/159219/10 "2019-01-01T16:28:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
