Search in sources :

Example 21 with GetResult

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

the class ReplicaReadIntegrationTest method alwaysPassesWithAll.

/**
 * As a simple litmus test, when ALL is used there should be at least one record coming back,
 * namely from the active.
 *
 * <p>Depending on the topology, it might be more than that.</p>
 */
@Test
void alwaysPassesWithAll() {
    String id = UUID.randomUUID().toString();
    collection.upsert(id, "Hello, World!");
    List<GetResult> results = collection.getAllReplicas(id).collect(Collectors.toList());
    assertFalse(results.isEmpty());
    for (GetResult result : results) {
        assertEquals("Hello, World!", result.contentAs(String.class));
        assertFalse(result.expiry().isPresent());
    }
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with GetResult

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

the class RetryStrategyIntegrationTest method retryStrategyCanTriggerCustomException.

@Test
void retryStrategyCanTriggerCustomException() {
    String docId = UUID.randomUUID().toString();
    collection.upsert(docId, "foo");
    GetResult r = collection.getAndLock(docId, Duration.ofSeconds(15));
    assertThrows(CustomDocumentLockedException.class, () -> collection.remove(docId, removeOptions().retryStrategy(failFastIfLocked)));
    collection.unlock(docId, r.cas());
    collection.remove(docId);
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with GetResult

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

the class SubdocMutateIntegrationTest method expiration.

@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED, ClusterType.CAVES })
void expiration() {
    JsonObject content = JsonObject.create().put("hello", "world");
    String docId = prepare(content);
    coll.mutateIn(docId, Arrays.asList(MutateInSpec.insert("foo2", "bar2")), MutateInOptions.mutateInOptions().expiry(Duration.ofSeconds(10)));
    GetResult result = coll.get(docId, GetOptions.getOptions().withExpiry(true));
    assertTrue(result.expiry().isPresent());
    assertTrue(result.expiry().get().getSeconds() != 0);
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) 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 24 with GetResult

use of com.couchbase.client.java.kv.GetResult 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)

Example 25 with GetResult

use of com.couchbase.client.java.kv.GetResult 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)

Aggregations

GetResult (com.couchbase.client.java.kv.GetResult)39 Test (org.junit.jupiter.api.Test)25 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)20 JsonObject (com.couchbase.client.java.json.JsonObject)18 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)15 MutationResult (com.couchbase.client.java.kv.MutationResult)11 Collection (com.couchbase.client.java.Collection)7 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)6 Bucket (com.couchbase.client.java.Bucket)5 Cluster (com.couchbase.client.java.Cluster)4 Record (org.talend.sdk.component.api.record.Record)4 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)3 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)2 TimeoutException (com.couchbase.client.core.error.TimeoutException)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2