Closed aurabhi closed 11 years ago
What maven plugin are you using to run your integration tests? The typical way to run integration tests with Maven is to use the maven-failsafe-plugin and give your test a name like MongoIT
(instead of MongoTest
).
I think what might be happening here is that your integration test is actually running as a unit test. That means, it's being run by the maven-surefure-plugin and is running during the test
phase instead of the integration
phase.
Maven phases are ordered like this:
validate
-> compile
-> test
-> package
-> integration
-> verify
-> install
-> deploy
By default, the embedmongo-maven-plugin starts before the integration
phase and stops after the integration
phase. If you run your test as a unit test during the test
phase then you are running your test before Mongo has started.
What exact command are you using to run Maven (what phase or goals are you specifying)?
Hi Joe,
Thanks for the response. I am using maven-failsafe-plugin to run integration tests. I use 'mvn install' to run the same. There are other integration tests in the project and they run successfully. Only the ones related to mongo fail with the error that I had mentioned below. I see that the mongod is running and listening on that port during the 'integration' phase. But I always get a connection refused.
Any help with the plugin is really appreciated as I have already spent a complete day trying to fix this test.
Thanks,
From: Joe Littlejohn notifications@github.com To: joelittlejohn/embedmongo-maven-plugin embedmongo-maven-plugin@noreply.github.com Cc: aurabhi aurabhi@yahoo.com Sent: Monday, September 2, 2013 3:12 PM Subject: Re: [embedmongo-maven-plugin] Connection refused (#29)
What maven plugin are you using to run your integration tests? The typical way to run integration tests with Maven is to use the maven-failsafe-plugin and give your test a name like MongoIT (instead of MongoTest). I think what might be happening here is that your integration test is actually running as a unit test. That means, it's being run by the maven-surefure-plugin and is running during the test phase instead of the integration phase. Maven phases are ordered like this: validate -> compile -> test -> package -> integration -> verify -> install -> deploy By default, the embedmongo-maven-plugin starts before the integration phase and stops after the integration phase. If you run your test as a unit test during the test phase then you are running your test before Mongo has started. What exact command are you using to run Maven (what phase or goals are you specifying)? — Reply to this email directly or view it on GitHub.
Have you actually disabled the surefire plugin for this project? By default it will attempt to run your test if you have the test named like MongoTest
. The default includes for failsafe are:
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
and for failsafe default includes are:
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
My other thought would be firewall problems. Are you developing on Windows? If so you might want to add <bindIp>127.0.0.1</bindIp>
to your config.
Joe,
I have already tried disabling surefire. My config includes the tests in failsafe config.
I am developing on CentOS. I tried binding it to localhost, disabling iptables etc but non of these helped.
On 03-Sep-2013, at 5:25 PM, Joe Littlejohn notifications@github.com wrote:
Have you actually disabled the surefire plugin for this project? By default it will attempt to run your test if you have the test named like MongoTest. The default includes for failsafe are:
**/Test*.java **/_Test.java __/_TestCase.java and for failsafe default includes are:
**/IT*.java **/_IT.java __/_ITCase.java My other thought would be firewall problems. Are you developing on Windows? If so you might want to add
127.0.0.1 to your config.— Reply to this email directly or view it on GitHub.
Could you send me your maven log? Either via pastebin or (if you don't want to make it public) then feel free to email it to me using my github username at gmail.com. Also, could you send your mongodb.log?
There's really very little to go wrong here, either you are running your test at the wrong time (when mongo is not running) or your system configuration is blocking this communication.
Another thing you could try is invoking Maven with this extra property:
-Dembedmongo.wait
This should cause Mongo to start but will leave the build paused. You could then try connecting using the mongo shell:
mongo localhost 37017
To make sure that mongo is starting correctly. Ctrl-C to stop.
Not enough information here to investigate I'm afraid. It looks like you are not running the plugin at the same time as your tests.
In my config, that I had mentioned above, we can see that a port is specified and randomPort is also set to true.
<port>37017</port>
<randomPort>true</randomPort>
and because random port is set to true it ignores the specified port and starts the MongoDB on a random port. That's why I was getting the connection refused error. This should either be documented or a warn msg must be logged when the MongoDB is being started.
Thanks for reporting back after you solved this, I'll definitely put in a warning and mention the order of precedence in the docs somewhere.
Ah, it's actually already mentioned in the docs that the randomPort setting overrides the port parameter.
I'll add a warning though.
I am trying to connect to the embedded mongo instance from a unit test. My configuration looks like this:
When in the unit test I try to connect from an integration test. I see the following error. (The mongolog is clean and stops mongod only post-integration-test.