package com.couchbase.failover.testing; import java.net.URI; public class CouchbaseClientTester { public static void main( String[] args ) throws Exception { //System.setProperty("cbclient.disableCarrierBootstrap", "true"); List hosts = new ArrayList(); hosts.add(new URI("http://node1:8091/pools")); hosts.add(new URI("http://node2:8091/pools")); CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder(); //cfb.setAuthWaitTime(3000); //cfb.setTimeoutExceptionThreshold(3); //cfb.setObsTimeout(300); //cfb.setFailureMode(FailureMode.Cancel); cfb.setOpTimeout(200); CouchbaseClient client = new CouchbaseClient(cfb.buildCouchbaseConnection(hosts, "bucketname", "password")); String key = UUID.randomUUID().toString(); client.add(key, "value"); CouchbaseClientTester cct = new CouchbaseClientTester(); List threads = new ArrayList(); for(int i = 0; i < 8; i++) { Thread aThread = cct.new TestThread(client, key); threads.add(aThread); } for(Thread aThread : threads) { aThread.start(); } for(Thread aThread : threads) { aThread.join(); } } private class TestThread extends Thread { private CouchbaseClient client; private String key; public TestThread(CouchbaseClient client, String key) { this.client = client; this.key = key; } public void run() { while(true) { couchbaseGet(client, key); } } } private static Object couchbaseGet(CouchbaseClient client, String key) { Object result = null; try { result = client.get(key); System.out.println("Got From Master"); } catch(OperationTimeoutException ex) { try { result = client.getFromReplica(key); System.out.println("Got From Replica"); } catch (OperationTimeoutException innerEx) { //client.shutdown(); //createClient(); System.out.println("Timed out waiting for Replica Call"); innerEx.printStackTrace(); } } return result; } }