package com.couchbase.failover.testing; import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.UUID; import net.spy.memcached.OperationTimeoutException; import com.couchbase.client.CouchbaseClient; public class CouchbaseClientTester { public static void main( String[] args ) throws Exception { List hosts = new ArrayList(); hosts.add(new URI("http://node1:8091/pools")); hosts.add(new URI("http://node2:8091/pools")); CouchbaseClient client = new CouchbaseClient(hosts, "bucketname", "password"); String key = UUID.randomUUID().toString(); client.add(key, "value"); for(int i = 0; i < 5; i++) { couchbaseGet(client, key); Thread.sleep(1000); } System.out.println("Block traffic from master node then Press 'Enter'"); System.in.read(); for(int i = 0; i < 10; i++) { couchbaseGet(client, key); Thread.sleep(1000); } System.out.println("Look at admin console 'Server Nodes' tab and wait until the master node is marked as down (this can take 10-30 seconds). Then fail it over and then press 'Enter'"); System.in.read(); while(true) { couchbaseGet(client, key); Thread.sleep(1000); } } 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("Exception"); innerEx.printStackTrace(); } } return result; } }