Search in sources :

Example 41 with MutationResult

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

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

the class KeyValueIntegrationTest method exists.

/**
 * Mock does not support Get Meta, so we need to ignore it there.
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void exists() {
    String id = UUID.randomUUID().toString();
    assertFalse(collection.exists(id).exists());
    MutationResult insertResult = collection.insert(id, "Hello, World");
    assertTrue(insertResult.cas() != 0);
    ExistsResult existsResult = collection.exists(id);
    assertEquals(insertResult.cas(), existsResult.cas());
    assertTrue(existsResult.exists());
    assertFalse(collection.exists("some_id").exists());
}
Also used : ExistsResult(com.couchbase.client.java.kv.ExistsResult) 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

MutationResult (com.couchbase.client.java.kv.MutationResult)42 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)40 Test (org.junit.jupiter.api.Test)40 JsonObject (com.couchbase.client.java.json.JsonObject)16 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)13 GetResult (com.couchbase.client.java.kv.GetResult)11 SearchQuery.queryString (com.couchbase.client.java.search.SearchQuery.queryString)5 SearchResult (com.couchbase.client.java.search.result.SearchResult)5 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)4 TimeoutException (com.couchbase.client.core.error.TimeoutException)3 Bucket (com.couchbase.client.java.Bucket)2 Collection (com.couchbase.client.java.Collection)2 ExistsResult (com.couchbase.client.java.kv.ExistsResult)2 QueryOptions (com.couchbase.client.java.query.QueryOptions)2 QueryResult (com.couchbase.client.java.query.QueryResult)2 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)2 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)1