Search in sources :

Example 6 with CouchbaseClient

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);
    }
}
Also used : CouchbaseConnectionFactoryBuilder(com.couchbase.client.CouchbaseConnectionFactoryBuilder) IOException(java.io.IOException) CouchbaseClient(com.couchbase.client.CouchbaseClient)

Example 7 with CouchbaseClient

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) CouchbaseClient(com.couchbase.client.CouchbaseClient) Test(org.junit.Test)

Example 8 with CouchbaseClient

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();
}
Also used : CouchbaseConnectionFactoryBuilder(com.couchbase.client.CouchbaseConnectionFactoryBuilder) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) CouchbaseClient(com.couchbase.client.CouchbaseClient) Test(org.junit.Test)

Aggregations

CouchbaseClient (com.couchbase.client.CouchbaseClient)8 URI (java.net.URI)7 CouchbaseConnectionFactoryBuilder (com.couchbase.client.CouchbaseConnectionFactoryBuilder)5 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 AttributeMap (com.datatorrent.api.Attribute.AttributeMap)1 Partition (com.datatorrent.api.Partitioner.Partition)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 PartitioningContextImpl (org.apache.apex.malhar.lib.partitioner.StatelessPartitionerTest.PartitioningContextImpl)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 BucketConfiguration (org.couchbase.mock.BucketConfiguration)1 CouchbaseMock (org.couchbase.mock.CouchbaseMock)1