Java Client 1.1.0-1.2 query View always timeout
code:
=================================
package trade.test;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.client.protocol.views.View;
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import com.google.gson.Gson;
public class CouchbaseTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CouchbaseClient client = null;
List uris = new LinkedList();
uris.add(URI.create("http://192.168.1.108:8091/pools"));
try {
client = new CouchbaseClient(uris, "beer-sample", "");//
} catch (Exception e) {
System.err.println("Error connecting to Couchbase: " + e.getMessage());
System.exit(0);
}
System.err.println("===1===");
Gson gson = new Gson();
client.set("mykey",0,"my info is 123");
String strObj = (String)client.get("mykey");
if(null!=strObj) System.err.printf("strObj is %s\n", strObj); //ok
System.err.println("===11===");
// Fetch the View
View view = client.getView("beer", "by_location");//by_name
// Set up the Query object
Query query = new Query();
// We the full documents and only the top 20
//query.setIncludeDocs(true).setLimit(20);
// Query the Cluster
System.err.println("===2===");
ViewResponse result = client.query(view, query);
System.err.println("===3===");
// This ArrayList will contain all found beers
ArrayList> beers = new ArrayList>();
// Iterate over the found documents
for(ViewRow row : result) {
// Use Google GSON to parse the JSON into a HashMap
HashMap parsedDoc = gson.fromJson((String)row.getDocument(), HashMap.class);
// Create a HashMap which will be stored in the beers list.
HashMap beer = new HashMap();
beer.put("id", row.getId());
beer.put("name", parsedDoc.get("name"));
beer.put("brewery", parsedDoc.get("brewery_id"));
//beers.add(beer);
System.out.printf("id:", row.getId());
System.out.printf("name:", parsedDoc.get("name"));
System.out.printf("brewery:", parsedDoc.get("brewery_id"));
}
}
}
console:
=================================
2012-12-20 18:54:57.885 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/192.168.1.108:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2012-12-20 18:55:07.216 INFO com.couchbase.client.CouchbaseConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@45a877
2012-12-20 18:55:07.303 INFO net.spy.memcached.auth.AuthThread: Authenticated to 192.168.1.108/192.168.1.108:11210
2012-12-20 18:55:16.335 INFO com.couchbase.client.ViewConnection: Added 192.168.1.108 to connect queue
2012-12-20 18:55:16.339 INFO com.couchbase.client.CouchbaseClient: viewmode property isn't defined. Setting viewmode to production mode
===1===
strObj is my info is 123
===11===
2012-12-20 18:55:16.558 INFO com.couchbase.client.http.AsyncConnectionManager: Opening new Couchbase HTTP connection
2012-12-20 18:55:16.563 INFO com.couchbase.client.http.AsyncConnectionManager$ConnRequestCallback: /192.168.1.108:8092 - Session request successful
2012-12-20 18:55:25.595 ERROR com.couchbase.client.ViewNode$EventLogger: Connection timed out: [192.168.1.108/192.168.1.108:8092]
Exception in thread "main" java.lang.RuntimeException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:66)
at com.couchbase.client.CouchbaseClient.getView(CouchbaseClient.java:489)
at trade.test.CouchbaseTest.main(CouchbaseTest.java:43)
Caused by: java.util.concurrent.TimeoutException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation(HttpFuture.java:84)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:73)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:63)
... 2 more
=================================
I have tried it using jdk7 and jdk6. The results is same. Anybody can tell me why? Thanks a lot.
I found it... The couchbase in the CentOS 6.3 with the error, but it is ok in Windows 2008 R2 64 bit.