Ask a Question

Getting java.util.concurrent.timeoutexception intermittently while connecting to couchbase

avidCoder
Super Contributor

Getting java.util.concurrent.timeoutexception intermittently while connecting to couchbase

I am using Ready API 1.9.0 version to fetch the documents from the couchbase. Sometimes it works but sometimes it gives java.util.concurrent.timeoutexception. Below is the code I have written:-

 

@Grab('com.couchbase.client:java-client:2.5.5')

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.query.*;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;

def env = DefaultCouchbaseEnvironment.builder().connectTimeout(10000).queryTimeout(10000).build()
CouchbaseCluster cluster = CouchbaseCluster.create(env, IP)
Bucket bucket = cluster.openBucket(user, pass)

String doc = "EID_1900"
JsonObject docInv = getInventoryDocument(bucket, doc)

log.info dovInv

def getInventoryDocument(Bucket bucket, String val) {
 try {
  if (bucket.get(val) != null) {
   JsonObject docs= bucket.get(val).content()
   return docs;
  } else
   return null;
 } catch (Exception e) {
  if (bucket.get(val) != null) {
   JsonObject docs= bucket.get(val, 1, TimeUnit.MINUTES).content();
   return docs;
  } else
   return null;
 }
}

Could you please help me with this? 

5 REPLIES 5
groovyguy
Champion Level 0

My guess is that this is likely some sort of network interference between whatever machine you are running ReadyAPI on and Couchbase itself. Maybe try setting up a ping that runs while testing and see if the ping times out when the groovy script times out? That might help rule out network problems.

 

Other than that, you may want to try checking with Couchbase support, as I'm thinking the problem may be there. I see similar threads on their forums and on Stack Exchange. 

 

https://forums.couchbase.com/t/unable-to-connect-to-db-java-util-concurrent-timeoutexception/4471

https://stackoverflow.com/questions/40758934/couchbase-concurrent-timeout-exception-java-sdk

 

 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

Anyway thanks for reply. I tried different code approach to resolve this issue. Instead of fetching it using JSON code, I used CouchBase queries. It solved my problem.

Glad you were able to fix it! It might not be a bad idea, if you want, to give more details of how you fixed it or what you did differently in case someone else has the same problem down the road. 🙂 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
sanj
Super Contributor

Just curious what is couchbase?

groovyguy
Champion Level 0

Couchbase is a form of NoSQL database. 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
cancel
Showing results for 
Search instead for 
Did you mean: