use of com.couchbase.client.CouchbaseClient in project apex-malhar by apache.
the class CouchBaseWindowStore method connect.
@Override
public void connect() throws IOException {
super.connect();
logger.debug("connection established");
try {
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
// wait up to 10 seconds for an operation to succeed
cfb.setOpTimeout(timeout);
// wait up to 10 second when trying to enqueue an operation
cfb.setOpQueueMaxBlockTime(blockTime);
clientMeta = new CouchbaseClient(cfb.buildCouchbaseConnection(baseURIs, bucketMeta, passwordMeta));
} catch (IOException e) {
logger.error("Error connecting to Couchbase: ", e);
DTThrowable.rethrow(e);
}
}
use of com.couchbase.client.CouchbaseClient in project apex-malhar by apache.
the class CouchBaseSetTest method test.
@Test
public void test() {
URI uri = null;
ArrayList<URI> nodes = new ArrayList<URI>();
// Add one or more nodes of your cluster (exchange the IP with yours)
nodes.add(URI.create("http://localhost:8091/pools"));
// Try to connect to the client
try {
client = new CouchbaseClient(nodes, "default", "");
} catch (Exception e) {
throw new RuntimeException(e);
}
TestPojo obj = new TestPojo();
obj.setName("test");
obj.setPhone(123344555);
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put("test", 12345);
obj.setMap(map);
future = processKeyValue("key", obj);
future.addListener(listener);
}
use of com.couchbase.client.CouchbaseClient 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