Generator-jhipster: Hazelcast + Cucumber - Running tests in IDE throws an ApplicationContextException

Created on 7 Apr 2017  路  14Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

Running tests from IDE's built in test generator throws an Application Context Exception

Motivation for or Use Case

JHipster run's tests from command line just fine, but running tests from IDE's using their nice UI's that have colorful pass/fail and store test history don't work without my proposed fix (or possible other configurations not built into JHipster).

Reproduce the error
  1. Open JHipster in Intellij (gradle or maven both have the issue). More recently using it with Maven though.
  2. IDE will detect tests in Maven/Gradle projects (e.g. for maven "Maven Projects -> Lifecycle -> test" shows up after importing the project.) EDIT THIS WORKS FINE, ONLY SECOND OPTIONS IS BROKEN:

    • Also, you can add the tests by right click the Projects tree's src/test/java folder then select "Run 'All Tests'" to run all unit/itests/feature (cucumber) tests (this is better as it shows up in the Configuration drop down menu).

  3. For both options in # 2, when you run the test ONE test will fail with: Application Context Exception. After the first test fails, all the others pass.
Related issues

I searched this issue here and outside but did not find an elegant solution.

Suggest a Fix

In CacheConfiguration.java:

        // Allows running all tests back to back, will throw Application Context Exception otherwise TODO wart?
        HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName(<PROJECT NAME>);
        if(hazelCastInstance == null) {
            hazelCastInstance = Hazelcast.newHazelcastInstance(config);
        }
        return hazelCastInstance;

Original code just has:

        return Hazelcast.newHazelcastInstance(config);

To be safer, we can enable this wart/workaround only to happen when the DEV/test? profile is run. After several attempts, I was not able to figure out how to detect when the project is running in DEV/test mode (vs. production).

JHipster Version(s)

Annoying issue exists for as long as I have used JHipster (over a year).

JHipster configuration

PS C:\Users\t\hapi\server\gtw> yo jhipster:info
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
[email protected] C:\Users\t\hapi\server\gtw
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- [email protected]
`-- UNMET PEER DEPENDENCY [email protected]

JHipster configuration, a .yo-rc.json file generated in the root folder
{
  "generator-jhipster": {
    "jhipsterVersion": "4.1.1",
    "baseName": "gtw",
    "packageName": "hapi.gtw",
    "packageFolder": "hapi/gtw",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "hazelcast",
    "clusteredHttpSession": "hazelcast",
    "websocket": "spring-websocket",
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": "elasticsearch",
    "messageBroker": "kafka",
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "jwtSecretKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "clientFramework": "angular2",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "gateway",
    "testFrameworks": [
      "gatling",
      "cucumber",
      "protractor"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en",
      "es",
      "tr"
    ]
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

ls: no such file or directory: .jhipster/*.json

Browsers and Operating System

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

git version 2.12.0.windows.1

node: v7.8.0

npm: 4.2.0

yeoman: 1.8.5

yarn: 0.22.0

Docker version 1.13.1, build 092cba3

docker-compose version 1.11.1, build 7afaa436

  • [ X ] Checking this box is mandatory (this is just to show you read everything)

(I love the advanced mark box feature.) :)

area

All 14 comments

Oh sweet got #5555! This issue was written in the stars...

can you put your yo-rc.json plz ?
so we can try to reproduce

Yes, I'm doing this all the time without any issue, so we need your configuration for that.

I'm closing as we need to follow the same rules for everyone, but I'm really annoyed because it really looks like you know what you are doing, and found a real issue.

This ticket has been closed as the guidelines are not followed.

Tickets must follow our Guidelines, as mentioned in:

  1. our Readme file on the front page of the project,
  2. the "create a new ticket" page and
  3. our Help page

We have also created a template on the "create a new ticket" page to help you follow those guidelines.

Updated with config. Since I seen this regardless of monolith/microservice gradle/maven many Node and Java versions, etc. did not think it was related to my config. I seen it on MAC/Linux/Windows too. Also, happens with fresh project, don't touch any file...

  • With my sample project, I have no issue (I just did it right now, but I'm using this all the time anyway so I know it works) -> maybe you're missing something in your steps? Maybe this is linked to your Intellij configuration? I'm using Intellij IDEA Ultimate on Mac OS X.
  • I'm going to test with your specific configuration: please note you have a lot of non-default options, with some very uncommon combinaisons (Clustered HTTP cache with Websocket? You're free to do it, of course, but for me this looks like a really bad idea)

Indeed I can reproduce the error with your configuration -> as you can see, there is something specific with your . yo-rc.json :-)

I think the hazelcast clusteredHttpSession might be the culprit. It might be creating more than 1 hazelcast instance

Yes this is probably due to a combinaison of Hazelcast (http session and/or 2nd level cache) and Cucumber. I'm updating the title.

I enabled all the features that I thought I may use in the future. Did you think I was going to let any of your guys amazing work go to waste?

@tezcane : looks like you find the fix. Can you do a PR? I would just do this improvment, and do this at the beginning of the method:

HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName(<PROJECT NAME>);
if (hazelCastInstance != null) {
    return hazelCastInstance;
}

OK will do by end of the day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomj0101 picture tomj0101  路  3Comments

shivroy121 picture shivroy121  路  3Comments

DanielFran picture DanielFran  路  3Comments

dronavallisaikrishna picture dronavallisaikrishna  路  3Comments

marcelinobadin picture marcelinobadin  路  3Comments