Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hazelcast + Cucumber - Running tests in IDE throws an ApplicationContextException #5555

Closed
tezcane opened this issue Apr 7, 2017 · 14 comments · Fixed by #5569
Closed

Hazelcast + Cucumber - Running tests in IDE throws an ApplicationContextException #5555

tezcane opened this issue Apr 7, 2017 · 14 comments · Fixed by #5569
Milestone

Comments

@tezcane
Copy link
Contributor

tezcane commented Apr 7, 2017

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).
  1. 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.) :)

@tezcane
Copy link
Contributor Author

tezcane commented Apr 7, 2017

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

@pascalgrimaud
Copy link
Member

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

@jdubois
Copy link
Member

jdubois commented Apr 7, 2017

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

@jdubois
Copy link
Member

jdubois commented Apr 7, 2017

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.

@jdubois
Copy link
Member

jdubois commented Apr 7, 2017

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.

@jdubois jdubois closed this as completed Apr 7, 2017
@tezcane
Copy link
Contributor Author

tezcane commented Apr 7, 2017

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...

@jdubois jdubois reopened this Apr 7, 2017
@jdubois
Copy link
Member

jdubois commented Apr 8, 2017

  • 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)

@jdubois
Copy link
Member

jdubois commented Apr 8, 2017

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

@deepu105
Copy link
Member

deepu105 commented Apr 8, 2017

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

@jdubois
Copy link
Member

jdubois commented Apr 8, 2017

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

@jdubois jdubois changed the title Running IDE generated tests throws an Application Context Exception Hazelcast + Cucumber - Running tests in IDE throws an ApplicationContextException Apr 8, 2017
@tezcane
Copy link
Contributor Author

tezcane commented Apr 8, 2017

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?

@pascalgrimaud
Copy link
Member

I thought it was resolved by #2589 :(

@pascalgrimaud
Copy link
Member

@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;
}

@tezcane
Copy link
Contributor Author

tezcane commented Apr 9, 2017

OK will do by end of the day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants