import com.couchbase.client.CouchbaseClient; import java.net.URI; import java.util.ArrayList; import java.util.Random; import net.spy.memcached.internal.OperationFuture; import net.spy.memcached.ops.OperationStatus; import com.couchbase.client.CouchbaseConnectionFactoryBuilder; public class Append { public static void main(String[] args) throws Exception { ArrayList nodes = new ArrayList(); // Add one or more nodes of your cluster (exchange the IP with yours) nodes.add(URI.create("http://127.0.0.1:8091/pools")); // Try to connect to the client CouchbaseClient client = null; try { client = new CouchbaseClient(nodes, "default", ""); } catch (Exception e) { System.err.println("Error connecting to Couchbase: " + e.getMessage()); System.exit(1); } byte[] big = new byte[1*1024*1024]; new Random().nextBytes(big); // 1. - Doc doesn't exist - should return "Not stored" OperationFuture res = client.append("append_test", new String(big)); OperationStatus status = res.getStatus(); if (!status.isSuccess()) { System.err.println("1. Expected failure with status: " + status.getMessage()); } else { System.err.println("1. Unexpected success - does key 'append_test' already exist?"); System.exit(1); } // 2. Create doc. res = client.set("append_test", ""); status = res.getStatus(); if (!status.isSuccess()) { System.err.println("2. Failed with status: " + status.getMessage()); System.exit(1); } // 3. Append 30 times to hit 20MB limit. // ISSUE: This returns the same error as not existing ("Not stored") for (int i = 0; i < 30; i++) { res = client.append("append_test", new String(big)); status = res.getStatus(); if (!status.isSuccess()) { System.err.println("3. Failed with status: " + status.getMessage()); } else { System.err.println("3. Success with status: " + status.getMessage()); } } // Shutdown the client client.shutdown(); } }