Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package test;
  2.  
  3. import com.couchbase.client.java.Bucket;
  4. import com.couchbase.client.java.Cluster;
  5. import com.couchbase.client.java.CouchbaseCluster;
  6. import com.couchbase.client.java.document.StringDocument;
  7. import com.couchbase.client.java.env.CouchbaseEnvironment;
  8. import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
  9. import java.util.UUID;
  10.  
  11. // 4 node cluster
  12. public class MainTest {
  13.  
  14. public static void main(String... args) throws Exception {
  15. CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().build();
  16. Cluster cluster = CouchbaseCluster.create(env, "127.0.0.1");
  17. final Bucket bucket = cluster.openBucket("default", "");
  18.  
  19.  
  20. String id = UUID.randomUUID().toString();
  21.  
  22. System.err.println(id);
  23.  
  24. bucket.upsert(StringDocument.create(id, "Hello "));
  25.  
  26. // lock the document
  27. StringDocument oldDoc = bucket.getAndLock(id, 10, StringDocument.class);
  28.  
  29. // create the one to append with the
  30. StringDocument newDoc = StringDocument.create(oldDoc.id(), "World!", oldDoc.cas());
  31.  
  32. // blows up with tmpfail
  33. bucket.append(newDoc);
  34.  
  35. bucket.unlock(oldDoc);
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement