Search in sources :

Example 6 with GetResult

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

the class QueryIntegrationTest method preserveExpiry.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.QUERY_PRESERVE_EXPIRY)
void preserveExpiry() {
    String id = UUID.randomUUID().toString();
    collection.insert(id, FOO_CONTENT, InsertOptions.insertOptions().expiry(Duration.ofDays(1L)));
    Instant expectedExpiry = collection.get(id, GetOptions.getOptions().withExpiry(true)).expiryTime().get();
    cluster.query("UPDATE " + bucketName + " AS content USE KEYS '" + id + "' SET content.foo = 'updated'", queryOptions().preserveExpiry(true));
    GetResult result = collection.get(id, GetOptions.getOptions().withExpiry(true));
    assertEquals("updated", result.contentAsObject().get("foo"));
    assertEquals(expectedExpiry, result.expiryTime().get());
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) Instant(java.time.Instant) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with GetResult

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

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

the class KeyValueIntegrationTest method touch.

/**
 * Right now the mock does not change the cas on touch, so we need to ignore the test
 * until https://github.com/couchbase/CouchbaseMock/issues/50 is resolved.
 */
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void touch() throws Exception {
    String id = UUID.randomUUID().toString();
    JsonObject expected = JsonObject.create().put("foo", true);
    MutationResult upsert = collection.upsert(id, expected, upsertOptions().expiry(Duration.ofSeconds(10)));
    assertTrue(upsert.cas() != 0);
    MutationResult touched = collection.touch(id, Duration.ofSeconds(1));
    assertNotEquals(touched.cas(), upsert.cas());
    Thread.sleep(300);
    GetResult r = collection.get(id);
    assertEquals(expected, r.contentAsObject());
    assertEquals(r.cas(), touched.cas());
    waitUntilCondition(() -> {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        // ignored.
        }
        try {
            collection.get(id);
            return false;
        } catch (DocumentNotFoundException knf) {
            return true;
        }
    });
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with GetResult

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

the class KeyValueIntegrationTest method unlock.

/**
 * The mock returns TMPFAIL instead of LOCKED, so this test is ignored on the mock.
 */
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void unlock() {
    String id = UUID.randomUUID().toString();
    MutationResult upsert = collection.upsert(id, JsonObject.create().put("foo", true));
    assertTrue(upsert.cas() != 0);
    GetResult locked = collection.getAndLock(id, Duration.ofSeconds(30));
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.upsert(id, JsonObject.create(), upsertOptions().timeout(Duration.ofMillis(100))));
    assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
    assertThrows(CasMismatchException.class, () -> collection.unlock(id, locked.cas() + 1));
    collection.unlock(id, locked.cas());
    JsonObject expected = JsonObject.create().put("foo", false);
    MutationResult replaced = collection.replace(id, expected);
    assertTrue(replaced.cas() != 0);
    assertEquals(expected, collection.get(id).contentAsObject());
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with GetResult

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

the class KeyValueCollectionIntegrationTest method recognizesCollectionAfterCreation.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void recognizesCollectionAfterCreation() {
    String collId = UUID.randomUUID().toString().substring(0, 10);
    CollectionSpec collectionSpec = CollectionSpec.create(collId, CollectionIdentifier.DEFAULT_SCOPE);
    bucket.collections().createCollection(collectionSpec);
    Collection collection = bucket.collection(collId);
    String id = UUID.randomUUID().toString();
    String content = "bar";
    MutationResult upsertResult = collection.upsert(id, content);
    GetResult getResult = collection.get(id);
    assertEquals(upsertResult.cas(), getResult.cas());
    assertEquals(content, getResult.contentAs(String.class));
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) MutationResult(com.couchbase.client.java.kv.MutationResult) 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