Exception while connecting to MongoDB using spring data

650 views
Skip to first unread message

Karthik

unread,
Feb 5, 2013, 3:18:58 PM2/5/13
to mongod...@googlegroups.com

I am trying to connect to a MongoDB instance from my testcases. I am getting the below error...

Mongo process is up and running. Any thoughts on the exception reason?

org.springframework.dao.DataAccessResourceFailureException: can't call something : localhost:12346/test; nested exception is com.mongodb.MongoException$Network: can't call something : localhost:12346/test
    at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:56)
    at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1644)
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1507)
    at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1309)
    at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:489)
    at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:484)
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$SingleEntityExecution.execute(AbstractMongoQuery.java:202)
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:90)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:313)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy69.findById(Unknown Source)
    at com.test.ServiceImpl.save(ServiceImpl.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy71.save(Unknown Source)
    at com.SearchTestCase.setUp(SearchTestCase.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: com.mongodb.MongoException$Network: can't call something : localhost:12346/test
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:227)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
    at com.mongodb.DBCollection.findOne(DBCollection.java:647)
    at com.mongodb.DBCollection.findOne(DBCollection.java:626)
    at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:1699)
    at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:1684)
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1503)
    ... 48 more
Caused by: java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:129)
    at com.mongodb.OutMessage.pipe(OutMessage.java:111)
    at com.mongodb.DBPort.go(DBPort.java:119)
    at com.mongodb.DBPort.call(DBPort.java:79)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)
    ... 54 more

Octavian Covalschi

unread,
Feb 5, 2013, 4:22:50 PM2/5/13
to mongod...@googlegroups.com

What about your webapp? Can it connect to localhost:12346/your_db ?

How did you configure mongodb for your tests? Do you have a separate app context file?

On Tue, Feb 5, 2013 at 2:18 PM, Karthik <karthi...@gmail.com> wrote:
localhost:12346/test


Karthik

unread,
Feb 5, 2013, 4:35:27 PM2/5/13
to mongod...@googlegroups.com
Yep. I am able to connect from the webapp (localhost:27017).

I have a separate config file for test cases with different port.

I am starting the mongo process before the test class is executed and stopping the process after test class execution. I am getting the below error, if i run more than 1 test class. If i run the test classes individually, they are working fine.

Octavian Covalschi

unread,
Feb 5, 2013, 5:11:39 PM2/5/13
to mongod...@googlegroups.com
Hm..i took a different approach, I have a db_test in my main instance... but your way should work too.

I suspect that other classes are trying to start your test instance while it's being shut down..  How are you running your tests? ant, maven, gradle? I wonder if you could move to a higher level your start/stop operations... I mean for all tests and not each test class.


--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Karthik Cherukuri

unread,
Feb 5, 2013, 5:15:34 PM2/5/13
to mongod...@googlegroups.com
I am running my tests using maven. Yeah...i am wondering the same. If the Port is not yet released for the next test connection. I am trying to add an artificial wait state between each test case and see, if that helps.

Thanks for the response.
Reply all
Reply to author
Forward
0 new messages