Search in sources :

Example 36 with GetResult

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

the class KeyValueIntegrationTest method getAndLock.

/**
 * We need to ignore this test on the mock because the mock returns TMPFAIL instead of LOCKED when the
 * document is locked (which used to be the old functionality but now since XERROR is negotiated it
 * returns LOCKED properly).
 *
 * <p>Once the mock is modified to return LOCKED, this test can also be run on the mock again.</p>
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void getAndLock() {
    String id = UUID.randomUUID().toString();
    JsonObject expected = JsonObject.create().put("foo", true);
    MutationResult insert = collection.insert(id, expected);
    assertTrue(insert.cas() != 0);
    GetResult getAndLock = collection.getAndLock(id, Duration.ofSeconds(30));
    assertTrue(getAndLock.cas() != 0);
    assertNotEquals(insert.cas(), getAndLock.cas());
    assertEquals(expected, getAndLock.contentAsObject());
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndLock(id, Duration.ofSeconds(30), getAndLockOptions().timeout(Duration.ofMillis(100))));
    assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
    assertThrows(DocumentNotFoundException.class, () -> collection.getAndLock("some_doc", Duration.ofSeconds(30)));
}
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 37 with GetResult

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

the class KeyValueReactiveCollectionIntegrationTest method reactiveTouch.

@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void reactiveTouch() {
    StepVerifier.create(docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1)))).expectError(DocumentNotFoundException.class).verify();
    // Insert docs with expiry of 10s
    InsertOptions firstOpts = InsertOptions.insertOptions().expiry(Duration.ofSeconds(10));
    List<MutationResult> insertResults = docIds.concatMap(key -> reactiveCollection.insert(key, JsonObject.create().put("key", key), firstOpts)).collectList().block();
    // Touch docs and update the expiry to 1s
    List<MutationResult> touchResults = docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1))).collectList().block();
    // Assert cas of insert and touch results differ
    StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> insertResults.get(i).cas() != touchResults.get(i).cas()).verifyComplete();
    List<GetResult> getResults = docIds.concatMap(reactiveCollection::get).collectList().block();
    StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> getResults.get(i).cas() == touchResults.get(i).cas()).verifyComplete();
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) GetResult(com.couchbase.client.java.kv.GetResult) BeforeEach(org.junit.jupiter.api.BeforeEach) InsertOptions(com.couchbase.client.java.kv.InsertOptions) StepVerifier(reactor.test.StepVerifier) Iterator(java.util.Iterator) MutationResult(com.couchbase.client.java.kv.MutationResult) ExistsResult(com.couchbase.client.java.kv.ExistsResult) ClusterType(com.couchbase.client.test.ClusterType) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) JsonObject(com.couchbase.client.java.json.JsonObject) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) GetResult(com.couchbase.client.java.kv.GetResult) InsertOptions(com.couchbase.client.java.kv.InsertOptions) 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 38 with GetResult

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

the class KeyValueIntegrationTest method insertAndGet.

@Test
void insertAndGet() {
    String id = UUID.randomUUID().toString();
    MutationResult insertResult = collection.insert(id, "Hello, World");
    assertTrue(insertResult.cas() != 0);
    assertTrue(insertResult.mutationToken().isPresent());
    GetResult getResult = collection.get(id);
    assertEquals("Hello, World", getResult.contentAs(String.class));
    assertEquals("\"Hello, World\"", new String(getResult.contentAsBytes(), UTF_8));
    assertTrue(getResult.cas() != 0);
    assertFalse(getResult.expiryTime().isPresent());
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 39 with GetResult

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

the class CavesKeyValueIntegrationTest method setGet.

@Caves("kv/crud/SetGet")
@Test
void setGet() {
    JsonObject testDoc = JsonObject.create().put("foo", "bar");
    collection.upsert("test-doc", testDoc);
    GetResult result = collection.get("test-doc");
    assertEquals(testDoc, result.contentAsObject());
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test) Caves(com.couchbase.client.test.Caves)

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