Search in sources :

Example 1 with MutateInResult

use of com.couchbase.client.java.kv.MutateInResult in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method reviveDocumentWithCAS3.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void reviveDocumentWithCAS3() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    MutateInResult mr = coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().createAsDeleted(true).accessDeleted(true).storeSemantics(StoreSemantics.INSERT));
    // Create a CAS mismatch
    coll.insert(docId, JsonObject.create());
    try {
        coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).cas(mr.cas()).storeSemantics(StoreSemantics.REVIVE));
        fail();
    } catch (CasMismatchException ignored) {
    // It hits this rather than CannotReviveAliveDocumentException
    }
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) JsonObject(com.couchbase.client.java.json.JsonObject) ReplaceBodyWithXattr(com.couchbase.client.java.kv.ReplaceBodyWithXattr) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with MutateInResult

use of com.couchbase.client.java.kv.MutateInResult in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method reviveDocumentWithCAS.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void reviveDocumentWithCAS() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    MutateInResult mr = coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().createAsDeleted(true).accessDeleted(true).storeSemantics(StoreSemantics.INSERT));
    // Create a CAS mismatch
    coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().accessDeleted(true));
    try {
        coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).cas(mr.cas()).storeSemantics(StoreSemantics.REVIVE));
        fail();
    } catch (CasMismatchException ignored) {
    }
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) JsonObject(com.couchbase.client.java.json.JsonObject) ReplaceBodyWithXattr(com.couchbase.client.java.kv.ReplaceBodyWithXattr) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with MutateInResult

use of com.couchbase.client.java.kv.MutateInResult in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method xattrOpsAreReordered.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void xattrOpsAreReordered() {
    JsonObject content = JsonObject.create();
    String docId = prepareXattr(content);
    MutateInResult result = coll.mutateIn(docId, Arrays.asList(MutateInSpec.insert("foo2", "bar2"), MutateInSpec.increment("x.foo", 5).xattr()));
    assertThrows(NoSuchElementException.class, () -> result.contentAs(0, String.class));
    assertEquals(5, result.contentAs(1, Integer.class));
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with MutateInResult

use of com.couchbase.client.java.kv.MutateInResult in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method replaceBodyWithXattrSimulatingTransactionalReplace.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REPLACE_BODY_WITH_XATTR })
@Test
void replaceBodyWithXattrSimulatingTransactionalReplace() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    coll.upsert(docId, JsonObject.create());
    MutateInResult mr = coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().accessDeleted(true));
    coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().cas(mr.cas()));
    GetResult gr = coll.get(docId);
    assertEquals(gr.contentAsObject(), body);
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) ReplaceBodyWithXattr(com.couchbase.client.java.kv.ReplaceBodyWithXattr) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with MutateInResult

use of com.couchbase.client.java.kv.MutateInResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnSubdocMutate.

@Test
void tokenOnSubdocMutate() {
    String id = UUID.randomUUID().toString();
    MutationResult result = collection.upsert(id, JsonObject.create());
    assertMutationToken(result.mutationToken());
    MutateInResult mutateResult = collection.mutateIn(id, Arrays.asList(MutateInSpec.insert("foo", true)));
    assertMutationToken(mutateResult.mutationToken());
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

MutateInResult (com.couchbase.client.java.kv.MutateInResult)5 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)5 Test (org.junit.jupiter.api.Test)5 JsonObject (com.couchbase.client.java.json.JsonObject)4 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)4 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)3 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)2 GetResult (com.couchbase.client.java.kv.GetResult)1 MutationResult (com.couchbase.client.java.kv.MutationResult)1