Generator-jhipster: ElasticSearch+Cucumber tests fail (6.1.2 and 6.2.0)

Created on 28 Aug 2019  ·  4Comments  ·  Source: jhipster/generator-jhipster

Overview of the issue

Running ./mvnw clean verify on a fresh jhipster app with cucumber and elasticsearch selected (with all other defaults) fails.

Motivation for or Use Case

Would like tests to pass

Reproduce the error
jhipster
# Select Cucubmer and Elasticsearch
./mvnw clean verify

Expected: tests to pass

Actual:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.611 s <<< FAILURE! - in CucumberIT
[ERROR] Feature: User management  Time elapsed: 2.611 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [com/mycompany/myapp/config/ElasticsearchConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namef593e8eb-029a-47a2-9689-c6de10c2b3cc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namef593e8eb-029a-47a2-9689-c6de10c2b3cc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namef593e8eb-029a-47a2-9689-c6de10c2b3cc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namef593e8eb-029a-47a2-9689-c6de10c2b3cc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   CucumberIT » IllegalState Failed to load ApplicationContext
[INFO]
[ERROR] Tests run: 113, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.4:report-integration (post-integration-tests) @ cukes ---
[INFO] Loading execution data file /Users/amir/jhipster-cucumber-elasticsearch/target/jacoco/integrationTest.exec
[INFO] Analyzed bundle 'Cukes' with 61 classes
[INFO]
[INFO] --- maven-failsafe-plugin:3.0.0-M3:verify (verify) @ cukes ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:57 min
[INFO] Finished at: 2019-08-28T13:02:39-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M3:verify (verify) on project cukes: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/amir/jhipster-cucumber-elasticsearch/target/test-results/integrationTest for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Related issues

https://github.com/jhipster/generator-jhipster/issues/10081

Suggest a Fix

It sounds like there is a conflict in ES setting up a lock. Not sure if the tests are running in parallel or an isolated ES context/test node can be set up

JHipster Version(s)
JHipster configuration
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:info
INFO! Options: from-cli: true
Welcome to the JHipster Information Sub-Generator

##### **JHipster Version(s)**

[email protected] /Users/amir/jhipster-cucumber-elasticsearch
└── [email protected]



##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**


<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp"
    },
    "jhipsterVersion": "6.2.0",
    "applicationType": "monolith",
    "baseName": "cukes",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "testFrameworks": [
      "cucumber"
    ],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": false,
    "blueprints": []
  }
}
</pre>
</details>


##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

No JDL/Entities needed, fails for Cucumber User Search test CucumberIT

##### **Environment and Tools**

openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)

git version 2.20.1

node: v10.16.3

npm: 6.9.0

yarn: 1.13.0

Docker version 19.03.1, build 74b1e89

docker-compose version 1.24.1, build 4667896b

INFO! Congratulations, JHipster execution is complete!

yo-rc

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp"
    },
    "jhipsterVersion": "6.2.0",
    "applicationType": "monolith",
    "baseName": "cukes",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "testFrameworks": [
      "cucumber"
    ],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": false,
    "blueprints": []
  }
}
Browsers and Operating System

MacOS
ZSH

  • [x] Checking this box is mandatory (this is just to show you read everything)
$$ bug-bounty $$ $100 area java

Most helpful comment

Cucumber does not support JUnit 5 (see cucumber/cucumber-jvm#1149), CucumberIT tests use the junit-vintage engine. All other tests are started with the junit-platform engine (JUnit 5).

Each engine creates one node instance of elasticsearch and share the same data path. By default, Elasticsearch is configured to prevent more than one node from sharing the same data path. The setting node.max_local_storage_nodes enables to share the data path for more than one node.

Be careful : This setting is deprecated in 7.x and will be removed in version 8.0.

Add this settings in src/test/resources/config/application.yml

spring:
  data:
    elasticsearch:
      properties:
        node:
          max_local_storage_nodes: 2

All 4 comments

Related: https://stackoverflow.com/questions/56997858/junit-tests-fail-because-of-elasticsearch

This seems to be happening for all integration tests that use ElasticSearch

I confirm the issue and put a bounty on this, as it needs to be fixed

Cucumber does not support JUnit 5 (see cucumber/cucumber-jvm#1149), CucumberIT tests use the junit-vintage engine. All other tests are started with the junit-platform engine (JUnit 5).

Each engine creates one node instance of elasticsearch and share the same data path. By default, Elasticsearch is configured to prevent more than one node from sharing the same data path. The setting node.max_local_storage_nodes enables to share the data path for more than one node.

Be careful : This setting is deprecated in 7.x and will be removed in version 8.0.

Add this settings in src/test/resources/config/application.yml

spring:
  data:
    elasticsearch:
      properties:
        node:
          max_local_storage_nodes: 2

Closed by https://github.com/jhipster/generator-jhipster/pull/10623

@juliensadaoui : don't forget to claim the bounty

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielFran picture DanielFran  ·  3Comments

shivroy121 picture shivroy121  ·  3Comments

RizziCR picture RizziCR  ·  3Comments

DanielFran picture DanielFran  ·  3Comments

pascalgrimaud picture pascalgrimaud  ·  4Comments