use of com.couchbase.client.CouchbaseConnectionFactoryBuilder in project apex-malhar by apache.
the class CouchBaseGetTest method test.
@Test
public void test() {
URI uri = null;
try {
uri = new URI("http://localhost:8091/pools");
} catch (URISyntaxException ex) {
logger.error("Error connecting to Couchbase: " + ex.getMessage());
DTThrowable.rethrow(ex.getCause());
}
baseURIs.add(uri);
CouchbaseClient client = null;
try {
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
// wait up to 10 seconds for an operation to succeed
cfb.setOpTimeout(10000);
// wait up to 5 second when trying to enqueue an operation
cfb.setOpQueueMaxBlockTime(5000);
client = new CouchbaseClient(cfb.buildCouchbaseConnection(baseURIs, "default", "default"));
} catch (IOException ex) {
logger.error("Error connecting to Couchbase: " + ex.getMessage());
DTThrowable.rethrow(ex.getCause());
}
client.flush();
long startTime = System.currentTimeMillis();
logger.info("start time before get is " + startTime);
for (int k = 0; k < 1000; k++) {
logger.info("k " + k);
for (int i = 0; i < 100; i++) {
String value = client.get("Key" + (k * 100 + i)).toString();
logger.info("value is " + value);
}
}
long stopTime = System.currentTimeMillis();
logger.info("stop time after get is " + stopTime);
logger.info("Threads after get are + " + Thread.activeCount());
client.shutdown();
}
Aggregations