Search in sources :

Example 6 with CouchbaseConnectionFactoryBuilder

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();
}
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

CouchbaseConnectionFactoryBuilder (com.couchbase.client.CouchbaseConnectionFactoryBuilder)6 CouchbaseClient (com.couchbase.client.CouchbaseClient)5 URI (java.net.URI)5 IOException (java.io.IOException)4 Test (org.junit.Test)3 AttributeMap (com.datatorrent.api.Attribute.AttributeMap)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 BucketConfiguration (org.couchbase.mock.BucketConfiguration)2 CouchbaseMock (org.couchbase.mock.CouchbaseMock)2 OperatorContext (com.datatorrent.api.Context.OperatorContext)1 Partition (com.datatorrent.api.Partitioner.Partition)1 HashMap (java.util.HashMap)1 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)1 PartitioningContextImpl (org.apache.apex.malhar.lib.partitioner.StatelessPartitionerTest.PartitioningContextImpl)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1