Search in sources :

Example 6 with DocumentNotFoundException

use of com.couchbase.client.core.error.DocumentNotFoundException in project couchbase-jvm-clients by couchbase.

the class KeyValueErrorIntegrationTest method verifyGetExceptions.

@Test
void verifyGetExceptions() {
    DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.get(UUID.randomUUID().toString()));
    assertNotNull(thrown.context());
    assertThrows(InvalidArgumentException.class, () -> collection.get("foo", null));
    assertThrows(InvalidArgumentException.class, () -> collection.get(""));
    assertThrows(InvalidArgumentException.class, () -> collection.get(null));
    assertThrows(InvalidArgumentException.class, () -> collection.get("", getOptions().withExpiry(true)));
    List<String> tooManyFields = IntStream.rangeClosed(1, 17).boxed().map(Object::toString).collect(Collectors.toList());
    assertThrows(InvalidArgumentException.class, () -> collection.get("foo", getOptions().project(tooManyFields)));
}
Also used : DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with DocumentNotFoundException

use of com.couchbase.client.core.error.DocumentNotFoundException in project couchbase-jvm-clients by couchbase.

the class KeyValueErrorIntegrationTest method verifyGetAndTouchExceptions.

@Test
void verifyGetAndTouchExceptions() {
    DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.getAndTouch(UUID.randomUUID().toString(), Duration.ofSeconds(1)));
    assertNotNull(thrown.context());
    assertThrows(InvalidArgumentException.class, () -> collection.getAndTouch("foo", Duration.ofSeconds(1), null));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndTouch("", Duration.ofSeconds(1)));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndTouch(null, Duration.ofSeconds(1)));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndTouch("foo", null));
}
Also used : DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with DocumentNotFoundException

use of com.couchbase.client.core.error.DocumentNotFoundException in project couchbase-jvm-clients by couchbase.

the class KeyValueErrorIntegrationTest method verifyTouchExceptions.

@Test
void verifyTouchExceptions() {
    assertThrows(InvalidArgumentException.class, () -> collection.touch("foo", null));
    assertThrows(InvalidArgumentException.class, () -> collection.touch(null, Duration.ofSeconds(1), null));
    assertThrows(InvalidArgumentException.class, () -> collection.touch("foo", null, touchOptions()));
    DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.touch(UUID.randomUUID().toString(), Duration.ofSeconds(1)));
    assertNotNull(thrown.context());
}
Also used : DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with DocumentNotFoundException

use of com.couchbase.client.core.error.DocumentNotFoundException in project couchbase-jvm-clients by couchbase.

the class KeyValueErrorIntegrationTest method verifyGetAndLockExceptions.

@Test
void verifyGetAndLockExceptions() {
    DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.getAndLock(UUID.randomUUID().toString(), Duration.ofSeconds(1)));
    assertNotNull(thrown.context());
    assertThrows(InvalidArgumentException.class, () -> collection.getAndLock("foo", Duration.ofSeconds(1), null));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndLock("", Duration.ofSeconds(1)));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndLock(null, Duration.ofSeconds(1)));
    assertThrows(InvalidArgumentException.class, () -> collection.getAndLock("foo", null));
}
Also used : DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with DocumentNotFoundException

use of com.couchbase.client.core.error.DocumentNotFoundException 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)

Aggregations

DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)19 Test (org.junit.jupiter.api.Test)10 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)8 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)7 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)6 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)5 GetResult (com.couchbase.client.java.kv.GetResult)5 LookupInResult (com.couchbase.client.java.kv.LookupInResult)5 JsonObject (com.couchbase.client.java.json.JsonObject)4 MutationResult (com.couchbase.client.java.kv.MutationResult)3 Bucket (com.couchbase.client.java.Bucket)2 Cluster (com.couchbase.client.java.Cluster)2 Collection (com.couchbase.client.java.Collection)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 ClusterAwareIntegrationTest (com.couchbase.client.test.ClusterAwareIntegrationTest)2 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)2 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)1 DmlFailureException (com.couchbase.client.core.error.DmlFailureException)1 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1