Search in sources :

Example 1 with ReplaceBodyWithXattr

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

the class SubdocMutateIntegrationTest method replaceBodyWithXattrPathNotFound.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void replaceBodyWithXattrPathNotFound() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    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));
    try {
        coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("does_not_exist")), MutateInOptions.mutateInOptions().accessDeleted(true).storeSemantics(StoreSemantics.REVIVE));
        fail();
    } catch (PathNotFoundException ignored) {
    }
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) ReplaceBodyWithXattr(com.couchbase.client.java.kv.ReplaceBodyWithXattr) PathNotFoundException(com.couchbase.client.core.error.subdoc.PathNotFoundException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReplaceBodyWithXattr

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

the class SubdocMutateIntegrationTest method replaceBodyWithXattrWithoutReviveDocument.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void replaceBodyWithXattrWithoutReviveDocument() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().storeSemantics(StoreSemantics.INSERT));
    coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true));
    GetResult gr = coll.get(docId);
    assertEquals(gr.contentAsObject(), body);
}
Also used : 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 3 with ReplaceBodyWithXattr

use of com.couchbase.client.java.kv.ReplaceBodyWithXattr 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 4 with ReplaceBodyWithXattr

use of com.couchbase.client.java.kv.ReplaceBodyWithXattr 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 5 with ReplaceBodyWithXattr

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

the class SubdocMutateIntegrationTest method replaceBodyWithXattrSimulatingTransactionalInsert.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void replaceBodyWithXattrSimulatingTransactionalInsert() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    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));
    coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).storeSemantics(StoreSemantics.REVIVE));
    GetResult gr = coll.get(docId);
    assertEquals(gr.contentAsObject(), body);
}
Also used : 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)

Aggregations

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